vsql_complex extension is VillageSQL’s reference implementation for custom types using the VEF SDK—demonstrating production-ready extension patterns.
Source: villagesql/examples/vsql_complex/ in VillageSQL repository
What vsql_complex Provides
COMPLEX type for complex numbers (a + bi) with arithmetic, utilities, and aggregation. Usage Example:Directory Structure
VEF Registration Pattern
File:src/complex.cc
vsql_complex uses the VEF SDK with VEF_GENERATE_ENTRY_POINTS():
- Single macro call registers everything - no manual SQL needed
.compare()enables ORDER BY and indexing.hash()is optional (uses default if not provided)- Function registration uses
make_func<&impl>("name")with.build() - Type conversion uses special
.from_string<>()and.to_string<>()methods
Binary Storage Format
COMPLEX stores 16 bytes (little-endian):- Bytes 0-7: Real part (double)
- Bytes 8-15: Imaginary part (double)
Wrapper Functions
The VEF SDK allows clean C++ wrapper functions without raw UDF boilerplate: Arithmetic Example (from complex.cc):Testing Strategy
Test File (test/t/complex_create.test):Key Implementation Patterns
Manifest
File:manifest.json
Next Steps
Create Extension
Build your own extension
Extension Architecture
Understand the internals
vsql_complex Source
View complete source code
Available Extensions
Browse extension catalog