|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Lindel is a DuckDB extension that provides Hilbert and Morton (Z-order) encoding/decoding functions for multi-dimensional data linearization. It's a DuckDB Community Extension that enables sorting multi-dimensional data using space-filling curves for improved query performance on spatial or multi-field data. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Build release version |
| 13 | +GEN=ninja make release |
| 14 | + |
| 15 | +# Build debug version |
| 16 | +GEN=ninja make debug |
| 17 | + |
| 18 | +# Run all tests (requires building first) |
| 19 | +make test # runs against release build |
| 20 | +make test_debug # runs against debug build |
| 21 | + |
| 22 | +# Format code |
| 23 | +make format |
| 24 | + |
| 25 | +``` |
| 26 | + |
| 27 | +All extension functions should be documented inside of DuckDB with CreateScalarFunctionInfo or CreateAggregateFunctionInfo or the appropriate type for the function. This documentation of the function should include examples, parameter types and parameter names. The function should be categorized. |
| 28 | + |
| 29 | +When making changes the version should always be updated to the current date plus an ordinal counter in the form of YYYYMMDDCC. |
| 30 | + |
| 31 | + |
| 32 | +### macOS Setup Prerequisites |
| 33 | + |
| 34 | +```bash |
| 35 | +brew install cbindgen rustup |
| 36 | +rustup toolchain install stable |
| 37 | +rustup-init |
| 38 | +rustup default stable |
| 39 | +``` |
| 40 | + |
| 41 | +## Build Outputs |
| 42 | + |
| 43 | +- `./build/release/duckdb` - DuckDB shell with extension loaded |
| 44 | +- `./build/release/test/unittest` - Test runner |
| 45 | +- `./build/release/extension/lindel/lindel.duckdb_extension` - Loadable extension binary |
| 46 | + |
| 47 | +## Architecture |
| 48 | + |
| 49 | +### C++/Rust Hybrid |
| 50 | + |
| 51 | +The extension uses a C++/Rust hybrid architecture: |
| 52 | + |
| 53 | +1. **C++ Layer** (`src/lindel_extension.cpp`): DuckDB extension interface |
| 54 | + - Registers `hilbert_encode`, `hilbert_decode`, `morton_encode`, `morton_decode` scalar functions |
| 55 | + - Handles type validation, bind functions, and DuckDB vector operations |
| 56 | + - Uses `lindelEncodingBindData` to track encoding type (0=Hilbert, 1=Morton) |
| 57 | + |
| 58 | +2. **Rust Layer** (`duckdb_lindel_rust/`): Core encoding/decoding logic |
| 59 | + - Wraps the `lindel` Rust crate for Hilbert/Morton curve algorithms |
| 60 | + - Exposes C FFI functions via `cbindgen`-generated headers (`src/include/rust.h`) |
| 61 | + - Built as a static library linked into the extension |
| 62 | + |
| 63 | +### FFI Interface |
| 64 | + |
| 65 | +Rust functions exposed to C++: |
| 66 | +- `hilbert_encode_u8_var`, `hilbert_encode_u16_var`, `hilbert_encode_u32_var`, `hilbert_encode_u64_var` |
| 67 | +- `morton_encode_u8_var`, `morton_encode_u16_var`, `morton_encode_u32_var`, `morton_encode_u64_var` |
| 68 | +- `perform_decode` - unified decode function for both encoding types |
| 69 | + |
| 70 | +### Build System |
| 71 | + |
| 72 | +- Uses CMake with DuckDB's extension build infrastructure |
| 73 | +- Corrosion integrates Rust/Cargo into CMake build |
| 74 | +- Configuration in `extension_config.cmake` |
| 75 | +- Inherits from `extension-ci-tools/makefiles/duckdb_extension.Makefile` |
| 76 | + |
| 77 | +## Testing |
| 78 | + |
| 79 | +SQL tests are in `test/sql/lindel.test`. Run with: |
| 80 | +```bash |
| 81 | +make test # Release tests |
| 82 | +make test_debug # Debug tests |
| 83 | +./build/release/test/unittest "test/*" # Direct unittest runner |
| 84 | +``` |
| 85 | + |
| 86 | +## Key Files |
| 87 | + |
| 88 | +- `src/lindel_extension.cpp` - Main extension code with all DuckDB function implementations |
| 89 | +- `duckdb_lindel_rust/src/lib.rs` - Rust encoding/decoding implementations |
| 90 | +- `src/include/rust.h` - Auto-generated C++ headers for Rust FFI (regenerate with `make rust_binding_headers`) |
| 91 | +- `duckdb_lindel_rust/cbindgen.toml` - Configuration for header generation |
0 commit comments