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

Yuzhao Chen edited comment on CALCITE-2276 at 4/26/18 8:16 AM:
---------------------------------------------------------------

In sql-2003, the syntax elements for my case are:  
{code:java}
<WHERE clause>
----+ <boolean value expression>
--------+ <predicate>
------------+ <in predicate>
----------------+ <row value predicand>
--------------------+ <row value constructor predicand>
------------------------+ <explicit row value constructor>
ROW <left paren> <row value constructor element list> <right paren>
{code}
So `where ROW(xxx) in` is a standard way.

Also the 
{code:java}
<row value predicand>{code}
 appears in many syntax elements[ most are predicate ], eg: <distinct 
predicate>, <null predicate>, <between predicate>, <comparison predicate>, not 
just in <contextually typed table value constructor>.

 

For sql-1999, the <row value expression> can also appears in many syntax 
elements, not just <contextually typed table value constructor> which is the 
same case as sql-2003.

 


was (Author: danny0405):
In sql-2003, the syntax elements for my case are:  
{code:java}
<WHERE clause>
----+ <boolean value expression>
--------+ <predicate>
------------+ <in predicate>
----------------+ <row value predicand>
--------------------+ <row value constructor predicand>
------------------------+ <explicit row value constructor>
ROW <left paren> <row value constructor element list> <right paren>
{code}
So `where ROW(xxx) in` is a standard way.

Also the 
{code:java}
<row value predicand>{code}
 appears in many syntax elements[ most are predicate ], eg: <distinct 
predicate>, <null predicate>, <between predicate>, <comparison predicate>, not 
just in <contextually typed table value constructor>.

 

For sql-1999, the <row value expression> can also appears in many syntax 
elements, not just <contextually typed table value constructor> which is the 
same case as sql-2003

 

> Calcite unable to parse ROW value constructor in certain scenario
> -----------------------------------------------------------------
>
>                 Key: CALCITE-2276
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2276
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Shuyi Chen
>            Assignee: Julian Hyde
>            Priority: Major
>
> h2. Original dev mailing list question:
> Now for our production, we can parse a query successfully like this :
> {code}
> -- correlated IN subquery
> -- TC 01.01
> SELECT t1a,
>        t1b,
>        t1h
> FROM   t1
> WHERE  ( t1a, t1h ) NOT IN (SELECT t2a,
>                                    t2h
>                             FROM   t2
>                             WHERE  t2a = t1a
>                             ORDER  BY t2a)
> AND t1a = 'val1a'
> {code}
> but if we add in `Row`:
> {code}
> -- correlated IN subquery
> -- TC 01.01
> SELECT t1a,
>        t1b,
>        t1h
> FROM   t1
> WHERE  ROW( t1a, t1h ) NOT IN (SELECT t2a,
>                                    t2h
>                             FROM   t2
>                             WHERE  t2a = t1a
>                             ORDER  BY t2a)
> AND t1a = 'val1a'
> {code}
>  it will throw exception:
> {noformat}
> Caused by: org.apache.calcite.sql.parser.SqlParseException: ROW expression
> encountered in illegal context
>   at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:351)
>   at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:133)
>   at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:138)
>   at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:163)
>   at 
> org.apache.flink.table.calcite.FlinkPlannerImpl.parse(FlinkPlannerImpl.scala:81)
> ... 8 more
> {noformat}
> For the success query, if we exec parsed AST tree rootNode.toString(), it
> will return a query like:
> {code}
> SELECT `t1a`,
>        `t1b`,
>        `t1h`
> FROM `t1`
> WHERE ROW(`t1a`, `t1h`) NOT IN (SELECT `t2a`, `t2h`
>                                 FROM `t2`
>                                 WHERE `t2a` = `t1a`
>                                 ORDER BY `t2a`)
> AND `t1a` = 'val1a'
> {code}
> This is inconsistent  by Calcite itself semantic.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to