konstantinb commented on code in PR #6014:
URL: https://github.com/apache/hive/pull/6014#discussion_r2337480835


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ASTConverter.java:
##########
@@ -602,12 +603,23 @@ private QueryBlockInfo convertSource(RelNode r) throws 
CalciteSemanticException
 
       // retrieve the base table source.
       QueryBlockInfo tableFunctionSource = convertSource(tfs.getInput(0));
-      String sqAlias = tableFunctionSource.schema.get(0).table;
-      // the schema will contain the base table source fields
-      s = new Schema(tfs, sqAlias);
 
-      ast = createASTLateralView(tfs, s, tableFunctionSource, sqAlias);
+      // Create schema that preserves base table columns with original alias,
+      // but gives new UDTF columns the unique lateral view alias
+      int baseFieldCount = tableFunctionSource.schema.size();
+      List<RelDataTypeField> allOutputFields = tfs.getRowType().getFieldList();
 
+      final String sqAlias = tableFunctionSource.schema.get(0).table;
+      Stream<ColumnInfo> baseColumnsStream = allOutputFields.subList(0, 
baseFieldCount).stream()
+          .map(field -> new ColumnInfo(sqAlias, field.getName()));
+
+      final String lateralViewAlias = nextAlias();
+      Stream<ColumnInfo> udtfColumnsStream =
+          allOutputFields.subList(baseFieldCount, 
allOutputFields.size()).stream()
+              .map(field -> new ColumnInfo(lateralViewAlias, field.getName()));
+
+      s = new Schema(Stream.concat(baseColumnsStream, 
udtfColumnsStream).toList());
+      ast = createASTLateralView(tfs, s, tableFunctionSource, 
lateralViewAlias);

Review Comment:
   > Concretely, I was thinking something like the following:
   > 
   > assuming that the code inside `createASTLateralView` that needs a schema 
can use directly `tableFunctionSource.schema`.
   > 
   > In this case, the "input" schema is that inside `tableFunctionSource` and 
the "output" schema is the one constructed in `s`.
   
   @zabetak Thank you very much for this suggestion, it definitely makes 
perfect sense to better distinguish input & output schemas. I believe that the 
commit 
https://github.com/apache/hive/pull/6014/commits/f413e345205aab278f7d61a920444237bcb095c6
 is in a very close match with your proposal. I would appreciate it if you can 
give it another look when you get a chance.



-- 
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: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to