[
https://issues.apache.org/jira/browse/CALCITE-6838?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17927632#comment-17927632
]
xiong duan edited comment on CALCITE-6838 at 2/17/25 8:12 AM:
--------------------------------------------------------------
According to
[dbms_comparison|https://www.sql-workbench.eu/dbms_comparison.html],
Support UNNEST:Postgres、IBM DB2、HSQLDB
Don't SUPPORT UNNEST: Oracle、SQL Server、MySQL、MariaDB、Firebird、H2、SQLite
So I test UNNEST in Postgres(In description) and HSQLDB.
In HSQLDB:
{code:java}
CREATE TABLE IF NOT EXISTS public.unnestTable
(
array_int integer array,
valueInt integer
);
select * from unnest((SELECT array_int from public.unnestTable)) as "t"
("ZERO");
select * from unnest((SELECT ARRAY_AGG(valueInt) from public.unnestTable)) as
"t" ("ZERO");
select * from unnest((SELECT ARRAY_AGG(valueInt) from public.unnestTable))
WITH ORDINALITY AS "t" ("ZERO","ZERO1");
SELECT * FROM public.unnestTable,unnest((SELECT array_int from
public.unnestTable));{code}
The HSQLDB always needs double parentheses.
And I test it in Spark(needs double parentheses):
{code:java}
SELECT * FROM explode ((SELECT ARRAY(1, 2, 3) FROM (VALUES (0)) `t` (`ZERO`)))
`t0` (`col_0`);{code}
was (Author: nobigo):
According to
[dbms_comparison|https://www.sql-workbench.eu/dbms_comparison.html],
Support UNNEST:Postgres、IBM DB2、HSQLDB
Don't SUPPORT UNNEST: Oracle、SQL Server、MySQL、MariaDB、Firebird、H2、SQLite
So I test UNNEST in Postgres and HSQLDB.
In HSQLDB:
{code:java}
CREATE TABLE IF NOT EXISTS public.unnestTable
(
array_int integer array,
valueInt integer
);
select * from unnest((SELECT array_int from public.unnestTable)) as "t"
("ZERO");
select * from unnest((SELECT ARRAY_AGG(valueInt) from public.unnestTable)) as
"t" ("ZERO");
select * from unnest((SELECT ARRAY_AGG(valueInt) from public.unnestTable))
WITH ORDINALITY AS "t" ("ZERO","ZERO1");
SELECT * FROM public.unnestTable,unnest((SELECT array_int from
public.unnestTable));{code}
The HSQLDB always needs double parentheses.
And I test it in Spark(needs double parentheses):
{code:java}
SELECT * FROM explode ((SELECT ARRAY(1, 2, 3) FROM (VALUES (0)) `t` (`ZERO`)))
`t0` (`col_0`);{code}
> RelToSqlConverter should generate double parentheses when the input to Unnest
> is a query statement
> --------------------------------------------------------------------------------------------------
>
> Key: CALCITE-6838
> URL: https://issues.apache.org/jira/browse/CALCITE-6838
> Project: Calcite
> Issue Type: Bug
> Reporter: xiong duan
> Assignee: xiong duan
> Priority: Major
> Labels: pull-request-available
>
> ReloSqlConverter should generate double parentheses when the input to Unnest
> is a query statement.
> For unit tests in RelToSqlConverterTest:
> {code:java}
> @Test void testUnnest() {
> final String sql = "select * from UNNEST(array [1, 2, 3])";
> final String expected = "SELECT *\n" +
> "FROM UNNEST (SELECT ARRAY[1, 2, 3]\n" +
> "FROM (VALUES (0)) AS \"t\" (\"ZERO\")) AS \"t0\" (\"col_0\")";
> sql(sql).ok(expected).withPostgresql().ok(expected);
> }{code}
> The generated SQL is valid in CALCITE but not in PG.
> In PostgreSQL:
> {code:java}
> CREATE TABLE IF NOT EXISTS public."unnestTable"
> (
> array_int integer[],
> "valueInt" integer
> );
> SELECT "valueInt","t10"."col_0" FROM public."unnestTable",unnest(( SELECT
> "array_int" FROM (VALUES (0)) AS "t" ("ZERO"))) AS "t10" ("col_0");
> select * from unnest((SELECT "array_int" from public."unnestTable")) as "t"
> ("ZERO");
> select * from unnest((SELECT ARRAY_AGG("valueInt") from
> public."unnestTable")) as "t" ("ZERO");
> select * from unnest((SELECT ARRAY_AGG("valueInt") from
> public."unnestTable")) WITH ORDINALITY AS "t" ("ZERO","ZERO1");{code}
> The PG always needs double parentheses.
> The Calcite supports double parentheses too.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)