[jira] [Commented] (CALCITE-2431) AssertionError: SqlUtil.getAncestry when providing completion hints for sub-schema

2018-07-30 Thread Vladimir Sitnikov (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2431?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16562531#comment-16562531
 ] 

Vladimir Sitnikov commented on CALCITE-2431:


PS. The purpose of the check is to remove * (star) from completion hints in 
case suggest pointer is outside of a select clause:

{code:java}final SqlMoniker star =
new SqlMonikerImpl(ImmutableList.of("*"), SqlMonikerType.KEYWORD);
if (hintList.contains(star) && !isSelectListItem(sqlNode, pos)) { // <-- 
This checks if _SUGGEST_ is placed within SELECT or not
  hintList.remove(star);
}
{code}


> 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
>Priority: Major
> Fix For: 1.18.0
>
>
> 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 getAncestry(SqlNode root,
>   Predicate predicate, Predicate 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 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 

[jira] [Commented] (CALCITE-2431) AssertionError: SqlUtil.getAncestry when providing completion hints for sub-schema

2018-07-30 Thread Vladimir Sitnikov (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2431?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16562522#comment-16562522
 ] 

Vladimir Sitnikov commented on CALCITE-2431:


[~julianhyde], the match there is against {{_SUGGEST_}} token, and AFAIK it is 
supposed to be unique and never to be used by the application token.

That is why I think using contains there is just fine.

> 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
>Priority: Major
> Fix For: 1.18.0
>
>
> 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 getAncestry(SqlNode root,
>   Predicate predicate, Predicate 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 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)


[jira] [Commented] (CALCITE-2431) AssertionError: SqlUtil.getAncestry when providing completion hints for sub-schema

2018-07-30 Thread Julian Hyde (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2431?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16562465#comment-16562465
 ] 

Julian Hyde commented on CALCITE-2431:
--

Does your fix work when a table alias matches a column name? E.g. {code}select 
empno.deptno from emp as e, dept as empno{code} The reason we only match the 
last item in the identifier is to avoid that problem. I know you need to match 
non-last items because you may have record-valued fields. But there are complex 
cases like {{myDatabase.mySchema.customers.orders.lineItems}} where the field 
("orders") is somewhere in the middle of the identifier's names. 

> 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
>Priority: Major
>
> 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 getAncestry(SqlNode root,
>   Predicate predicate, Predicate 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 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