diff --git a/vortex-duckdb/cpp/include/duckdb_vx/table_function.h b/vortex-duckdb/cpp/include/duckdb_vx/table_function.h index e8f483514a5..721fe17e3a4 100644 --- a/vortex-duckdb/cpp/include/duckdb_vx/table_function.h +++ b/vortex-duckdb/cpp/include/duckdb_vx/table_function.h @@ -38,15 +38,6 @@ void duckdb_vx_tfunc_bind_result_add_column(duckdb_vx_tfunc_bind_result ffi_resu size_t name_len, duckdb_logical_type ffi_type); -// Opaque type for the result of get_virtual_columns -typedef struct duckdb_vx_tfunc_virtual_cols_result_ *duckdb_vx_tfunc_virtual_cols_result; -// Push a column into the get_virtual_columns result. -void duckdb_vx_tfunc_virtual_columns_push(duckdb_vx_tfunc_virtual_cols_result ffi_result, - idx_t column_idx, - const char *name_str, - size_t name_len, - duckdb_logical_type ffi_type); - // String map for to_string result typedef struct duckdb_vx_string_map_ *duckdb_vx_string_map; @@ -144,8 +135,6 @@ typedef struct { bool (*pushdown_complex_filter)(void *bind_data, duckdb_vx_expr expr, duckdb_vx_error *error_out); - void (*get_virtual_columns)(void *bind_data, duckdb_vx_tfunc_virtual_cols_result result_out); - void *pushdown_expression; duckdb_vx_string_map (*to_string)(void *bind_data); // void *dynamic_to_string; @@ -162,7 +151,6 @@ typedef struct { // void *supports_pushdown_type; // void *get_partition_info; // void *get_partition_stats; - // void *get_virtual_columns; // void *get_row_id_columns; bool projection_pushdown; diff --git a/vortex-duckdb/cpp/table_function.cpp b/vortex-duckdb/cpp/table_function.cpp index 6154e91f738..d8a10b1b673 100644 --- a/vortex-duckdb/cpp/table_function.cpp +++ b/vortex-duckdb/cpp/table_function.cpp @@ -274,33 +274,6 @@ extern "C" void duckdb_vx_tfunc_bind_result_add_column(duckdb_vx_tfunc_bind_resu result->return_types.emplace_back(*logical_type); } -virtual_column_map_t c_get_virtual_columns(ClientContext & /*context*/, - optional_ptr bind_data) { - auto &bind = bind_data->Cast(); - - auto result = virtual_column_map_t(); - bind.info->vtab.get_virtual_columns(bind_data->Cast().ffi_data->DataPtr(), - reinterpret_cast(&result)); - return result; -} - -extern "C" void duckdb_vx_tfunc_virtual_columns_push(duckdb_vx_tfunc_virtual_cols_result ffi_result, - idx_t column_idx, - const char *name_str, - size_t name_len, - duckdb_logical_type ffi_type) { - if (!ffi_result || !name_str || !ffi_type) { - return; - } - - auto result = reinterpret_cast(ffi_result); - const auto logical_type = reinterpret_cast(ffi_type); - const auto name = string(name_str, name_len); - - auto table_col = TableColumn(std::move(name), *logical_type); - result->emplace(column_idx, std::move(table_col)); -} - OperatorPartitionData c_get_partition_data(ClientContext & /*context*/, TableFunctionGetPartitionInput &input) { if (input.partition_info.RequiresPartitionColumns()) { @@ -360,10 +333,13 @@ extern "C" duckdb_state duckdb_vx_tfunc_register(duckdb_database ffi_db, const d tf.late_materialization = vtab->late_materialization; tf.cardinality = c_cardinality; tf.get_partition_data = c_get_partition_data; - tf.get_virtual_columns = c_get_virtual_columns; tf.to_string = c_to_string; tf.table_scan_progress = c_table_scan_progress; + tf.get_virtual_columns = [](auto &, auto) -> virtual_column_map_t { + return {{COLUMN_IDENTIFIER_EMPTY, TableColumn("", LogicalTypeId::BOOLEAN)}}; + }; + // Set up the parameters tf.arguments.reserve(vtab->parameter_count); for (size_t i = 0; i < vtab->parameter_count; i++) { diff --git a/vortex-duckdb/src/datasource.rs b/vortex-duckdb/src/datasource.rs index 47a1eba2b4f..0cb9fa84484 100644 --- a/vortex-duckdb/src/datasource.rs +++ b/vortex-duckdb/src/datasource.rs @@ -5,7 +5,7 @@ //! //! Table functions that resolve to a [`DataSourceRef`] can implement [`DataSourceTableFunction`] //! to get a blanket [`TableFunction`] implementation covering init, scan, progress, filter -//! pushdown, cardinality, partitioning, and virtual columns. +//! pushdown, cardinality, and partitioning. use std::ffi::CString; use std::fmt::Debug; @@ -60,7 +60,6 @@ use crate::duckdb::LogicalType; use crate::duckdb::TableFilterSetRef; use crate::duckdb::TableFunction; use crate::duckdb::TableInitInput; -use crate::duckdb::VirtualColumnsResultRef; use crate::exporter::ArrayExporter; use crate::exporter::ConversionCache; @@ -74,17 +73,15 @@ use crate::exporter::ConversionCache; /// If you define COLUMN_IDENTIFIER_EMPTY, planner takes it, otherwise the /// first column. As we don't want to fill the output chunk and we can leave /// it uninitialized in this case, we define COLUMN_IDENTIFIER_EMPTY as a -/// virtual column in our table function vtab's get_virtual_columns. -/// See vortex-duckdb/cpp/include/duckdb_vx/table_function.h -/// See virtual_columns in this file +/// virtual column. +/// See vortex-duckdb/cpp/table_function.cpp static EMPTY_COLUMN_IDX: u64 = 18446744073709551614; -static EMPTY_COLUMN_NAME: &str = ""; /// A trait for table functions that resolve to a [`DataSourceRef`]. /// /// Implementors only need to define how parameters are declared and how binding produces a /// data source. All other [`TableFunction`] methods (init, scan, progress, filter pushdown, -/// cardinality, partitioning, virtual columns) are provided by a blanket implementation. +/// cardinality, partitioning) are provided by a blanket implementation. pub(crate) trait DataSourceTableFunction: Sized + Debug { /// Returns the positional parameters of the table function. fn parameters() -> Vec { @@ -442,10 +439,6 @@ impl TableFunction for T { Some(result) } - - fn virtual_columns(_bind_data: &Self::BindData, result: &mut VirtualColumnsResultRef) { - result.register(EMPTY_COLUMN_IDX, EMPTY_COLUMN_NAME, &LogicalType::bool()); - } } // --------------------------------------------------------------------------- diff --git a/vortex-duckdb/src/duckdb/table_function/mod.rs b/vortex-duckdb/src/duckdb/table_function/mod.rs index f20e844d381..a59cebdb417 100644 --- a/vortex-duckdb/src/duckdb/table_function/mod.rs +++ b/vortex-duckdb/src/duckdb/table_function/mod.rs @@ -15,12 +15,9 @@ mod init; mod partition; mod pushdown_complex_filter; mod table_scan_progress; -mod virtual_columns; pub use bind::*; pub use init::*; -pub use virtual_columns::VirtualColumnsResult; -pub use virtual_columns::VirtualColumnsResultRef; use crate::cpp; use crate::cpp::duckdb_client_context; @@ -35,7 +32,6 @@ use crate::duckdb::table_function::cardinality::cardinality_callback; use crate::duckdb::table_function::partition::get_partition_data_callback; use crate::duckdb::table_function::pushdown_complex_filter::pushdown_complex_filter_callback; use crate::duckdb::table_function::table_scan_progress::table_scan_progress_callback; -use crate::duckdb::table_function::virtual_columns::get_virtual_columns_callback; use crate::duckdb_try; /// A trait that defines the supported operations for a table function in DuckDB. @@ -140,9 +136,6 @@ pub trait TableFunction: Sized + Debug { _local_init_data: &mut Self::LocalState, ) -> VortexResult; - /// Returns the virtual columns of the table function. - fn virtual_columns(_bind_data: &Self::BindData, _result: &mut VirtualColumnsResultRef) {} - /// Returns a vector of key-value pairs for EXPLAIN output fn to_string(_bind_data: &Self::BindData) -> Option> { None @@ -192,7 +185,6 @@ impl DatabaseRef { cardinality: Some(cardinality_callback::), pushdown_complex_filter: Some(pushdown_complex_filter_callback::), pushdown_expression: ptr::null_mut::(), - get_virtual_columns: Some(get_virtual_columns_callback::), to_string: Some(to_string_callback::), table_scan_progress: Some(table_scan_progress_callback::), get_partition_data: Some(get_partition_data_callback::), diff --git a/vortex-duckdb/src/duckdb/table_function/virtual_columns.rs b/vortex-duckdb/src/duckdb/table_function/virtual_columns.rs deleted file mode 100644 index 7e4b06e48b9..00000000000 --- a/vortex-duckdb/src/duckdb/table_function/virtual_columns.rs +++ /dev/null @@ -1,43 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: Copyright the Vortex contributors - -use std::ffi::c_void; - -use vortex::error::VortexExpect; - -use crate::cpp; -use crate::duckdb::LogicalTypeRef; -use crate::duckdb::TableFunction; -use crate::lifetime_wrapper; - -/// Native callback for the get_virtual_columns function. -pub(crate) unsafe extern "C-unwind" fn get_virtual_columns_callback( - bind_data: *mut c_void, - result: cpp::duckdb_vx_tfunc_virtual_cols_result, -) { - let bind_data = - unsafe { bind_data.cast::().as_ref() }.vortex_expect("bind_data null pointer"); - let result = unsafe { VirtualColumnsResult::borrow_mut(result) }; - - T::virtual_columns(bind_data, result); -} - -lifetime_wrapper!( - VirtualColumnsResult, - cpp::duckdb_vx_tfunc_virtual_cols_result, - |_| {} -); - -impl VirtualColumnsResultRef { - pub fn register(&self, column_idx: u64, name: &str, logical_type: &LogicalTypeRef) { - unsafe { - cpp::duckdb_vx_tfunc_virtual_columns_push( - self.as_ptr(), - column_idx as _, - name.as_ptr().cast(), - name.len() as _, - logical_type.as_ptr(), - ) - } - } -}