Class SubstraitAccumulatorVisitor

  • All Implemented Interfaces:
    org.apache.calcite.sql.util.SqlVisitor<org.apache.calcite.sql.SqlNode>

    public class SubstraitAccumulatorVisitor
    extends org.apache.calcite.sql.util.SqlShuttle
    A SqlShuttle-based AST visitor that converts inline-literal SQL into a parameterized form by extracting literals and replacing them with SqlDynamicParam placeholders.

    Beyond the standard recursive AST traversal provided by SqlShuttle, this visitor does the following extra work:

    • Literal extraction & parameterization: Literals in comparisons (=, <>, >, <, >=, <=), IN, BETWEEN, and LIKE are replaced with ? params. Each extracted value is stored in the accumulator as a SubstraitTypeAndValue.
    • 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 columnStack associates literals with their column by pushing column names when visiting identifiers and peeking when visiting literals.
    • WHERE clause scoping: An inWhereClause flag 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 to WHERE is_active = ? with TRUE accumulated as the parameter.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.apache.calcite.sql.util.SqlShuttle

        org.apache.calcite.sql.util.SqlShuttle.CallCopyingArgHandler
      • Nested classes/interfaces inherited from class org.apache.calcite.sql.util.SqlBasicVisitor

        org.apache.calcite.sql.util.SqlBasicVisitor.ArgHandler<R extends Object>, org.apache.calcite.sql.util.SqlBasicVisitor.ArgHandlerImpl<R extends Object>
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.calcite.sql.SqlNode visit​(org.apache.calcite.sql.SqlCall call)  
      org.apache.calcite.sql.SqlNode visit​(org.apache.calcite.sql.SqlIdentifier id)  
      org.apache.calcite.sql.SqlNode visit​(org.apache.calcite.sql.SqlLiteral literal)  
      • Methods inherited from class org.apache.calcite.sql.util.SqlShuttle

        visit, visit, visit, visit
      • Methods inherited from interface org.apache.calcite.sql.util.SqlVisitor

        visitAll, visitNode
    • 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:
        visit in interface org.apache.calcite.sql.util.SqlVisitor<org.apache.calcite.sql.SqlNode>
        Overrides:
        visit in class org.apache.calcite.sql.util.SqlShuttle
      • visit

        public org.apache.calcite.sql.SqlNode visit​(org.apache.calcite.sql.SqlIdentifier id)
        Specified by:
        visit in interface org.apache.calcite.sql.util.SqlVisitor<org.apache.calcite.sql.SqlNode>
        Overrides:
        visit in class org.apache.calcite.sql.util.SqlShuttle
      • visit

        public org.apache.calcite.sql.SqlNode visit​(org.apache.calcite.sql.SqlLiteral literal)
        Specified by:
        visit in interface org.apache.calcite.sql.util.SqlVisitor<org.apache.calcite.sql.SqlNode>
        Overrides:
        visit in class org.apache.calcite.sql.util.SqlShuttle