Run saved spatial SQL from the shell#
With cugeo-geometry-query on your PATH and CUGEO_GEOMETRY_CUDF_LIBRARY exported in the same shell, map the relation names in your saved SQL to input files. Keep the SQL intact: use each name from FROM and JOIN on the left side of its source mapping. Supply a logical layer when the format requires one, and declare the geometry for a CSV.
Run the checked query#
Run the following from cugeo-geometry/.
d=backends/cudf/tests/fixtures/native_geoarrow
cugeo-geometry-query --sql "$d/mixed-spatial.sql" --table "n=$d/point-XY.parquet" --csv "p=$d/points.csv" point:x,y
Here n supplies the GeoParquet relation and p supplies the tagged CSV points. Inspect stdout for the header id, label, g, tag and 11 data rows. Both near-a and near-b are expected because the CSV has two tags at (5, 5). Keep their separate matches. The query has no ORDER BY, so compare rows with their multiplicities in any order.
Save a complete result#
Redirect output and consume matches.tsv only after a zero exit.
cugeo-geometry-query --sql "$d/mixed-spatial.sql" --table "n=$d/point-XY.parquet" --csv "p=$d/points.csv" point:x,y > matches.tsv 2> query.err
The TSV includes a header and represents NULL as \N. For a direct Bash pipeline, enable set -o pipefail so a query failure is visible in the pipeline status. On failure, inspect kind and message on stderr, then stage or refusal fields when present.
Look up options#
cugeo-geometry-query --help
For the parser-derived source mappings and device limits, see Spatial SQL and query-shape support.
Count nearby trips#
Run this query against the checked-in Parquet fixture to count pickups within 0.45 degrees of a point. The threshold uses the file’s coordinate units.
Build the standalone CUDA SDK and native cuDF backend following their
backends/cuda/README.md and
backends/cudf/README.md instructions. Then build the CLI from
cugeo-geometry:
cargo build --release --locked -p cugeo-geometry-execution \
--features cudf-request --bin cugeo-geometry-query
Save the query in a file. The SQL relation trip is independent of the
Parquet filename:
cat > /tmp/cugeo-trip-count.sql <<'SQL'
SELECT COUNT(*) AS nearby_trips
FROM trip t
WHERE ST_DWithin(
ST_GeomFromWKB(t.t_pickuploc),
ST_GeomFromText('POINT (-111.7610 34.8697)'),
0.45
)
SQL
Point the CLI at the native library and the checked-in file:
CUGEO_GEOMETRY_CUDF_LIBRARY=/path/to/libcugeo_geometry_cudf.so \
target/release/cugeo-geometry-query --sql /tmp/cugeo-trip-count.sql \
--table trip=crates/execution/tests/fixtures/spatialbench-q1-local-files/trip.parquet
The TSV has one bigint column and one row:
nearby_trips
126
The fixture’s pinned independent
crates/execution/tests/fixtures/spatialbench-q1-local-files/q1-expected.json
records 129 input rows and 126 rows that satisfy this predicate. COUNT(*)
returns one row even when no input row qualifies. For a file of your own,
replace the path and SQL relation mapping together. A Parquet geometry column
is binary, so the spatial predicate decodes it with ST_GeomFromWKB. See
Input formats for the other file readers.
Check a failed run#
This valid PostgreSQL query uses a set operation the cuGeo SQL frontend does not admit:
cat > /tmp/cugeo-union.sql <<'SQL'
SELECT t_tripkey FROM trip UNION SELECT t_tripkey FROM trip
SQL
CUGEO_GEOMETRY_CUDF_LIBRARY=/path/to/libcugeo_geometry_cudf.so \
target/release/cugeo-geometry-query --sql /tmp/cugeo-union.sql \
--table trip=crates/execution/tests/fixtures/spatialbench-q1-local-files/trip.parquet \
2> /tmp/cugeo-query-error.json
The command exits with status 5 and writes a primary JSON failure record.
If trimming also fails, a query_cleanup_error record precedes it. Select
the primary record by its top-level marker:
uv run --no-project python3 - <<'PY'
import json
from pathlib import Path
records = (json.loads(line) for line in
Path('/tmp/cugeo-query-error.json').read_text().splitlines())
record = next(record for record in records if record.get('query_error') == 2)
print(record['kind'], record['stage'], record['layer'], record['sql_code'])
print(record['refusal_class'] is not None)
PY
query sql_compilation frontend Unsupported
True
This SQL-frontend refusal has all five deciding_* fields set to null.
A canonical binder failure supplies its typed cause in those fields.
The record has a refusal class; use it with the layer to choose a supported
query form or another engine.
The diagnostic message explains this instance but is not a stable value to
parse. Errors and refusals describes
the other fields and exit statuses.