InvisibleProgrammer commented on code in PR #6043:
URL: https://github.com/apache/hive/pull/6043#discussion_r2353553766


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/lineage/OpProcFactory.java:
##########
@@ -676,6 +689,249 @@ public Object process(Node nd, Stack<Node> stack, 
NodeProcessorCtx procCtx,
     }
   }
 
+  /**
+   * PTF processor
+   */
+  public static class PTFLineage implements SemanticNodeProcessor {
+
+    @Override
+    public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx 
procCtx, Object... nodeOutputs) throws SemanticException {
+      // LineageCTx
+      LineageCtx lCtx = (LineageCtx) procCtx;
+
+      // The operators
+      @SuppressWarnings("unchecked")
+      PTFOperator op = (PTFOperator)nd;
+      Operator<? extends OperatorDesc> inpOp = getParent(stack);
+      lCtx.getIndex().copyPredicates(inpOp, op);
+
+      Dependency dep = new Dependency();
+      DependencyType new_type = DependencyType.EXPRESSION;
+      dep.setType(new_type);
+
+      Set<String> columns = new HashSet<>();
+      PartitionedTableFunctionDef funcDef = op.getConf().getFuncDef();
+      StringBuilder sb = new StringBuilder();
+      WindowFrameDef windowFrameDef = null;
+
+      if (!(funcDef.getTFunction() instanceof Noop)) {
+
+        if (funcDef instanceof WindowTableFunctionDef) {
+          // function name
+          WindowFunctionDef windowFunctionDef = ((WindowTableFunctionDef) 
funcDef).getWindowFunctions().getFirst();
+          sb.append(windowFunctionDef.getName()).append("(");
+
+          addArgs(sb, columns, lCtx, inpOp, op.getSchema(), 
windowFunctionDef.getArgs());
+
+        } else /* PartitionedTableFunctionDef */ {
+          // function name
+          sb.append(funcDef.getName()).append("(");
+          addArgs(sb, columns, lCtx, inpOp, 
funcDef.getRawInputShape().getRr().getRowSchema(), funcDef.getArgs());
+        }
+
+        if (funcDef instanceof WindowTableFunctionDef) {
+          WindowFunctionDef windowFunctionDef = ((WindowTableFunctionDef) 
funcDef).getWindowFunctions().getFirst();
+          windowFrameDef = windowFunctionDef.getWindowFrame();
+
+          if (sb.charAt(sb.length() - 2) == ',') {
+            sb.delete(sb.length() - 2, sb.length());
+          }
+          sb.append(")");
+          sb.append(" over (");
+        } else {
+          // matchpath has argument pattern like matchpath(<input expression>, 
<argument methods: arg1(), arg2()...>)
+          if (funcDef.getInput() != null) {
+            sb.append("on ").append(funcDef.getInput().getAlias()).append(" ");
+
+            int counter = 1;
+            for (PTFExpressionDef arg : funcDef.getArgs()) {
+              ExprNodeDesc exprNode = arg.getExprNode();
+
+              addIfNotNull(columns, exprNode.getCols());
+
+              sb.append("arg").append(counter++).append("(");
+              
sb.append(ExprProcFactory.getExprString(funcDef.getRawInputShape().getRr().getRowSchema(),
 arg.getExprNode(), lCtx, inpOp, null));
+              sb.append("), ");
+            }
+
+            sb.delete(sb.length() - 2, sb.length());
+          }
+
+        }

Review Comment:
   Sure, thx. 



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