Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
For the case of using named parameters in table functions, when several table functions with the same name, but with different argument types, query with such function fails with an assertion error.
For example, the following table functions:
View(String R, String S, Integer T) and View(String R, String S, Integer T, String S2)
will fail with assertion error for the following query:
select * from table("adhoc"."View"(t=>5, s=>'6'))
with error:
VARCHAR java.lang.AssertionError: VARCHAR at org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:139) at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:691) at org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:660) at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:519) at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:439) at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:240) at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:218) at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5854) at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5841) at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:139) at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1800) at org.apache.calcite.sql.validate.ProcedureNamespace.validateImpl(ProcedureNamespace.java:53) at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84) at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:1110) at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:1084) at org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:3256) at org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:3238) at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3510) at org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60) at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84) at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:1110) at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:1084) at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:232) at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:1059) at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:766) at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:565) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:241) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:207) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:634) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:498) at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:468) 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.CalciteAssert.assertQuery(CalciteAssert.java:533) at org.apache.calcite.test.CalciteAssert$AssertQuery.lambda$returns$1(CalciteAssert.java:1519) at org.apache.calcite.test.CalciteAssert$AssertQuery.withConnection(CalciteAssert.java:1451) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1517) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1500) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1463) at org.apache.calcite.test.JdbcTest.testTableMacroWithNamedParameters(JdbcTest.java:546)
The issue here is that SqlUtil.filterRoutinesByTypePrecedence() assumes that all functions will have the same type at the same position, but table functions allow omitting arguments or flipping them.
Attachments
Issue Links
- is depended upon by
-
DRILL-7526 Assertion Error when only type is used with schema in table function
- Resolved
- links to