Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ members = [
"benchmarks/duckdb-bench",
"benchmarks/random-access-bench",
"benchmarks/vector-search-bench",
"vortex-geo",
]
exclude = ["java/testfiles", "wasm-test"]
resolver = "2"
Expand Down Expand Up @@ -151,6 +152,9 @@ flatbuffers = "25.2.10"
fsst-rs = "0.5.5"
futures = { version = "0.3.31", default-features = false }
fuzzy-matcher = "0.3"
geo-traits = "0.3.0"
geo-types = "0.7.19"
geoarrow = "0.8.0"
get_dir = "0.5.0"
glob = "0.3.2"
goldenfile = "1"
Expand Down Expand Up @@ -256,6 +260,7 @@ tracing-subscriber = "0.3"
url = "2.5.7"
uuid = { version = "1.21", features = ["js"] }
wasm-bindgen-futures = "0.4.54"
wkb = "0.9.2"
xshell = "0.2.6"
zigzag = "0.1.0"
zip = "8.0.0"
Expand All @@ -279,6 +284,7 @@ vortex-fastlanes = { version = "0.1.0", path = "./encodings/fastlanes", default-
vortex-file = { version = "0.1.0", path = "./vortex-file", default-features = false }
vortex-flatbuffers = { version = "0.1.0", path = "./vortex-flatbuffers", default-features = false }
vortex-fsst = { version = "0.1.0", path = "./encodings/fsst", default-features = false }
vortex-geo = { version = "0.1.0", path = "./vortex-geo", default-features = false }
vortex-io = { version = "0.1.0", path = "./vortex-io", default-features = false }
vortex-ipc = { version = "0.1.0", path = "./vortex-ipc", default-features = false }
vortex-layout = { version = "0.1.0", path = "./vortex-layout", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions vortex-duckdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ paste = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }
vortex = { workspace = true, features = ["files", "tokio", "object_store"] }
vortex-geo = { workspace = true }
vortex-utils = { workspace = true, features = ["dashmap"] }

[dev-dependencies]
anyhow = { workspace = true }
geo-types = { workspace = true }
jiff = { workspace = true }
rstest = { workspace = true }
tempfile = { workspace = true }
vortex-array = { workspace = true, features = ["_test-harness"] }
vortex-runend = { workspace = true }
vortex-sequence = { workspace = true }
wkb = { workspace = true }

[lints]
workspace = true
Expand Down
4 changes: 4 additions & 0 deletions vortex-duckdb/cpp/include/duckdb_vx/logical_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ extern "C" {
char *duckdb_vx_logical_type_stringify(duckdb_logical_type ty);
duckdb_logical_type duckdb_vx_logical_type_copy(duckdb_logical_type ty);

/// Creates a GEOMETRY logical type with the given CRS (Coordinate Reference System).
/// `crs` must be a NUL-terminated UTF-8 string. Pass an empty string for no CRS.
duckdb_logical_type duckdb_vx_create_geometry(const char *crs);

#ifdef __cplusplus /* End C ABI */
}
#endif
19 changes: 19 additions & 0 deletions vortex-duckdb/cpp/include/duckdb_vx/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,32 @@

#pragma once

#include "duckdb_vx/duckdb_diagnostics.h"

DUCKDB_INCLUDES_BEGIN
#include "duckdb.h"
DUCKDB_INCLUDES_END

#ifdef __cplusplus /* If compiled as C++, use C ABI */
extern "C" {
#endif

// Create a null value with a reference to a logical type.
duckdb_value duckdb_vx_value_create_null(duckdb_logical_type ty);

/// Creates a GEOMETRY value containing the given WKB bytes and CRS.
///
/// `wkb` points to `len` bytes of well-known-binary geometry data; the bytes are not validated.
/// `crs` must be a NUL-terminated UTF-8 string; pass NULL or an empty string for no CRS.
duckdb_value duckdb_vx_value_create_geometry(const uint8_t *wkb, idx_t len, const char *crs);

/// Extracts the raw WKB bytes from a GEOMETRY value as a duckdb_blob.
///
/// This bypasses the GEOMETRY -> BLOB default cast (which would require the spatial extension to
/// be loaded). The returned `data` pointer must be freed with `duckdb_free`. The caller must
/// ensure `value` is a non-null GEOMETRY value, otherwise behavior is undefined.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memory unsafe??

duckdb_blob duckdb_vx_value_get_geometry(duckdb_value value);

#ifdef __cplusplus /* End C ABI */
}
#endif
9 changes: 9 additions & 0 deletions vortex-duckdb/cpp/logical_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ DUCKDB_INCLUDES_BEGIN
#include "duckdb/common/types.hpp"
DUCKDB_INCLUDES_END
#include <cassert>
#include <string>

duckdb_logical_type duckdb_vx_logical_type_copy(duckdb_logical_type ty) {
D_ASSERT(ty);
Expand All @@ -23,3 +24,11 @@ char *duckdb_vx_logical_type_stringify(duckdb_logical_type c_type) {
memcpy(result, str.c_str(), str.size() + 1);
return result;
}

duckdb_logical_type duckdb_vx_create_geometry(const char *crs) {
D_ASSERT(crs);
auto geom =
(*crs == '\0') ? duckdb::LogicalType::GEOMETRY() : duckdb::LogicalType::GEOMETRY(std::string(crs));
auto copy = duckdb::make_uniq<duckdb::LogicalType>(std::move(geom));
return reinterpret_cast<duckdb_logical_type>(copy.release());
Comment on lines +32 to +33
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude generated this function and the header update, most of the rest of the PR was braincoded

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha braincoded

}
Comment on lines +28 to +34
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These C++ changes are because DuckDB upstream doesn't expose the full geometry type stuff over the C API.

22 changes: 22 additions & 0 deletions vortex-duckdb/cpp/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "duckdb_vx/duckdb_diagnostics.h"

DUCKDB_INCLUDES_BEGIN
#include "duckdb/common/types/geometry_crs.hpp"
#include "duckdb/common/types/value.hpp"
DUCKDB_INCLUDES_END

Expand All @@ -14,3 +15,24 @@ extern "C" duckdb_value duckdb_vx_value_create_null(duckdb_logical_type ty) {
auto value = duckdb::make_uniq<duckdb::Value>(*logical_type);
return reinterpret_cast<duckdb_value>(value.release());
}

extern "C" duckdb_value duckdb_vx_value_create_geometry(const uint8_t *wkb, idx_t len, const char *crs) {
const auto bytes = reinterpret_cast<duckdb::const_data_ptr_t>(wkb);
auto value =
(crs == nullptr || *crs == '\0')
? duckdb::Value::GEOMETRY(bytes, len)
: duckdb::Value::GEOMETRY(bytes, len, duckdb::CoordinateReferenceSystem(std::string(crs)));
auto owned = duckdb::make_uniq<duckdb::Value>(std::move(value));
return reinterpret_cast<duckdb_value>(owned.release());
}

extern "C" duckdb_blob duckdb_vx_value_get_geometry(duckdb_value value) {
const auto val = reinterpret_cast<duckdb::Value *>(value);
const auto &str = duckdb::StringValue::Get(*val);
Comment on lines +30 to +31
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a panic or memory unsafe is val is not a string type?

const auto size = str.size();
auto buf = reinterpret_cast<void *>(duckdb_malloc(size));
if (size > 0) {
memcpy(buf, str.c_str(), size);
}
return {buf, size};
}
Loading
Loading