[ https://issues.apache.org/jira/browse/CALCITE-2382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16524568#comment-16524568 ]
pengzhiwei edited comment on CALCITE-2382 at 6/27/18 4:55 AM: -------------------------------------------------------------- Hello Julian,I have test on top of your branch.A exception has thrown out as follow: {code:java} Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Duplicate relation name 'T' in FROM clause at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463) at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572) ... 50 more {code} I find the reason is that the namespace of s.t has added twice in the JoinScope. I fix it as the code show bellow In SqlValidatorImpl: !屏幕快照 2018-06-27 下午12.39.46.png! Now it work well. The table function test PR is here: [https://github.com/apache/calcite/pull/743/commits/8c5ea5a6bc0d1274ad59c2405af188c9a5664724] was (Author: pzw2018): Hello Julian,I have test on top of your branch.A exception has thrown out as follow: {code:java} Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Duplicate relation name 'T' in FROM clause at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463) at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572) ... 50 more {code} I find the reason is that the namespace of s.t has add twice in the JoinScope. I fix it as the code show bellow In SqlValidatorImpl: !屏幕快照 2018-06-27 下午12.39.46.png! Now it work well. The table function test PR is here: https://github.com/apache/calcite/pull/743/commits/8c5ea5a6bc0d1274ad59c2405af188c9a5664724 > Column not found when subquery join lateral table function > ---------------------------------------------------------- > > Key: CALCITE-2382 > URL: https://issues.apache.org/jira/browse/CALCITE-2382 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.16.0 > Reporter: pengzhiwei > Assignee: Julian Hyde > Priority: Critical > Attachments: 屏幕快照 2018-06-27 下午12.39.46.png > > > When using subquery join lateral table function as followed: > > {code:java} > select * from ( select 5 as f0 from s.t ) a,lateral > table(s.GenerateStrings(f0)) as t(n, c) where char_length(c) > 3 > {code} > 'SqlValidatorException: Column 'F0' not found in any table' was thrown out. > I find the reason is that SqlValidatorImpl add the namespace of Identifier > 's.t' to the children of tableScope,but not the subquey's namespace,just as > the code show bellow in SqlValidatorImpl#registerFrom: > {code:java} > case IDENTIFIER: > ........... > if (tableScope == null) { > tableScope = new TableScope(parentScope, node); > } > tableScope.addChild(newNs, alias, forceNullable);{code} > I think the namespace of JoinScope's left child should be the children of > tableScope which was referenced by the table function,just as the code show > bellow in SqlValidatorImpl#registerFrom: > {code:java} > case COLLECTION_TABLE: > .... > TableScope tableScope = null; > if(parentScope instanceof JoinScope) { > tableScope = new TableScope(new EmptyScope(this),operand); > JoinScope scope = (JoinScope) parentScope; > SqlValidatorNamespace leftNs = scope.getChildren().get(0); > tableScope.addChild(leftNs,scope.children.get(0).name,forceNullable); > } > ....{code} > After this modification,the case upon runs well. > Is there any problem for this modification? Any suggestions is > welcomed.Thanks a lot. > > > > -- This message was sent by Atlassian JIRA (v7.6.3#76005)