vrajat commented on code in PR #13221:
URL: https://github.com/apache/pinot/pull/13221#discussion_r1618686269


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/serde/PlanNodeSerializationVisitor.java:
##########
@@ -0,0 +1,386 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.query.planner.serde;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.calcite.rel.RelDistribution;
+import org.apache.calcite.rel.RelFieldCollation;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.logical.PinotRelExchangeType;
+import org.apache.pinot.common.proto.Expressions;
+import org.apache.pinot.common.proto.Plan;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.query.planner.logical.RexExpression;
+import org.apache.pinot.query.planner.plannode.AbstractPlanNode;
+import org.apache.pinot.query.planner.plannode.AggregateNode;
+import org.apache.pinot.query.planner.plannode.ExchangeNode;
+import org.apache.pinot.query.planner.plannode.FilterNode;
+import org.apache.pinot.query.planner.plannode.JoinNode;
+import org.apache.pinot.query.planner.plannode.MailboxReceiveNode;
+import org.apache.pinot.query.planner.plannode.MailboxSendNode;
+import org.apache.pinot.query.planner.plannode.PlanNodeVisitor;
+import org.apache.pinot.query.planner.plannode.ProjectNode;
+import org.apache.pinot.query.planner.plannode.SetOpNode;
+import org.apache.pinot.query.planner.plannode.SortNode;
+import org.apache.pinot.query.planner.plannode.TableScanNode;
+import org.apache.pinot.query.planner.plannode.ValueNode;
+import org.apache.pinot.query.planner.plannode.WindowNode;
+
+
+public class PlanNodeSerializationVisitor implements PlanNodeVisitor<Void, 
Plan.StageNode.Builder> {
+  public static final PlanNodeSerializationVisitor INSTANCE = new 
PlanNodeSerializationVisitor();
+
+  private PlanNodeSerializationVisitor() {
+  }
+
+  public Plan.StageNode process(AbstractPlanNode planNode) {
+    Plan.StageNode.Builder builder = 
Plan.StageNode.newBuilder().setStageId(planNode.getPlanFragmentId());
+    DataSchema dataSchema = planNode.getDataSchema();
+    for (int i = 0; i < dataSchema.getColumnNames().length; i++) {
+      builder.addColumnNames(dataSchema.getColumnName(i));
+      
builder.addColumnDataTypes(RexExpressionToProtoExpression.convertColumnDataType(dataSchema.getColumnDataType(i)));
+    }
+
+    planNode.visit(this, builder);
+    planNode.getInputs().forEach(input -> 
builder.addInputs(process((AbstractPlanNode) input)));
+
+    return builder.build();
+  }
+
+  @Override
+  public Void visitAggregate(AggregateNode node, Plan.StageNode.Builder 
builder) {
+    Plan.AggregateNode.Builder aggregateNodeBuilder =
+        
Plan.AggregateNode.newBuilder().setNodeHint(getNodeHintBuilder(node.getNodeHint()))
+            
.setAggCalls(convertExpressions(node.getAggCalls())).addAllFilterArgIndices(node.getFilterArgIndices())
+            
.setGroupSet(convertExpressions(node.getGroupSet())).setAggType(convertAggType(node.getAggType()));
+
+    builder.setAggregateNode(aggregateNodeBuilder);
+    return null;
+  }
+
+  @Override
+  public Void visitFilter(FilterNode node, Plan.StageNode.Builder builder) {
+    Expressions.RexExpression condition = 
RexExpressionToProtoExpression.process(node.getCondition());
+    Plan.FilterNode.Builder filterNodeBuilder = 
Plan.FilterNode.newBuilder().setCondition(condition);
+    builder.setFilterNode(filterNodeBuilder);
+
+    return null;
+  }
+
+  @Override
+  public Void visitJoin(JoinNode node, Plan.StageNode.Builder builder) {
+    Plan.JoinKeys.Builder joinKeyBuilder = 
Plan.JoinKeys.newBuilder().addAllLeftKeys(node.getJoinKeys().getLeftKeys())
+        .addAllRightKeys(node.getJoinKeys().getRightKeys());
+
+    Plan.JoinNode.Builder joinNodeBuilder =
+        
Plan.JoinNode.newBuilder().setJoinRelType(convertJoinRelType(node.getJoinRelType())).setJoinKeys(joinKeyBuilder)
+            .setJoinClause(convertExpressions(node.getJoinClauses()))
+            
.setJoinHints(getNodeHintBuilder(node.getJoinHints())).addAllLeftColumnNames(node.getLeftColumnNames())
+            .addAllRightColumnNames(node.getRightColumnNames());
+
+    builder.setJoinNode(joinNodeBuilder);

Review Comment:
    I did not write the code this way. This is formatted by intellij using the 
project's coding rules. 
    
    I ran an experiment where I modified the code so that there is one fn. per 
line as you have pasted above. Then I formatted the file (Code -> Reformat File 
...). The editor changed the format back to fitting in as many function calls 
as possible into a line. It is too much of an hassle to disallow a developer to 
reformat this file. The best option is to add this rule in the future and then 
make the change. 



-- 
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: commits-unsubscr...@pinot.apache.org

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


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

Reply via email to