Wei-hao-Li commented on code in PR #14928:
URL: https://github.com/apache/iotdb/pull/14928#discussion_r1992969042


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java:
##########
@@ -1077,6 +1134,789 @@ private List<Expression> 
analyzeSelect(QuerySpecification node, Scope scope) {
       return outputExpressionBuilder.build();
     }
 
+    /**
+     * Check if there is Columns function in expression, and verify they are 
same if there are multi
+     * Column functions.
+     *
+     * @param expression input expression
+     * @return if there is Columns function in expression
+     * @throws SemanticException if there are multi Columns functions but 
different
+     */
+    private boolean containsColumns(Expression expression) {
+      return containsColumnsHelper(expression) != null;
+    }
+
+    private Node containsColumnsHelper(Node node) {
+      if (node instanceof Columns) {
+        return node;
+      }
+
+      Node target = null;
+      for (Node child : node.getChildren()) {
+        Node childResult = containsColumnsHelper(child);
+
+        if (childResult == null) {
+          continue;
+        }
+
+        // initialize target
+        if (target == null) {
+          target = childResult;
+          continue;
+        }
+
+        if (!childResult.equals(target)) {
+          throw new SemanticException(
+              "Multiple different COLUMNS in the same expression are not 
supported");
+        }
+      }
+      return target;
+    }
+
+    private class ExpandColumnsVisitor extends AstVisitor<List<Expression>, 
Scope> {
+      private final Identifier alias;
+      // Record Columns expanded result in process, not always equals with 
final result
+      private List<Expression> expandedExpressions;
+      // Records the actual output column name of each Expression, used to 
compute output Scope.
+      private List<String> accordingColumnNames;
+
+      private ExpandColumnsVisitor(Identifier alias) {
+        this.alias = alias;
+      }
+
+      public List<String> getAccordingColumnNames() {
+        return accordingColumnNames;
+      }
+
+      protected List<Expression> visitNode(Node node, Scope scope) {
+        throw new UnsupportedOperationException(
+            "This Visitor only supported process of Expression");
+      }
+
+      protected List<Expression> visitExpression(Expression node, Scope scope) 
{
+        if (node.getChildren().isEmpty()) {
+          return Collections.singletonList(node);
+        }
+        throw new UnsupportedOperationException("UnSupported Expression: " + 
node);
+      }
+
+      @Override
+      public List<Expression> visitColumns(Columns node, Scope context) {
+        // avoid redundant process
+        if (expandedExpressions != null) {
+          return expandedExpressions;
+        }
+
+        context.getRelationType().getVisibleFields();

Review Comment:
   > Remove this line?
   
   Yes, it's a typo



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