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

AssertionError: RelDataTypeImpl.getFieldList when SQL Advisor inspects non-struct field

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.17.0
    • Fix Version/s: 1.18.0
    • Component/s: core
    • Labels:
      None

      Description

      Test case (in JdbcTest):

        @Test public void testSqlAdvisorNonStructColumn()
            throws SQLException, ClassNotFoundException {
          adviseSql("select e.\"empid\".^ from \"hr\".\"emps\" e",
              CalciteAssert.checkResultUnordered(
                  "id=; names=null; type=MATCH",
                  "id=hr.dependents; names=[hr, dependents]; type=TABLE",
                  "id=hr.depts; names=[hr, depts]; type=TABLE",
                  "id=hr.emps; names=[hr, emps]; type=TABLE",
                  "id=hr.locations; names=[hr, locations]; type=TABLE",
                  "id=hr; names=[hr]; type=SCHEMA"));
        }

      Relevant source from RelDataTypeImpl.getFieldList:

        public List<RelDataTypeField> getFieldList() {
          assert isStruct(); // <-- Error here
          return fieldList;
        }

      Relevant source from SqlValidatorImpl.lookupNameCompletionHints:

            if (ns != null) {
              RelDataType rowType = ns.getRowType();
              for (RelDataTypeField field : rowType.getFieldList()) { // <-- Error here
                hintList.add(
                    new SqlMonikerImpl(
                        field.getName(),
                        SqlMonikerType.COLUMN));
              }
            }

      It looks like it makes sense to add isStruct check before iterating over rowType.getFieldList().

      Any objections?

      Original exception:

      java.lang.AssertionError
      	at org.apache.calcite.rel.type.RelDataTypeImpl.getFieldList(RelDataTypeImpl.java:146)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.lookupNameCompletionHints(SqlValidatorImpl.java:808)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.lookupSelectHints(SqlValidatorImpl.java:690)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.lookupSelectHints(SqlValidatorImpl.java:701)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.lookupHints(SqlValidatorImpl.java:655)
      	at org.apache.calcite.sql.advise.SqlAdvisor.getCompletionHints(SqlAdvisor.java:235)
      	at org.apache.calcite.sql.advise.SqlAdvisor.getCompletionHints0(SqlAdvisor.java:182)
      	at org.apache.calcite.sql.advise.SqlAdvisor.getCompletionHints(SqlAdvisor.java:142)
      	at org.apache.calcite.sql.advise.SqlAdvisorGetHintsFunction.getCompletionHints(SqlAdvisorGetHintsFunction.java:105)
      	at Baz.bind(Unknown Source)
      	at org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:356)
      	at org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:309)
      	at org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:506)
      	at org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:497)
      	at org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
      	at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
      	at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
      	at org.apache.calcite.avatica.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:573)
      	at org.apache.calcite.avatica.AvaticaPreparedStatement.executeQuery(AvaticaPreparedStatement.java:137)
      	at org.apache.calcite.test.JdbcTest.adviseSql(JdbcTest.java:426)
      	at org.apache.calcite.test.JdbcTest.testSqlAdvisorNonStructColumn(JdbcTest.java:359)
      

        Attachments

        1. fieldnamespace.png
          413 kB
          Vladimir Sitnikov

          Activity

            People

            • Assignee:
              julianhyde Julian Hyde
              Reporter:
              vladimirsitnikov Vladimir Sitnikov
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: