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

AssertionError thrown for user-defined table function with array argument

    XMLWordPrintableJSON

    Details

      Description

      Steps to reproduce:

      1. Add method with list parameter to Smalls.java

        public static final Method GENERATE_STRINGS_2_METHOD =
            Types.lookupMethod(Smalls.class, "generateStrings2", List.class);
        public static QueryableTable generateStrings2(final List<Integer> list) {
          return generateStrings(list.size());
        }
      

      2. Add test method which uses new user-defined table function to TableFunctionTest.java

        @Test public void testTableFunction2() throws SQLException {
          try (Connection connection = DriverManager.getConnection("jdbc:calcite:")) {
            CalciteConnection calciteConnection =
                connection.unwrap(CalciteConnection.class);
            SchemaPlus rootSchema = calciteConnection.getRootSchema();
            SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
            final TableFunction table =
                TableFunctionImpl.create(Smalls.GENERATE_STRINGS_2_METHOD);
            schema.add("GenerateStrings2", table);
            final String sql = "select *\n"
                + "from table(\"s\".\"GenerateStrings2\"(5,4,3,1,2)) as t(n, c)\n"
                + "where char_length(c) > 3";
            ResultSet resultSet = connection.createStatement().executeQuery(sql);
            assertThat(CalciteAssert.toString(resultSet),
                equalTo("N=4; C=abcd\n"));
          }
        }
      

      Execution result produced by such test method is the following stack trace:

      java.lang.AssertionError: use createArrayType() instead
      
      	at org.apache.calcite.sql.type.SqlTypeFactoryImpl.assertBasic(SqlTypeFactoryImpl.java:221)
      	at org.apache.calcite.sql.type.SqlTypeFactoryImpl.createSqlType(SqlTypeFactoryImpl.java:48)
      	at org.apache.calcite.jdbc.JavaTypeFactoryImpl.toSql(JavaTypeFactoryImpl.java:255)
      	at org.apache.calcite.prepare.CalciteCatalogReader.toSql(CalciteCatalogReader.java:381)
      	at org.apache.calcite.prepare.CalciteCatalogReader.lambda$toSql$7(CalciteCatalogReader.java:370)
      	at com.google.common.collect.Lists$TransformingRandomAccessList$1.transform(Lists.java:640)
      	at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
      	at java.util.AbstractCollection.toArray(AbstractCollection.java:141)
      	at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:239)
      	at org.apache.calcite.sql.SqlFunction.<init>(SqlFunction.java:123)
      	at org.apache.calcite.sql.validate.SqlUserDefinedFunction.<init>(SqlUserDefinedFunction.java:63)
      	at org.apache.calcite.sql.validate.SqlUserDefinedTableFunction.<init>(SqlUserDefinedTableFunction.java:45)
      	at org.apache.calcite.prepare.CalciteCatalogReader.toOp(CalciteCatalogReader.java:338)
      	at org.apache.calcite.prepare.CalciteCatalogReader.toOp(CalciteCatalogReader.java:302)
      	at org.apache.calcite.prepare.CalciteCatalogReader.lambda$lookupOperatorOverloads$3(CalciteCatalogReader.java:271)
      	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
      	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
      	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
      	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
      	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
      	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
      	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
      	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
      	at java.util.stream.ReferencePipeline.forEachOrdered(ReferencePipeline.java:490)
      	at org.apache.calcite.prepare.CalciteCatalogReader.lookupOperatorOverloads(CalciteCatalogReader.java:272)
      	at org.apache.calcite.sql.util.ChainedSqlOperatorTable.lookupOperatorOverloads(ChainedSqlOperatorTable.java:73)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.performUnconditionalRewrites(SqlValidatorImpl.java:1195)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.performUnconditionalRewrites(SqlValidatorImpl.java:1180)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.performUnconditionalRewrites(SqlValidatorImpl.java:1180)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.performUnconditionalRewrites(SqlValidatorImpl.java:1180)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:937)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:651)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:558)
      	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:265)
      	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:638)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:502)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:472)
      	at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:231)
      	at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550)
      	at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
      	at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
      	at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227)
      	at org.apache.calcite.test.TableFunctionTest.testTableFunction2(TableFunctionTest.java:120)
      

      Tip: In scope of CALCITE-3238 was added new assertion to SqlTypeFactoryImpl.assertBasic(...) method, and now this check can't be
       ignored inside JavaTypeFactoryImpl.toSql(typeFactory, type) static method.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ihuzenko Igor Guzenko
                Reporter:
                ihuzenko Igor Guzenko
              • Votes:
                0 Vote for this issue
                Watchers:
                4 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 20m
                  3h 20m