sbroeder commented on code in PR #5271:
URL: https://github.com/apache/calcite/pull/5271#discussion_r4138853544


##########
core/src/main/java/org/apache/calcite/sql/validate/AliasNamespace.java:
##########
@@ -100,29 +100,30 @@ protected AliasNamespace(
     final RelDataType aliasedType;
     if (operands.size() == 2) {
       final SqlNode node = operands.get(0);
-      // Alias is 'AS t' (no column list).
-      // If the sub-query is UNNEST or VALUES,
-      // and the sub-query has one column,
-      // then the namespace's sole column is named after the alias.
+      // 'AS t': the sole column is named after the alias, unless it's a
+      // struct-array UNNEST field (isUnnestOfStructArray), which keeps its 
name.
+      final boolean isStructUnnest = node.getKind() == SqlKind.UNNEST
+          && isUnnestOfStructArray((SqlCall) node);
       if (rowType.getFieldCount() == 1) {
         final RelDataType singleColumnAlias = 
validator.getTypeFactory().builder()
             .kind(rowType.getStructKind())
             .add(((SqlIdentifier) operands.get(1)).getSimple(),
                 rowType.getFieldList().get(0).getType())
             .build();
-        aliasedType = node.getKind() == SqlKind.COLLECTION_TABLE
+        aliasedType = node.getKind() == SqlKind.COLLECTION_TABLE || 
isStructUnnest
             ? new SingleColumnAliasRelDataType(rowType, singleColumnAlias) : 
singleColumnAlias;
-        // If the sub-query is UNNEST with ordinality
-        // and the sub-query has two columns: data column, ordinality column
-        // then the namespace's sole column is named after the alias.
+        // WITH ORDINALITY: data column named after the alias, unless it's
+        // a struct-array field, which keeps its name.

Review Comment:
   Moved the comment into the WITH ORDINALITY branch. And you're right that it 
was wrong to say only the field name survives. The alias now also names the 
data column.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to