Skip to content

Commit d79e511

Browse files
committed
bump duckdb to 1.3
1 parent 6a80b20 commit d79e511

19 files changed

+635
-408
lines changed

.github/workflows/MainDistributionPipeline.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ jobs:
1616
name: Build extension binaries
1717
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@6a7a4f24c5999355ab36c0a6835baf891fc9d522
1818
with:
19-
duckdb_version: v1.2.2
20-
ci_tools_version: 6a7a4f24c5999355ab36c0a6835baf891fc9d522
19+
ci_tools_version: 1f00107ca1eaf1691049907296a8aa796d054e6b
20+
duckdb_version: ad1273222186d28b4b351736ed88101044bbe97b
2121
extension_name: vortex
2222
exclude_archs: "wasm_mvp;wasm_eh;wasm_threads;windows_amd64_rtools;windows_amd64_mingw;windows_amd64;linux_arm64"
2323
extra_toolchains: "rust"
24-
override_ci_tools_repository: spiraldb/extension-ci-tools

CMakeLists.txt

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,34 @@ project(${TARGET_NAME}_project)
66
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
77
set(CMAKE_CXX_STANDARD 17)
88

9+
# Allow C++20 designator syntax in C++17
10+
add_compile_options(-Wno-c++20-designator)
11+
912
include(FetchContent)
1013
FetchContent_Declare(
11-
Corrosion
12-
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
13-
GIT_TAG v0.5.2
14+
Corrosion
15+
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
16+
GIT_TAG v0.5.2
1417
)
1518

1619
FetchContent_MakeAvailable(Corrosion)
1720

1821
find_package(Catch2 CONFIG REQUIRED)
1922
find_package(Protobuf CONFIG REQUIRED)
23+
2024
if (APPLE)
2125
find_library(SECURITY_FRAMEWORK Security)
2226
endif ()
2327

2428
corrosion_import_crate(MANIFEST_PATH vortex/Cargo.toml
25-
CRATES vortex-ffi
26-
FEATURES duckdb
27-
CRATE_TYPES staticlib
28-
FLAGS --crate-type=staticlib
29+
CRATES vortex-ffi
30+
FEATURES duckdb mimalloc
31+
CRATE_TYPES staticlib
32+
FLAGS --crate-type=staticlib
2933
)
3034

3135
set(EXTENSION_NAME ${TARGET_NAME}_extension)
32-
set(EXTENSION_SOURCES src/vortex_extension.cpp src/expr/expr.cpp src/vortex_write.cpp src/vortex_scan.cpp)
36+
set(EXTENSION_SOURCES src/vortex_extension.cpp src/vortex_expr.cpp src/vortex_write.cpp src/vortex_scan.cpp)
3337
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
3438

3539
# Generate C++ code from .proto files.
@@ -38,22 +42,23 @@ set(PROTO_GEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gen)
3842
file(MAKE_DIRECTORY ${PROTO_GEN_DIR})
3943
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES} PROTOC_OUT_DIR ${PROTO_GEN_DIR})
4044

41-
include_directories(src/include ${PROTO_GEN_DIR} vortex/vortex-ffi/cinclude)
45+
include_directories(src/include ${PROTO_GEN_DIR} ../vortex-ffi/cinclude)
4246

4347
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES} ${PROTO_SRCS})
44-
build_loadable_extension(${TARGET_NAME} ${EXTENSION_SOURCES} ${PROTO_SRCS})
48+
set(PARAMETERS "-warnings")
49+
build_loadable_extension(${TARGET_NAME} ${PARAMETERS} ${EXTENSION_SOURCES} ${PROTO_SRCS})
4550

4651
target_link_libraries(${EXTENSION_NAME}
47-
vortex_ffi-static
48-
protobuf::libprotobuf
49-
${SECURITY_FRAMEWORK}
52+
vortex_ffi-static
53+
protobuf::libprotobuf
54+
${SECURITY_FRAMEWORK}
5055
)
5156

5257
add_subdirectory(test)
5358

5459
install(
55-
TARGETS ${EXTENSION_NAME}
56-
EXPORT "${DUCKDB_EXPORT_SET}"
57-
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
58-
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
60+
TARGETS ${EXTENSION_NAME}
61+
EXPORT "${DUCKDB_EXPORT_SET}"
62+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
63+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
5964
)

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@ PROJ_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
22

33
EXT_NAME=vortex_duckdb
44
EXT_CONFIG=${PROJ_DIR}extension_config.cmake
5-
EXT_FLAGS=-DCMAKE_OSX_DEPLOYMENT_TARGET=12.0 -DOVERRIDE_GIT_DESCRIBE=v1.2.2
5+
EXT_FLAGS=-DCMAKE_OSX_DEPLOYMENT_TARGET=12.0
66

7+
export OVERRIDE_GIT_DESCRIBE=v1.3.0
78
export MACOSX_DEPLOYMENT_TARGET=12.0
8-
export VCPKG_OSX_DEPLOYMENT_TARGET=12.0
99
export VCPKG_FEATURE_FLAGS=-binarycaching
10+
export VCPKG_OSX_DEPLOYMENT_TARGET=12.0
1011
export VCPKG_TOOLCHAIN_PATH := ${PROJ_DIR}vcpkg/scripts/buildsystems/vcpkg.cmake
1112

13+
export BUILD_MAIN_DUCKDB_LIBRARY=0
14+
export DISABLE_BUILTIN_EXTENSIONS=1
15+
16+
# This is not needed on macOS, we don't see a tls error on load there.
17+
ifeq ($(shell uname), Linux)
18+
export CFLAGS=-ftls-model=global-dynamic
19+
endif
20+
1221
include extension-ci-tools/makefiles/duckdb_extension.Makefile

duckdb

extension_config.cmake

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@
44
duckdb_extension_load(vortex
55
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}
66
LOAD_TESTS
7-
)
8-
9-
# Any extra extensions that should be built
10-
# e.g.: duckdb_extension_load(json)
7+
)

src/include/vortex.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1+
// This header prefixes the auto-generated vortex.h with #pragma once.
12
#pragma once
2-
3-
4-
// Include Vortex FFI, with the DuckDB FFI feature
5-
#ifndef ENABLE_DUCKDB_FFI
6-
#define ENABLE_DUCKDB_FFI
7-
#endif
8-
9-
#include "vortex.h"
3+
#include "vortex.h"

src/include/vortex_common.hpp

Lines changed: 115 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,162 @@
11
#pragma once
2+
#define ENABLE_DUCKDB_FFI
23

34
#include "duckdb.hpp"
5+
#include "duckdb/common/unique_ptr.hpp"
6+
47
#include "vortex.hpp"
58
#include "vortex_error.hpp"
9+
#include "vortex_session.hpp"
10+
11+
namespace vortex {
12+
13+
struct DType {
14+
explicit DType(vx_dtype *dtype) : dtype(dtype) {
15+
}
16+
17+
static duckdb::unique_ptr<DType> FromDuckDBTable(const std::vector<duckdb_logical_type> &column_types,
18+
const std::vector<unsigned char> &column_nullable,
19+
const std::vector<const char *> &column_names) {
20+
D_ASSERT(column_names.size() == column_nullable.size());
21+
D_ASSERT(column_names.size() == column_types.size());
622

7-
#include <duckdb/common/unique_ptr.hpp>
23+
auto dtype = Try([&](auto err) {
24+
return vx_duckdb_logical_type_to_dtype(column_types.data(), column_nullable.data(), column_names.data(),
25+
column_names.size(), err);
26+
});
827

9-
struct VortexConversionCache {
10-
explicit VortexConversionCache(const unsigned long cache_id) : cache(vx_conversion_cache_create(cache_id)) {
28+
return duckdb::make_uniq<DType>(dtype);
1129
}
1230

13-
~VortexConversionCache() {
31+
~DType() {
32+
if (dtype != nullptr) {
33+
vx_dtype_free(dtype);
34+
}
35+
}
36+
37+
vx_dtype *dtype;
38+
};
39+
40+
struct ConversionCache {
41+
explicit ConversionCache(const unsigned long cache_id) : cache(vx_conversion_cache_create(cache_id)) {
42+
}
43+
44+
~ConversionCache() {
1445
vx_conversion_cache_free(cache);
1546
}
1647

1748
vx_conversion_cache *cache;
1849
};
1950

20-
struct VortexFileReader {
21-
explicit VortexFileReader(vx_file_reader *file) : file(file) {
51+
struct FileReader {
52+
explicit FileReader(vx_file_reader *file) : file(file) {
2253
}
2354

24-
~VortexFileReader() {
55+
~FileReader() {
2556
vx_file_reader_free(file);
2657
}
2758

28-
static duckdb::unique_ptr<VortexFileReader> Open(const vx_file_open_options *options) {
29-
vx_error *error;
30-
auto file = vx_file_open_reader(options, &error);
31-
HandleError(error);
32-
return duckdb::make_uniq<VortexFileReader>(file);
59+
static duckdb::unique_ptr<FileReader> Open(const vx_file_open_options *options, VortexSession &session) {
60+
auto file = Try([&](auto err) { return vx_file_open_reader(options, session.session, err); });
61+
return duckdb::make_uniq<FileReader>(file);
62+
}
63+
64+
vx_array_iterator *Scan(const vx_file_scan_options *options) {
65+
return Try([&](auto err) { return vx_file_reader_scan(this->file, options, err); });
66+
}
67+
68+
bool CanPrune(const char *filter_expression, unsigned int filter_expression_len) {
69+
return Try([&](auto err) {
70+
return vx_file_reader_can_prune(this->file, filter_expression, filter_expression_len, err);
71+
});
72+
}
73+
74+
uint64_t FileRowCount() {
75+
return Try([&](auto err) { return vx_file_row_count(file, err); });
76+
}
77+
78+
struct DType DType() {
79+
return vortex::DType(vx_file_dtype(file));
3380
}
3481

3582
vx_file_reader *file;
3683
};
3784

38-
struct VortexArray {
39-
explicit VortexArray(vx_array *array) : array(array) {
85+
struct Array {
86+
explicit Array(vx_array *array) : array(array) {
4087
}
4188

42-
~VortexArray() {
89+
~Array() {
4390
if (array != nullptr) {
4491
vx_array_free(array);
4592
}
4693
}
4794

48-
idx_t ToDuckDBVector(idx_t current_row, duckdb_data_chunk output, const VortexConversionCache *cache) const {
49-
vx_error *error;
50-
auto idx = vx_array_to_duckdb_chunk(array, current_row, output, cache->cache, &error);
51-
HandleError(error);
52-
return idx;
95+
static duckdb::unique_ptr<Array> FromDuckDBChunk(DType &dtype, duckdb::DataChunk &chunk) {
96+
auto array = Try([&](auto err) {
97+
return vx_duckdb_chunk_to_array(reinterpret_cast<duckdb_data_chunk>(&chunk), dtype.dtype, err);
98+
});
99+
100+
return duckdb::make_uniq<Array>(array);
101+
}
102+
103+
idx_t ToDuckDBVector(idx_t current_row, duckdb_data_chunk output, const ConversionCache *cache) const {
104+
return Try([&](auto err) { return vx_array_to_duckdb_chunk(array, current_row, output, cache->cache, err); });
53105
}
54106

55107
vx_array *array;
56108
};
57109

58-
struct VortexArrayStream {
59-
explicit VortexArrayStream(vx_array_stream *array_stream) : array_stream(array_stream) {
110+
struct ArrayIterator {
111+
explicit ArrayIterator(vx_array_iterator *array_iter) : array_iter(array_iter) {
60112
}
61113

62-
~VortexArrayStream() {
63-
vx_array_stream_free(array_stream);
114+
~ArrayIterator() {
115+
vx_array_iter_free(array_iter);
64116
}
65117

66-
duckdb::unique_ptr<VortexArray> NextArray() const {
67-
vx_error *error;
68-
auto array = vx_array_stream_next(array_stream, &error);
69-
HandleError(error);
118+
duckdb::unique_ptr<Array> NextArray() const {
119+
auto array = Try([&](auto err) { return vx_array_iter_next(array_iter, err); });
120+
70121
if (array == nullptr) {
71122
return nullptr;
72123
}
73-
return duckdb::make_uniq<VortexArray>(array);
124+
125+
return duckdb::make_uniq<Array>(array);
74126
}
75127

76-
vx_array_stream *array_stream;
128+
vx_array_iterator *array_iter;
77129
};
130+
131+
struct ArrayStreamSink {
132+
explicit ArrayStreamSink(vx_array_sink *sink, duckdb::unique_ptr<DType> dtype)
133+
: sink(sink), dtype(std::move(dtype)) {
134+
}
135+
136+
static duckdb::unique_ptr<ArrayStreamSink> Create(std::string file_path, duckdb::unique_ptr<DType> &&dtype) {
137+
auto sink = Try([&](auto err) { return vx_array_sink_open_file(file_path.c_str(), dtype->dtype, err); });
138+
return duckdb::make_uniq<ArrayStreamSink>(sink, std::move(dtype));
139+
}
140+
141+
void PushChunk(duckdb::DataChunk &chunk) {
142+
auto array = Array::FromDuckDBChunk(*dtype, chunk);
143+
Try([&](auto err) { vx_array_sink_push(sink, array->array, err); });
144+
}
145+
146+
void Close() {
147+
Try([&](auto err) { vx_array_sink_close(sink, err); });
148+
this->sink = nullptr;
149+
}
150+
151+
~ArrayStreamSink() {
152+
// "should dctor a sink, before closing it
153+
// If you throw during writes then the stack will be unwound and the destructor is going to be called before the
154+
// close method is invoked thus triggering following assertion failure and will clobber the exception printing
155+
// D_ASSERT(sink == nullptr);
156+
}
157+
158+
vx_array_sink *sink;
159+
duckdb::unique_ptr<DType> dtype;
160+
};
161+
162+
} // namespace vortex

src/include/vortex_error.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
#pragma once
22

3+
#include <string>
4+
#include <type_traits>
5+
6+
#include "duckdb.hpp"
37
#include "vortex.hpp"
48

9+
namespace vortex {
10+
511
inline void HandleError(vx_error *error) {
612
if (error != nullptr) {
713
auto msg = std::string(vx_error_get_message(error));
814
vx_error_free(error);
915
throw duckdb::InvalidInputException(msg);
1016
}
1117
}
18+
19+
template <typename Func>
20+
auto Try(Func func) {
21+
vx_error *error = nullptr;
22+
// Handle both void and non-void return types.
23+
if constexpr (std::is_void_v<std::invoke_result_t<Func, vx_error **>>) {
24+
func(&error);
25+
HandleError(error);
26+
} else {
27+
auto result = func(&error);
28+
HandleError(error);
29+
return result;
30+
}
31+
}
32+
33+
} // namespace vortex
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#pragma once
22

3-
#include "expr.pb.h"
43
#include "duckdb/planner/expression.hpp"
4+
#include "duckdb/planner/table_filter.hpp"
55

6-
#include <duckdb/planner/table_filter.hpp>
6+
#include "expr.pb.h"
77

8+
namespace vortex {
89
vortex::expr::Expr *table_expression_into_expr(google::protobuf::Arena &arena, duckdb::TableFilter &filter,
910
const std::string &column_name);
10-
1111
vortex::expr::Expr *expression_into_vortex_expr(google::protobuf::Arena &arena, const duckdb::Expression &expr);
12-
1312
vortex::expr::Expr *flatten_exprs(google::protobuf::Arena &arena,
14-
const duckdb::vector<vortex::expr::Expr *> &child_filters);
13+
const duckdb::vector<vortex::expr::Expr *> &child_filters);
14+
} // namespace vortex

0 commit comments

Comments
 (0)