yobx.sql — convert module#

SQL to ONNX converter.

sql_to_onnx() converts a SQL query string into a self-contained onnx.ModelProto.

Design#

Every referenced column becomes a separate 1-D ONNX input so that the caller can supply column vectors independently (matching the convention used for tabular data). The converter processes the ParsedQuery operation list in execution order:

  1. JoinOp — equi-join on a key column.

  2. FilterOp — boolean mask applied to all columns.

  3. GroupByOp — group key used for aggregations.

  4. SelectOp — column expressions emitted as outputs.

ONNX operations used#

  • Compress — row-wise filtering (WHERE clause).

  • Gather — index-based row selection (JOIN / GROUP BY key alignment).

  • Add, Sub, Mul, Div — arithmetic expressions.

  • Equal, Less, Greater, LessOrEqual, GreaterOrEqual — comparison predicates.

  • And, Or — compound predicates.

  • ReduceSum, ReduceMean, ReduceMin, ReduceMaxSUM / AVG / MIN / MAX aggregations.

Limitations#

  • Only equi-joins on a single key column are supported.

  • GROUP BY aggregation is limited to the row-wise functions listed above; true SQL group-by semantics (unique key extraction) are not yet implemented as ONNX lacks a native GroupBy node.

  • COUNT(*) emits the total row count as a scalar int64 tensor.

  • SELECT DISTINCT is not yet supported and raises NotImplementedError.