Integrate Geometry with libcudf columns#
Decode a sliced WKB column and return it to the engine with its identifiers still aligned. The ID-to-point association checks the slice origin as well as the row count.
Check the input slice#
Start with engine IDs 10, 20, 30 and a WKB column containing Point (0,0), (1,1), (2,2). Slice both columns to the last two rows. Check the WKB view against its column_declaration with find_column_mismatch. Fix an input type or layout mismatch before decoding. The admitted cuDF layout is STRING with signed Int32 or Int64 offsets.
Describe the WKB slice with describe_wkb_column and check its addresses.
Use three offset entries starting at parent index 1 relative to the offsets child’s origin. They still address the original payload base.
The byte span must cover the WKB bytes reached by those offsets.
A present null mask uses bit offset 1, so it addresses the same two rows.
For an empty column with no offsets buffer, supply the single zero offset allocated by describe_wkb_column and keep its owner alive through the SDK call. See the slice, empty-column, export, and stream-order checks in backends/cudf-interop/tests/wkb_column_test.cpp.
Decode and export#
Bind spatial_session to the engine’s current CUDA context and device, choose the semantic profile for the plan, and adapt the engine’s output memory resource. Call decode_wkb with the sliced view, its Point family and identity, the producer stream, and the resource. Check both its SDK status and its family or axes mismatch before using the returned geometry.
For this round trip, enqueue WKB export with geometry_export. Its SDK Arrow export owns the validity, offsets, and payload spans described by written_wkb(). The caller supplies the outcome words. Read the spans only after export work completes and the failure word is zero, using the reported payload length. Retain the export and relevant outcome storage through the engine’s last dependent read. A different consumer stream must be ordered after the export work.
Copy or inspect the export#
If the consumer needs an independent cuDF column, use copy_wkb_export with a blocking export that has Int64 offsets and populated size metadata. Retain that export through the copy. Choosing an allocator alone does not make an independent copy.
After completion, decode the returned WKB for inspection and print it beside the retained IDs. Expect 20 with (1,1) and 30 with (2,2). The API and ownership contracts are in backends/cudf-interop/README.md.
Gather rows from a join#
For a join that returns pairs, borrow its pair view on the engine stream and check the view. Verify that each left and right ordinal is within the corresponding input’s row count, then use gather_pairs to select the engine rows. Retain the pair lease until the gather’s dependent reads are enqueued and retire it with the stream still valid.
Keep the session, resource and callback state, input and output owners, and leases alive for outstanding stream work, including during exception unwinding. If retirement by lease_owner fails, it transfers the live lease and its retained owners to the session’s quarantine for retry.