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


##########
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:
   @konstantinb I took the liberty to some further refactoring and cleanup in 
https://github.com/apache/hive/pull/6014/commits/2eaabefadb29dd24aa2a405262af6a91d55732b4
 and  
https://github.com/apache/hive/pull/6014/commits/829ecf9693f66b30b2e2ac64de04ca3bdb3bd304.
 If everything looks good to you then I think we are ready to merge it.
   
   



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to