Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-3379

Support expand STRING column expression of table during sql-to-rel conversion

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.21.0
    • Fix Version/s: 1.22.0
    • Component/s: core

      Description

      Now there are 2 ways to convert a RelOptTable to LogicalTableScan:

      1. One way is to open the Config#isConvertTableAccess[1] flag and the SqlToRelConverter would invoke the #toRel method which transforms the table to a node returned by the user(Usually a table scan).

      2. Another way is to use the LogicalTableScan rule, this rule would invoke RelOptTable#toRel and wrap the returned node with a LogicalTableScan.

       

      The difference between 1 and 2 is that, 2 happens in the planning rule but 1 happens in sql-to-rel conversion, 1 also supports to expand the table columns based on the defined default values expressions, see InitializerExpressionFactory#newColumnDefaultValue.

       

      The problem with the InitializerExpressionFactory#newColumnDefaultValue is that it uses InitializerContext#convertExpression to convert a SqlNode, but if the SqlNode is not validated, we always got a RexCall with SqlUnresolvedFunction. We should give the user chance to validate their SqlNode or even we can support pure string expressions which can be used to persist.

       

      Another problem with #toRel is that after the expressions applied as a projection, user has no chance to apply any other relational nodes if they want, we can actually support this, the same way as we support the column expressions.

       

      [1]https://github.com/apache/calcite/blob/2dc97e6723e1b5bf762540f87ffffb5cd1a848a1/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java#L5605

        Attachments

          Issue Links

          There are no Sub-Tasks for this issue.

            Activity

              People

              • Assignee:
                danny0405 Danny Chen
                Reporter:
                danny0405 Danny Chen
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 3h
                  3h