chunweilei commented on a change in pull request #1138: [CALCITE-1581] UDTF 
like in hive
URL: https://github.com/apache/calcite/pull/1138#discussion_r270263293
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
 ##########
 @@ -1320,6 +1331,175 @@ protected SqlNode performUnconditionalRewrites(
     return node;
   }
 
+  private SqlNode performHiveUdtfRewrite(SqlNode node) {
+    Map<SqlSelect, UdtfInfo> selectUdtfInfo = new HashMap<>();
+     SqlNode rewirte = performHiveUdtfRewriteInternal(node, selectUdtfInfo);
+   //  System.out.println("before:\n" + node.toString() +" \nafter:\n" + 
rewirte.toString());
+    return node;
+  }
+
+  private SqlNode performHiveUdtfRewriteInternal(SqlNode current,
+                                                 Map<SqlSelect, UdtfInfo> 
selectUdtfInfos) {
+    System.out.println("start rewrite:" + current);
+
+    // rewrite hive "udtf() as (f0,f1)" to lateral table
+    if (current instanceof SqlSelect) {
+      SqlSelect select = (SqlSelect) current;
+      SqlNodeList newSelectItem =
+          performRewriteForSelectItem(select,
+              select.getSelectList(), selectUdtfInfos);
+
+      UdtfInfo udtfInfo = selectUdtfInfos.get(select);
+      // if the select items contain a table function,
+      // join the from node with the table function.
+      if (udtfInfo != null && select.getFrom() != null) {
+        SqlBasicCall joinRight = createLateralTable(udtfInfo);
+        SqlNode newFrom = new SqlJoin(
 
 Review comment:
   Maybe use `SqlCall` is better.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to