You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/04/12 21:46:06 UTC

[GitHub] [pinot] siddharthteotia commented on a diff in pull request #8479: Use proto for query plan serialization

siddharthteotia commented on code in PR #8479:
URL: https://github.com/apache/pinot/pull/8479#discussion_r848898024


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/nodes/SerDeUtils.java:
##########
@@ -0,0 +1,90 @@
+/**
+ * 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.nodes;
+
+import com.google.protobuf.ByteString;
+import org.apache.pinot.common.proto.Plan;
+
+
+public final class SerDeUtils {
+  private SerDeUtils() {
+    // do not instantiate.
+  }
+
+  public static AbstractStageNode deserializeStageNode(Plan.StageNode protoNode) {
+    AbstractStageNode stageNode = newNodeInstance(protoNode.getNodeName(), protoNode.getStageId());
+    stageNode.setFields(protoNode.getFields());
+    for (Plan.StageNode protoChild : protoNode.getInputsList()) {
+      stageNode.addInput(deserializeStageNode(protoChild));
+    }
+    return stageNode;
+  }
+
+  public static Plan.StageNode serializeStageNode(AbstractStageNode stageNode) {
+    Plan.StageNode.Builder builder = Plan.StageNode.newBuilder()
+        .setStageId(stageNode.getStageId())
+        .setNodeName(stageNode.getClass().getSimpleName())
+        .setFields(stageNode.getFields());
+    for (StageNode childNode : stageNode.getInputs()) {
+      builder.addInputs(serializeStageNode((AbstractStageNode) childNode));
+    }
+    return builder.build();
+  }
+
+  public static Plan.LiteralField boolField(boolean val) {
+    return Plan.LiteralField.newBuilder().setBoolField(val).build();
+  }
+
+  public static Plan.LiteralField intField(int val) {
+    return Plan.LiteralField.newBuilder().setIntField(val).build();
+  }
+
+  public static Plan.LiteralField longField(long val) {
+    return Plan.LiteralField.newBuilder().setLongField(val).build();
+  }
+
+  public static Plan.LiteralField doubleField(double val) {
+    return Plan.LiteralField.newBuilder().setDoubleField(val).build();
+  }
+
+  public static Plan.LiteralField stringField(String val) {
+    return Plan.LiteralField.newBuilder().setStringField(val).build();
+  }
+
+  public static Plan.LiteralField bytesField(byte[] val) {
+    return Plan.LiteralField.newBuilder().setBytesField(ByteString.copyFrom(val)).build();
+  }
+
+  private static AbstractStageNode newNodeInstance(String nodeName, int stageId) {
+    switch (nodeName) {
+      case "TableScanNode":

Review Comment:
   (nit) Create a constants / utils file and put these names there as static final or may be in this class itself ?



-- 
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-unsubscribe@pinot.apache.org

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


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