You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Vladimir Sitnikov (JIRA)" <ji...@apache.org> on 2018/07/30 20:11:00 UTC
[jira] [Created] (CALCITE-2431) AssertionError: SqlUtil.getAncestry
when providing completion hints for sub-schema
Vladimir Sitnikov created CALCITE-2431:
------------------------------------------
Summary: AssertionError: SqlUtil.getAncestry when providing completion hints for sub-schema
Key: CALCITE-2431
URL: https://issues.apache.org/jira/browse/CALCITE-2431
Project: Calcite
Issue Type: Bug
Components: core
Affects Versions: 1.17.0
Reporter: Vladimir Sitnikov
Assignee: Julian Hyde
Test case (JdbcTest):
{code:java} @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"));
}{code}
Relevant code (SqlUtil.getAncestry):
{code:java} 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);
{code}
Relevant code from {{SqlAdvisor.isSelectListItem}}:
{code:java}
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();
}
{code}
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:
{noformat}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){noformat}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)