Skip to content

Commit 2167e61

Browse files
authored
remove unused methods from duckdb vtab (#7602)
1. Remove unused and not set methods from duckdb vtab. 2. Correctly set MAX_THREADS for table function (was u64::MAX but duckdb uses another constant). 3. Move boolean definitions like filter pushdown to C++ part. 4. Remove named parameters since we don't support them. 5. Fix a memory leak when throwing errors. Signed-off-by: Mikhail Kot <to@myrrc.dev>
1 parent c91d833 commit 2167e61

8 files changed

Lines changed: 77 additions & 258 deletions

File tree

vortex-duckdb/cpp/error.cpp

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
#include <cassert>
5-
#include <exception>
6-
4+
#include <string>
5+
#include "duckdb_vx/error.h"
76
#include "duckdb_vx/duckdb_diagnostics.h"
7+
88
DUCKDB_INCLUDES_BEGIN
9-
#include "duckdb/common/exception.hpp"
10-
#include "duckdb/common/types/vector_buffer.hpp"
11-
#include "duckdb/common/types/vector.hpp"
9+
#include "duckdb.h"
10+
#include "duckdb/common/assert.hpp"
1211
DUCKDB_INCLUDES_END
1312

14-
#include "duckdb_vx.h"
15-
1613
extern "C" duckdb_vx_error duckdb_vx_error_create(const char *message, size_t message_length) {
1714
return reinterpret_cast<duckdb_vx_error>(new std::string(message, message_length));
1815
}
@@ -33,26 +30,15 @@ std::string IntoErrString(duckdb_vx_error error) {
3330
if (!error) {
3431
return {};
3532
}
36-
return *reinterpret_cast<std::string *>(error);
33+
std::string *const error_str = reinterpret_cast<std::string *>(error);
34+
std::string out = std::move(*error_str);
35+
duckdb_vx_error_free(error);
36+
return out;
3737
}
3838

3939
duckdb_state SetError(duckdb_vx_error *error_out, std::string_view message) {
40-
assert(error_out != nullptr && "SetError called with null error_out");
40+
D_ASSERT(error_out != nullptr && "SetError called with null error_out");
4141
*error_out = duckdb_vx_error_create(message.data(), message.size());
4242
return DuckDBError;
4343
}
44-
45-
duckdb_state HandleException(std::exception_ptr ex, duckdb_vx_error *error_out) {
46-
if (!ex) {
47-
return SetError(error_out, "Unknown error");
48-
}
49-
50-
try {
51-
std::rethrow_exception(ex);
52-
} catch (const std::exception &caught) {
53-
return SetError(error_out, caught.what());
54-
} catch (...) {
55-
return SetError(error_out, "Unknown error");
56-
}
57-
}
5844
} // namespace vortex

vortex-duckdb/cpp/file_system.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ DUCKDB_INCLUDES_BEGIN
1212
#include <duckdb/main/client_context.hpp>
1313
DUCKDB_INCLUDES_END
1414

15-
#include <memory>
16-
#include <string>
1715
#include <utility>
1816

1917
using namespace duckdb;
20-
using vortex::HandleException;
2118
using vortex::SetError;
2219

2320
extern "C" duckdb_vx_file_handle

vortex-duckdb/cpp/include/duckdb_vx/error.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ DUCKDB_INCLUDES_END
1717
namespace vortex {
1818
std::string IntoErrString(duckdb_vx_error error);
1919
duckdb_state SetError(duckdb_vx_error *error_out, std::string_view message);
20-
duckdb_state HandleException(std::exception_ptr ex, duckdb_vx_error *error_out);
2120
} // namespace vortex

vortex-duckdb/cpp/include/duckdb_vx/table_function.h

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,19 @@
1212
#include "error.h"
1313
#include "table_filter.h"
1414
#include "duckdb_vx/data.h"
15-
#include "duckdb_vx/client_context.h"
1615

17-
#ifdef __cplusplus /* If compiled as C++, use C ABI */
16+
#ifdef __cplusplus
1817
extern "C" {
1918
#endif
2019

2120
// Info passed into the bind callback. The callback should set error or else add result columns.
2221
typedef struct duckdb_vx_tfunc_bind_input_ *duckdb_vx_tfunc_bind_input;
2322
typedef struct duckdb_vx_tfunc_bind_result_ *duckdb_vx_tfunc_bind_result;
2423

25-
// Fetch the parameter count from the bind info.
26-
size_t duckdb_vx_tfunc_bind_input_get_parameter_count(duckdb_vx_tfunc_bind_input ffi_input);
27-
2824
// Fetch a parameter from the bind info.
2925
// The caller is responsible for freeing the value using duckdb_value_free.
3026
duckdb_value duckdb_vx_tfunc_bind_input_get_parameter(duckdb_vx_tfunc_bind_input ffi_input, size_t index);
3127

32-
duckdb_value duckdb_vx_tfunc_bind_input_get_named_parameter(duckdb_vx_tfunc_bind_input ffi_input,
33-
const char *name_str);
34-
3528
// Add a result column to the bind info.
3629
void duckdb_vx_tfunc_bind_result_add_column(duckdb_vx_tfunc_bind_result ffi_result,
3730
const char *name_str,
@@ -90,33 +83,20 @@ typedef struct {
9083
bool has_null;
9184
} duckdb_column_statistics;
9285

93-
typedef idx_t column_t;
94-
95-
// A transparent DuckDB table function vtable, which can be used to configure a table function.
96-
// See duckdb/include/function/tfunc.hpp for details on each field.
86+
// vtable mimicking subset of TableFunction.
87+
// See duckdb/include/function/tfunc.hpp
9788
typedef struct {
98-
// The name of the table function.
9989
const char *name;
100-
101-
// The parameters of the table function.
10290
const duckdb_logical_type *parameters;
10391
size_t parameter_count;
10492

105-
// The named parameters of the table function.
106-
const duckdb_logical_type *named_parameter_types;
107-
const char *const *named_parameter_names;
108-
size_t named_parameter_count;
109-
11093
duckdb_vx_data (*bind)(duckdb_client_context ctx,
11194
duckdb_vx_tfunc_bind_input input,
11295
duckdb_vx_tfunc_bind_result result,
11396
duckdb_vx_error *error_out);
11497

11598
duckdb_vx_data (*bind_data_clone)(const void *bind_data, duckdb_vx_error *error_out);
11699

117-
// void *bind_replace;
118-
// void *bind_operator;
119-
120100
duckdb_vx_data (*init_global)(const duckdb_vx_tfunc_init_input *input, duckdb_vx_error *error_out);
121101

122102
duckdb_vx_data (*init_local)(const duckdb_vx_tfunc_init_input *input,
@@ -130,22 +110,15 @@ typedef struct {
130110
duckdb_data_chunk data_chunk_out,
131111
duckdb_vx_error *error_out);
132112

133-
// void *in_out_function;
134-
// void *in_out_function_final;
135-
136-
// false if statistics are not available
137113
bool (*statistics)(duckdb_client_context context,
138114
const void *bind_data,
139115
size_t column_index,
140116
duckdb_column_statistics *stats_out);
141117

142-
// void *dependency;
143118
void (*cardinality)(void *bind_data, duckdb_vx_node_statistics *node_stats_out);
144119

145120
bool (*pushdown_complex_filter)(void *bind_data, duckdb_vx_expr expr, duckdb_vx_error *error_out);
146121

147-
void *pushdown_expression;
148-
149122
void (*to_string)(void *bind_data, duckdb_vx_string_map map);
150123

151124
double (*table_scan_progress)(duckdb_client_context ctx, void *bind_data, void *global_state);
@@ -154,25 +127,11 @@ typedef struct {
154127
void *init_global_data,
155128
void *init_local_data,
156129
duckdb_vx_error *error_out);
157-
// void *get_bind_info;
158-
// void *type_pushdown;
159-
// void *get_multi_file_reader;
160-
// void *supports_pushdown_type;
161-
// void *get_partition_info;
162-
// void *get_partition_stats;
163-
// void *get_row_id_columns;
164-
165-
bool projection_pushdown;
166-
bool filter_pushdown;
167-
bool filter_prune;
168-
bool sampling_pushdown;
169-
bool late_materialization;
170-
idx_t max_threads;
171130
} duckdb_vx_tfunc_vtab_t;
172131

173132
// A single function for configuring the DuckDB table function vtable.
174133
duckdb_state duckdb_vx_tfunc_register(duckdb_database ffi_db, const duckdb_vx_tfunc_vtab_t *vtab);
175134

176-
#ifdef __cplusplus /* End C ABI */
135+
#ifdef __cplusplus
177136
}
178137
#endif

0 commit comments

Comments
 (0)