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

RelToSqlConverter not handling table alias reference correctly

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.11.0
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None

      Description

      The following code fails:

          RelBuilder relBuilder = RelBuilder.create(config);
          relBuilder.scan("product")
                    .scan("product")
                    .join(JoinRelType.INNER, "product_id")
                    .filter(relBuilder.call(SqlStdOperatorTable.PLUS, relBuilder.field(0), relBuilder.literal(10)))
                    .scan("product").as("p3")
                    .join(JoinRelType.INNER, "product_id")
                    .project(relBuilder.field("p3", "product_id"));
      
          final RelToSqlConverter converter =
              new RelToSqlConverter(SqlDialect.CALCITE);
          final SqlNode sqlNode = converter.visitChild(0, relBuilder.build()).asStatement();
      

      The exception is:

      Caused by: java.lang.AssertionError: field ordinal 1 out of range {t=RecordType(INTEGER product_class_id, INTEGER product_id, VARCHAR(60) brand_name, VARCHAR(60) product_name, BIGINT SKU, DECIMAL(10, 4) SRP, DOUBLE gross_weight, DOUBLE net_weight, BOOLEAN recyclable_package, BOOLEAN low_fat, SMALLINT units_per_case, SMALLINT cases_per_pallet, DOUBLE shelf_width, DOUBLE shelf_height, DOUBLE shelf_depth), product1=RecordType(INTEGER product_class_id, INTEGER product_id, VARCHAR(60) brand_name, VARCHAR(60) product_name, BIGINT SKU, DECIMAL(10, 4) SRP, DOUBLE gross_weight, DOUBLE net_weight, BOOLEAN recyclable_package, BOOLEAN low_fat, SMALLINT units_per_case, SMALLINT cases_per_pallet, DOUBLE shelf_width, DOUBLE shelf_height, DOUBLE shelf_depth)}
      	at org.apache.calcite.rel.rel2sql.SqlImplementor$AliasContext.field(SqlImplementor.java:845)
      	at org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:512)
      	at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:151)
      

      The RelToSqlConvertor (and SqlImplementor) attempt to track the aliases but fail to do so when a filter is placed over top of the join. As of yet, I'm unsure what the fix is. This code is a bit ... cumbersome.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                jbalint@gmail.com Jess Balint
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: