You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Mark Grey (Jira)" <ji...@apache.org> on 2022/01/03 21:06:00 UTC

[jira] [Comment Edited] (CALCITE-4972) Qualify subfields of array columns containing structs in return of getFieldOrigins

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

Mark Grey edited comment on CALCITE-4972 at 1/3/22, 9:05 PM:
-------------------------------------------------------------

Assuming that a fully qualified return is desirable in this case, I was able to get a naive fix working by checking if the namespace could unwrap to {{UnnestNamespace}} in {{SqlValidatorImpl}} and if so, using the identifiers within to qualify the sub fields in the return.

It seems like a poor approach however, and that rather than changing the output of this method specifically after the fact it would be better to construct the {{Step}} s and {{Path}} to account for the nesting during validation.


was (Author: mgthesecond):
Assuming that a fully qualified return is desirable in this case, I was able to get a naive fix working by checking if the namespace could unwrap to {{UnnestNamespace}} in {{SqlValidatorImpl}} and if so, using the identifiers within to qualify the sub fields in the return.

It seems like a poor approach however, and that rather than changing the output of this method specifically after the fact it would be better to construct the {{Step}}s and {{Path}} to account for the nesting during validation.

> Qualify subfields of array columns containing structs in return of getFieldOrigins
> ----------------------------------------------------------------------------------
>
>                 Key: CALCITE-4972
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4972
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.28.0
>            Reporter: Mark Grey
>            Priority: Minor
>
> Attempting to follow on the [suggestions from Julian in this thread|https://lists.apache.org/thread/pdpqtzy5mtzlpdbhwghbty6cj0jgc86l], found a potential improvement.
> Given a table schema containing a repeated array of structs and a query projecting fields of that struct via UNNEST, the present implementation of {{getFieldOrigins}} in {{SqlValidatorImpl}} will return a list representation suggesting that the subfield is actually a member of the top level table row type.
> For example, when using the [DEPT_NESTED table from the MockCatalogReaderSimple|https://github.com/apache/calcite/blob/master/testkit/src/main/java/org/apache/calcite/test/catalog/MockCatalogReaderSimple.java#L152-L159] within tests with the following query:
> {code:sql}
> select e.empno from dept_nested, unnest(employees) as e
> {code}
> The return value will be:
> {code}
> {CATALOG.SALES.DEPT_NESTED.EMPNO}
> {code}
> Rather than:
> {code}
> {CATALOG.SALES.DEPT_NESTED.EMPLOYEES.EMPNO}
> {code}
> No such column  {{EMPNO}} exists in the root schema of the DEPT_NESTED table.  [The javadoc for the method |https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/validate/SqlValidator.java#L717-L728]however suggests that the return from this method should always be four entries long, although it would seem this doesn't account for nesting.  Is this intended behavior, or should {{column}} entry of this list be of variable length? 



--
This message was sent by Atlassian Jira
(v8.20.1#820001)