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

NPE: SqlValidatorImpl.lookupFieldNamespace when SQL Advisor observes non-existing field

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.17.0
    • 1.18.0
    • core
    • None

    Description

      Test case (in JdbcTest):

        @Test public void testSqlAdvisorNonExistingColumn()
            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"));
        }
        SqlValidatorNamespace lookupFieldNamespace(RelDataType rowType, String name) {
          final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
          final RelDataTypeField field = nameMatcher.field(rowType, name);
          return new FieldNamespace(this, field.getType()); // <-- NPE
        }

      It looks like null-check for field resolves the exception and it suggests

      id=*; names=[*]; type=KEYWORD
      id=; names=null; type=MATCH

      Original exception:

      java.sql.SQLException: exception while executing query: null
      
      at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
      at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
      at org.apache.calcite.avatica.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:577)
      at org.apache.calcite.avatica.AvaticaPreparedStatement.executeQuery(AvaticaPreparedStatement.java:137)
      at org.apache.calcite.test.JdbcTest.adviseSql(JdbcTest.java:411)
      at org.apache.calcite.test.JdbcTest.testSqlAdvisorNonExistingColumn(JdbcTest.java:344)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
      
      Caused by: java.lang.NullPointerException
      at org.apache.calcite.sql.validate.SqlValidatorImpl.lookupFieldNamespace(SqlValidatorImpl.java:4835)
      at org.apache.calcite.sql.validate.AbstractNamespace.lookupChild(AbstractNamespace.java:144)
      at org.apache.calcite.sql.validate.IdentifierNamespace.lookupChild(IdentifierNamespace.java:42)
      at org.apache.calcite.sql.validate.SqlValidatorImpl.lookupNameCompletionHints(SqlValidatorImpl.java:800)
      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)
      ... 25 more

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: