You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Jess Balint (JIRA)" <ji...@apache.org> on 2017/01/27 23:00:26 UTC

[jira] [Created] (CALCITE-1611) RelToSqlConverter not handling table alias reference correctly

Jess Balint created CALCITE-1611:
------------------------------------

             Summary: RelToSqlConverter not handling table alias reference correctly
                 Key: CALCITE-1611
                 URL: https://issues.apache.org/jira/browse/CALCITE-1611
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.11.0
            Reporter: Jess Balint
            Assignee: Julian Hyde
            Priority: Minor


The following code fails:
{code:java}
    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();
{code}

The exception is:
{noformat}
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)
{noformat}

The {{RelToSqlConvertor}} (and {{SqlImplementor}}) is attempt to track the aliases but fails 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.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)