Skip to content

QDB-15924 - Expose lazy table creation mode in batch writer to Python API #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion quasardb/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void cluster::close()
_handle->close();
}
}
catch (qdb::invalid_handle_exception const & e)
catch (qdb::invalid_handle_exception const & /*e*/)
{
// This can happen if, for example, we call close() after an error occured; in those
// circumstances, we fully expect the connection to already be invalid, and we should
Expand Down
26 changes: 24 additions & 2 deletions quasardb/detail/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ void staged_table::prepare_table_data(qdb_exp_batch_push_table_data_t & table_da
void staged_table::prepare_batch(qdb_exp_batch_push_mode_t mode,
detail::deduplicate_options const & deduplicate_options,
qdb_ts_range_t * ranges,
qdb_exp_batch_push_table_t & batch)
qdb_exp_batch_push_table_t & batch,
qdb_exp_batch_creation_mode_t creation)
{
batch.name = _table_name.c_str();

Expand All @@ -235,7 +236,7 @@ void staged_table::prepare_batch(qdb_exp_batch_push_mode_t mode,
batch.where_duplicate = nullptr;
batch.where_duplicate_count = 0;
batch.deduplication_mode = qdb_exp_batch_deduplication_mode_disabled;
batch.creation = qdb_exp_batch_dont_create;
batch.creation = creation;

enum detail::deduplication_mode_t mode_ = deduplicate_options.mode_;

Expand Down Expand Up @@ -311,6 +312,27 @@ void staged_table::prepare_batch(qdb_exp_batch_push_mode_t mode,
return ret;
}

/* static */ py::kwargs detail::batch_creation_mode::ensure(py::kwargs kwargs)
{
if (kwargs.contains(batch_creation_mode::kw_creation_mode) == false)
{
kwargs[batch_creation_mode::kw_creation_mode] = batch_creation_mode::default_creation_mode;
}

return kwargs;
}

/* static */ qdb_exp_batch_creation_mode_t detail::batch_creation_mode::from_kwargs(
py::kwargs const & kwargs)
{
assert(kwargs.contains(batch_creation_mode::kw_creation_mode));

// By default no flags are set
qdb_exp_batch_creation_mode_t ret = qdb_exp_batch_dont_create;

return py::cast<qdb_exp_batch_creation_mode_t>(kwargs[batch_creation_mode::kw_creation_mode]);
}

/* static */ qdb_exp_batch_options_t detail::batch_options::from_kwargs(py::kwargs const & kwargs)
{
auto kwargs_ = detail::batch_push_mode::ensure(kwargs);
Expand Down
19 changes: 18 additions & 1 deletion quasardb/detail/writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ class staged_table
void prepare_batch(qdb_exp_batch_push_mode_t mode,
detail::deduplicate_options const & deduplicate_options,
qdb_ts_range_t * ranges,
qdb_exp_batch_push_table_t & batch);
qdb_exp_batch_push_table_t & batch,
qdb_exp_batch_creation_mode_t creation);

static inline void _set_deduplication_mode(
enum detail::deduplication_mode_t mode, bool columns, qdb_exp_batch_push_table_t & out)
Expand Down Expand Up @@ -487,6 +488,22 @@ struct batch_options
static qdb_exp_batch_options_t from_kwargs(py::kwargs const & kwargs);
};

struct batch_creation_mode
{
static constexpr char const * kw_creation_mode = "creation_mode";
static constexpr qdb_exp_batch_creation_mode_t default_creation_mode = qdb_exp_batch_dont_create;

/**
* Ensures all options are always explicitly set, according to the defaults above.
*/
static py::kwargs ensure(py::kwargs kwargs);

/**
* Returns the push mode, throws error if push mode is not set.
*/
static qdb_exp_batch_creation_mode_t from_kwargs(py::kwargs const & kwargs);
};

struct batch_truncate_ranges
{

Expand Down
7 changes: 5 additions & 2 deletions quasardb/writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class writer

// Ensure some default variables that are set
kwargs = detail::batch_push_flags::ensure(kwargs);
kwargs = detail::batch_creation_mode::ensure(kwargs);

std::vector<qdb_ts_range_t> truncate_ranges{};

Expand Down Expand Up @@ -202,7 +203,8 @@ class writer
truncate_ranges_ = truncate_ranges.data();
}

int cur = 0;
auto creation_mode = detail::batch_creation_mode::from_kwargs(kwargs);
int cur = 0;

for (auto pos = idx.begin(); pos != idx.end(); ++pos)
{
Expand All @@ -214,7 +216,8 @@ class writer
options.mode, //
deduplicate_options, //
truncate_ranges_, //
batch_table);
batch_table, //
creation_mode);

if (batch_table.data.column_count == 0) [[unlikely]]
{
Expand Down