Embed a spatial join in Velox#

Embed a spatial join to keep the join inside a Velox plan and return the projected identifiers for matching input occurrences. The cuDF join contract provides a complete executable example with a direct spatial node, a native-plan rewrite, bounded output pages, refusals and retries.

Build and run the contract#

In an already configured build with the Velox adapter and cuDF dependencies, set BUILD_DIR to the build directory and run the command.

cmake --build "$BUILD_DIR" --target cugeo_geometry_velox_cudf_join_contract
ctest --test-dir "$BUILD_DIR" -R '^velox_cudf_spatial_join_contract$' --output-on-failure

The adapter CMake configuration also defines optional _split_resource and _pool_resource test variants.

Put the join in the plan#

Follow main() in the contract for initialization and registration. It initializes Folly and the Velox memory manager, obtains a leaf pool, disables CPU fallback with CudfConfig::allowCpuFallback = false, then calls cudf_velox::registerCudf() followed by cugeo::geometry::velox::registerCuGeo(). The selected cuDF memory resources and pool must remain valid while the plan uses them. For explicit engine-resource binding and output-pool ownership, follow the engine resource contract. That binding classifies managed memory as a missing capability.

In run(), the contract creates typed Point probe and Region build inputs, including their physical fields and geometry descriptors. It projects input identifiers and payloads through an inner SpatialJoinNode using Point-first WITHIN. JoinLimits supplies build and output limits, including the page-row limit. Adapt these inputs, projections and limits to your plan.

Rewrite a native join#

The alternative path starts with a native nested-loop join and calls insertSpatialFragments with the input field descriptions and bindings. The example checks that the rewrite places a SpatialJoinNode beneath the output projection. Fragment compilation is a host-side decision: the typed recipe must fit the supported PostGIS planar XY profile with SRID 0 before execution.

For the accepted physical column declarations and refusal classifications, see Query engine interfaces and compatibility.

Check the result and a retry#

The contract consumes the plan’s output pages and compares the sorted (point, region) occurrence pairs with an independently computed exact bag. Its main fixture has 193 points and five region records and runs with several batch and page sizes. It reports the pair count for each run. Use the oracle comparison rather than assuming one count for every case.

The checks also require one preparation, an observed pair count equal to the oracle size, bounded page capacity, both spatial operators in task statistics, and no intermediate CudfToVelox conversion. Inspect the projected identifiers and these observations in your own execution to check both matches and placement.

Inspect refusals and retry#

The contract distinguishes MissingCapability for unsupported converse written forms, ResourceLimit for small limits, and InvalidGeometry for malformed input. A resource budget can refuse work before device execution. After each covered failure, the retry runs a Point (1, 1) against a region with bounds (0, 6) through the same oracle check. Its success demonstrates that the embedding remains usable for the next request. Inspect the status and deciding layer when diagnosing your own refusal.

Close the operators and retire their device leases before releasing their resources. For an explicitly bound engine resource, follow the unbind and unregister sequence in the resource and embedding contracts while the engine resources are still valid.