[
https://issues.apache.org/jira/browse/CALCITE-2276?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16454357#comment-16454357
]
Julian Hyde commented on CALCITE-2276:
--------------------------------------
Thanks, that helps clarify.
It seems to me that the standard still prevents {{ROW (...)}} or {{(...)}} in
places where its type becomes visible, because it never wants anonymous record
types to appear. This is very similar to how NULL is used - you can write {code}
INSERT INTO t (x, y) VALUES (1, NULL){code}but you cannot write{code}SELECT 1,
NULL FROM t{code}because the latter would produce a column whose type cannot be
deduced. You have to write {code}SELECT 1, CAST(NULL AS INTEGER) FROM
t{code}instead.
I think we should remove the restriction from the parser. The parser should be
able to parse {code}SELECT ROW(x, y) FROM t{code} or equivalently {code}SELECT
(x, y) FROM t{code}. But if you have strict compliance enabled those queries
would fail validation.
> 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)