Class SubstraitAccumulatorVisitor
- java.lang.Object
-
- org.apache.calcite.sql.util.SqlBasicVisitor<org.apache.calcite.sql.SqlNode>
-
- org.apache.calcite.sql.util.SqlShuttle
-
- com.amazonaws.athena.connector.substrait.SubstraitAccumulatorVisitor
-
- All Implemented Interfaces:
org.apache.calcite.sql.util.SqlVisitor<org.apache.calcite.sql.SqlNode>
public class SubstraitAccumulatorVisitor extends org.apache.calcite.sql.util.SqlShuttleASqlShuttle-based AST visitor that converts inline-literal SQL into a parameterized form by extracting literals and replacing them withSqlDynamicParamplaceholders.Beyond the standard recursive AST traversal provided by
SqlShuttle, this visitor does the following extra work:- Literal extraction & parameterization: Literals in comparisons (
=, <>, >, <, >=, <=),IN,BETWEEN, andLIKEare replaced with?params. Each extracted value is stored in theaccumulatoras aSubstraitTypeAndValue. - Schema-aware type resolution: Literal types are resolved from the column's schema type (not the literal's own type), ensuring correct Substrait type mapping.
- Column context tracking: A
columnStackassociates literals with their column by pushing column names when visiting identifiers and peeking when visiting literals. - WHERE clause scoping: An
inWhereClauseflag is set only during WHERE traversal to enable boolean-specific handling without affecting other clauses. - Implicit boolean expansion: Bare boolean column references in WHERE (e.g.,
WHERE is_active) are expanded toWHERE is_active = ?withTRUEaccumulated as the parameter.
-
-
Constructor Summary
Constructors Constructor Description SubstraitAccumulatorVisitor(List<SubstraitTypeAndValue> accumulator, org.apache.calcite.rel.type.RelDataType schema)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.calcite.sql.SqlNodevisit(org.apache.calcite.sql.SqlCall call)org.apache.calcite.sql.SqlNodevisit(org.apache.calcite.sql.SqlIdentifier id)org.apache.calcite.sql.SqlNodevisit(org.apache.calcite.sql.SqlLiteral literal)
-
-
-
Constructor Detail
-
SubstraitAccumulatorVisitor
public SubstraitAccumulatorVisitor(List<SubstraitTypeAndValue> accumulator, org.apache.calcite.rel.type.RelDataType schema)
-
-
Method Detail
-
visit
public org.apache.calcite.sql.SqlNode visit(org.apache.calcite.sql.SqlCall call)
- Specified by:
visitin interfaceorg.apache.calcite.sql.util.SqlVisitor<org.apache.calcite.sql.SqlNode>- Overrides:
visitin classorg.apache.calcite.sql.util.SqlShuttle
-
visit
public org.apache.calcite.sql.SqlNode visit(org.apache.calcite.sql.SqlIdentifier id)
- Specified by:
visitin interfaceorg.apache.calcite.sql.util.SqlVisitor<org.apache.calcite.sql.SqlNode>- Overrides:
visitin classorg.apache.calcite.sql.util.SqlShuttle
-
visit
public org.apache.calcite.sql.SqlNode visit(org.apache.calcite.sql.SqlLiteral literal)
- Specified by:
visitin interfaceorg.apache.calcite.sql.util.SqlVisitor<org.apache.calcite.sql.SqlNode>- Overrides:
visitin classorg.apache.calcite.sql.util.SqlShuttle
-
-