1313#include " duckdb/main/capi/capi_internal.hpp"
1414#include " duckdb/main/client_context.hpp"
1515#include " duckdb/main/connection.hpp"
16- #include " duckdb/parser/keyword_helper.hpp"
1716#include " duckdb/parser/parsed_data/create_copy_function_info.hpp"
1817
1918unique_ptr<FunctionData> copy_to_bind (ClientContext &,
@@ -42,7 +41,7 @@ unique_ptr<FunctionData> copy_to_bind(ClientContext &,
4241 throw BinderException (IntoErrString (error_out));
4342 }
4443 auto cdata = unique_ptr<CData>(reinterpret_cast <CData *>(ffi_bind_data));
45- return make_uniq<VortexCopyBindData>(std::move (cdata), names );
44+ return make_uniq<VortexCopyBindData>(std::move (cdata));
4645}
4746
4847unique_ptr<GlobalFunctionData>
@@ -88,7 +87,7 @@ void copy_to_get_written_statistics(ClientContext &,
8887 gstate.Cast <VortexCopyGlobalState>().written_stats = &statistics;
8988}
9089
91- void copy_to_finalize (ClientContext &, FunctionData &bind_data , GlobalFunctionData &gstate) {
90+ void copy_to_finalize (ClientContext &, FunctionData &, GlobalFunctionData &gstate) {
9291 auto &global = gstate.Cast <VortexCopyGlobalState>();
9392 void *const ffi_global = global.ffi_global ->DataPtr ();
9493
@@ -101,23 +100,16 @@ void copy_to_finalize(ClientContext &, FunctionData &bind_data, GlobalFunctionDa
101100 if (!global.written_stats ) {
102101 return ;
103102 }
104- const auto &names = bind_data.Cast <VortexCopyBindData>().column_names ;
105103 duckdb_vx_written_file_statistics file_stats;
106104 if (!duckdb_copy_function_get_written_file_statistics (ffi_global, &file_stats)) {
107105 throw InternalException (" vortex COPY: written statistics were requested but not produced" );
108106 }
109- if (file_stats.num_columns != names.size ()) {
110- throw InternalException (" vortex COPY: %llu statistics columns for %llu written columns" ,
111- file_stats.num_columns ,
112- names.size ());
113- }
114107 D_ASSERT (global.written_stats != nullptr );
115108 global.written_stats ->row_count = file_stats.row_count ;
116109 global.written_stats ->file_size_bytes = file_stats.file_size_bytes ;
117110 global.written_stats ->footer_size_bytes = Value::UBIGINT (file_stats.footer_size_bytes );
118- // Keyed by top-level column name only. The vortex footer reports one statistics set per
119- // top-level field, so nested struct/list leaf columns get no statistics here (unlike parquet,
120- // which recurses to leaf paths). Flat tables are fully covered.
111+ // One entry per leaf column: nested struct fields are reported at their full path and structs
112+ // get no entry of their own, as in parquet.
121113 for (idx_t i = 0 ; i < file_stats.num_columns ; i++) {
122114 duckdb_vx_written_column_statistics col_stats {};
123115 duckdb_vx_error col_error = nullptr ;
@@ -146,9 +138,9 @@ void copy_to_finalize(ClientContext &, FunctionData &bind_data, GlobalFunctionDa
146138 if (col_stats.has_nan_stat ) {
147139 column[" has_nan" ] = Value::BOOLEAN (col_stats.contains_nan );
148140 }
149-
150- string quoted = SQLQuotedIdentifier::ToString (names[i] );
151- global.written_stats ->column_statistics .emplace (std::move (quoted ), std::move (column));
141+ auto column_key = reinterpret_cast <Value *>(col_stats. column_key )-> ToString ();
142+ duckdb_destroy_value (&col_stats. column_key );
143+ global.written_stats ->column_statistics .emplace (std::move (column_key ), std::move (column));
152144 }
153145}
154146
0 commit comments