yobx.sql.sql_convert#
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:
JoinOp— equi-join on a key column.FilterOp— boolean mask applied to all columns.GroupByOp— group key used for aggregations.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,ReduceMax—SUM / AVG / MIN / MAXaggregations (global, when noGROUP BY).Unique— extracting distinct group keys forGROUP BY.ScatterElements— per-group accumulation forGROUP BYaggregations.
Limitations#
Only equi-joins on a single key column are supported.
GROUP BYwithSUM,AVG,MIN,MAX,COUNT(*)produces one output row per unique key combination. For multi-columnGROUP BYthe key columns are internally cast tofloat64before grouping, which may lose precision for integers larger than 2^53.SELECT DISTINCTis not yet supported and raisesNotImplementedError.