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

Maryann Xue commented on PHOENIX-953:
-------------------------------------

Thanks, [~julianhyde]! That's a good guide to me.

I suggest implementing the below examples as our initial scope:
1. UNNEST(subquery/derived_table) \[WITH ORDINALITY\] AS ...
2. UNNEST(literal_array) \[WITH ORDINALITY\] AS ...

For each of the above, we can turn them into DerivedTableNode with an "UNNEST" 
and a "ORDINALITY" flag:
1. DerivedTableNode\[select_node=subquery, unnest=true, with_ord=true/false, 
as_schema=...\]
2. DerivedTableNode\[select_node="select literal_array", unnest=true, 
with_ord=true/false, as_schema=...\]

Aside from the grammar changes required for UNNEST itself, we might have to add 
support for "AS" for defining a temporary table structure.

Changes in QueryCompiler should be simple: we handle UNNEST in our derived 
table compilation, and wrap the "innerPlan" with UnnestArrayQueryPlan if the 
flag is true. And we might need to check that the table structure (which is a 
PTable object in Phoenix but is called RowType in calcite) is consistent with 
the UNNEST content.

For the other example [~julianhyde] had mentioned "SELECT student, score FROM 
tests CROSS JOIN UNNEST(scores) AS t (score)", we might want to do it a little 
later, since more changes need to be made to support UNNEST that depends on a 
preceding table.

> Support UNNEST for ARRAY
> ------------------------
>
>                 Key: PHOENIX-953
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-953
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: James Taylor
>            Assignee: Dumindu Buddhika
>         Attachments: PHOENIX-953-v1.patch
>
>
> The UNNEST built-in function converts an array into a set of rows. This is 
> more than a built-in function, so should be considered an advanced project.
> For an example, see the following Postgres documentation: 
> http://www.postgresql.org/docs/8.4/static/functions-array.html
> http://www.anicehumble.com/2011/07/postgresql-unnest-function-do-many.html
> http://tech.valgog.com/2010/05/merging-and-manipulating-arrays-in.html
> So the UNNEST is a way of converting an array to a flattened "table" which 
> can then be filtered on, ordered, grouped, etc.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to