Skip to content

Commit

Permalink
Add patches to make passing down ClientContext optional
Browse files Browse the repository at this point in the history
  • Loading branch information
carlopi committed Jan 16, 2025
1 parent b315e18 commit 5cdd2fe
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
15 changes: 15 additions & 0 deletions patches/duckdb/arrow_appender_opt_client_context.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/src/common/arrow/arrow_appender.cpp b/src/common/arrow/arrow_appender.cpp
index 83f190b570..60c4b36268 100644
--- a/src/common/arrow/arrow_appender.cpp
+++ b/src/common/arrow/arrow_appender.cpp
@@ -40,8 +40,10 @@ void ArrowAppender::Append(DataChunk &input, const idx_t from, const idx_t to, c
for (idx_t i = 0; i < input.ColumnCount(); i++) {
if (root_data[i]->extension_data && root_data[i]->extension_data->duckdb_to_arrow) {
Vector input_data(root_data[i]->extension_data->GetInternalType());
+ if (options.client_context) {
root_data[i]->extension_data->duckdb_to_arrow(*options.client_context, input.data[i], input_data,
input_size);
+ }
root_data[i]->append_vector(*root_data[i], input_data, from, to, input_size);
} else {
root_data[i]->append_vector(*root_data[i], input.data[i], from, to, input_size);
52 changes: 52 additions & 0 deletions patches/duckdb/arrow_converter_opt_client_context.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
diff --git a/src/common/arrow/arrow_converter.cpp b/src/common/arrow/arrow_converter.cpp
index a693034a92..a7d4b78889 100644
--- a/src/common/arrow/arrow_converter.cpp
+++ b/src/common/arrow/arrow_converter.cpp
@@ -59,10 +59,10 @@ void InitializeChild(ArrowSchema &child, DuckDBArrowSchemaHolder &root_holder, c
}

void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, const LogicalType &type,
- ClientProperties &options, ClientContext &context);
+ ClientProperties &options, optional_ptr<ClientContext> context);

void SetArrowMapFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, const LogicalType &type,
- ClientProperties &options, ClientContext &context) {
+ ClientProperties &options, optional_ptr<ClientContext> context) {
child.format = "+m";
//! Map has one child which is a struct
child.n_children = 1;
@@ -77,18 +77,21 @@ void SetArrowMapFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child,
}

bool SetArrowExtension(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, const LogicalType &type,
- ClientContext &context) {
- auto &config = DBConfig::GetConfig(context);
+ optional_ptr<ClientContext> context) {
+ if (!context) {
+ return false;
+ }
+ auto &config = DBConfig::GetConfig(*context);
if (config.HasArrowExtension(type.id())) {
auto arrow_extension = config.GetArrowExtension(type.id());
- arrow_extension.PopulateArrowSchema(root_holder, child, type, context, arrow_extension);
+ arrow_extension.PopulateArrowSchema(root_holder, child, type, *context, arrow_extension);
return true;
}
return false;
}

void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, const LogicalType &type,
- ClientProperties &options, ClientContext &context) {
+ ClientProperties &options, optional_ptr<ClientContext> context) {
if (type.HasAlias()) {
// If it is a json type, we only export it as json if arrow_lossless_conversion = True
if (!(type.IsJSONType() && !options.arrow_lossless_conversion)) {
@@ -402,7 +405,7 @@ void ArrowConverter::ToArrowSchema(ArrowSchema *out_schema, const vector<Logical
root_holder->owned_column_names.push_back(AddName(names[col_idx]));
auto &child = root_holder->children[col_idx];
InitializeChild(child, *root_holder, names[col_idx]);
- SetArrowFormat(*root_holder, child, types[col_idx], options, *options.client_context);
+ SetArrowFormat(*root_holder, child, types[col_idx], options, options.client_context);
}

// Release ownership to caller

0 comments on commit 5cdd2fe

Please sign in to comment.