Skip to content
Merged
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 @@ -69,6 +69,7 @@ members = [
# Benchmarks website v3 (alpha) - leaf binary, not part of vortex-* API
"benchmarks-website/server",
"benchmarks-website/migrate",
"vortex-geo",
]
exclude = ["java/testfiles", "wasm-test"]
resolver = "2"
Expand Down Expand Up @@ -161,6 +162,9 @@ flatbuffers = "25.2.10"
fsst-rs = "0.5.11"
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 @@ -267,6 +271,7 @@ tracing-subscriber = "0.3"
url = "2.5.7"
uuid = { version = "1.23", 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 @@ -290,6 +295,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-json = { version = "0.1.0", path = "./vortex-json", 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 @@ -40,16 +40,19 @@ tracing = { workspace = true }
tracing-subscriber = { 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 @@ -12,6 +12,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
15 changes: 15 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,28 @@

#pragma once

#include "duckdb.h"

#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`. Returns `{nullptr, 0}`
/// if `value` is null or not a GEOMETRY value.
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 @@ -4,6 +4,7 @@
#include "duckdb_vx/logical_type.h"
#include "duckdb/common/types.hpp"
#include <cassert>
#include <string>

duckdb_logical_type duckdb_vx_logical_type_copy(duckdb_logical_type ty) {
D_ASSERT(ty);
Expand All @@ -19,3 +20,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 thread
a10y marked this conversation as resolved.
Comment thread
a10y marked this conversation as resolved.
}
Comment on lines +24 to +30

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.

28 changes: 28 additions & 0 deletions vortex-duckdb/cpp/value.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

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

#include "duckdb_vx.h"
Expand All @@ -10,3 +11,30 @@ 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) {
if (value == nullptr) {
return {nullptr, 0};
}
const auto val = reinterpret_cast<duckdb::Value *>(value);
if (val->type().id() != duckdb::LogicalTypeId::GEOMETRY) {
return {nullptr, 0};
}
const auto &str = duckdb::StringValue::Get(*val);
Comment thread
a10y marked this conversation as resolved.
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