Description
Test case (JdbcTest):
@Test public void testSqlAdvisorSubSchema() throws SQLException, ClassNotFoundException { adviseSql("select * from \"hr\".^.test_test_test", 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 code (SqlUtil.getAncestry):
public static ImmutableList<SqlNode> getAncestry(SqlNode root, Predicate<SqlNode> predicate, Predicate<SqlNode> postPredicate) { try { new Genealogist(predicate, postPredicate).visitChild(root); throw new AssertionError("not found: " + predicate + " in " + root);
Relevant code from SqlAdvisor.isSelectListItem:
private static boolean isSelectListItem(SqlNode root, final SqlParserPos pos) { List<SqlNode> nodes = SqlUtil.getAncestry(root, input -> input instanceof SqlIdentifier && Util.last(((SqlIdentifier) input).names) .equals(UPPER_HINT_TOKEN), input -> Objects.requireNonNull(input).getParserPosition() .startsAt(pos)); assert nodes.get(0) == root; nodes = Lists.reverse(nodes); return nodes.size() > 2 && nodes.get(2) instanceof SqlSelect && nodes.get(1) == ((SqlSelect) nodes.get(2)).getSelectList(); }
It looks like Util.last(((SqlIdentifier) input).names).equals(UPPER_HINT_TOKEN) should be replaced with (SqlIdentifier) input).names.contains(UPPER_HINT_TOKEN).
Note: the code is advisor-specific, so the replacement should be safe
Original exception:
java.lang.AssertionError: not found: org.apache.calcite.sql.advise.SqlAdvisor$$Lambda$197/402207819@1b70203f in SELECT * FROM `hr`.`_SUGGEST_`.`TEST_TEST_TEST` at org.apache.calcite.sql.SqlUtil.getAncestry(SqlUtil.java:872) at org.apache.calcite.sql.advise.SqlAdvisor.isSelectListItem(SqlAdvisor.java:242) at org.apache.calcite.sql.advise.SqlAdvisor.getCompletionHints(SqlAdvisor.java:220) 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:441) at org.apache.calcite.test.JdbcTest.testSqlAdvisorSubSchema(JdbcTest.java:374)