kasakrisz commented on code in PR #5131:
URL: https://github.com/apache/hive/pull/5131#discussion_r1576115514


##########
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java:
##########
@@ -1745,9 +1748,72 @@ public RelNode apply(RelOptCluster cluster, RelOptSchema 
relOptSchema, SchemaPlu
       if (LOG.isDebugEnabled()) {
         LOG.debug("Plan after post-join transformations:\n" + 
RelOptUtil.toString(calcitePlan));
       }
+      perfLogger.perfLogEnd(this.getClass().getName(), PerfLogger.OPTIMIZER);
+
+      if 
(conf.getBoolVar(ConfVars.TEST_CBO_PLAN_SERIALIZATION_DESERIALIZATION_ENABLED)) 
{
+        calcitePlan = testSerializationAndDeserialization(perfLogger, 
calcitePlan);
+      }
+
+      return calcitePlan;
+    }
+
+    @Nullable
+    private RelNode testSerializationAndDeserialization(PerfLogger perfLogger, 
RelNode calcitePlan) {
+      if (!isSerializable(calcitePlan)) {
+        return calcitePlan;
+      }
+      perfLogger.perfLogBegin(this.getClass().getName(), "plan serializer");
+      String calcitePlanJson = serializePlan(calcitePlan);
+      perfLogger.perfLogEnd(this.getClass().getName(), "plan serializer");
+
+      if (stringSizeGreaterThan(calcitePlanJson, 
PLAN_SERIALIZATION_DESERIALIZATION_STR_SIZE_LIMIT)) {
+        return calcitePlan;
+      }
+
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("Size of calcite plan: {}", 
calcitePlanJson.getBytes(Charset.defaultCharset()).length);
+        LOG.debug("JSON plan: \n{}", calcitePlanJson);
+      }
+
+      try {
+        perfLogger.perfLogBegin(this.getClass().getName(), "plan 
deserializer");
+        RelNode fromJson = deserializePlan(calcitePlan.getCluster(), 
calcitePlanJson);
+        perfLogger.perfLogEnd(this.getClass().getName(), "plan deserializer");
+
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("Base plan: \n{}", RelOptUtil.toString(calcitePlan));
+          LOG.debug("Plan from JSON: \n{}", RelOptUtil.toString(fromJson));
+        }
+
+        calcitePlan = fromJson;
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+

Review Comment:
   I think test code should't be shipped to production. Could you please move 
this to a unit test, there are ways to build a test plan:
   
https://github.com/apache/hive/blob/master/ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/views/TestHiveRowIsDeletedPropagator.java



-- 
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: gitbox-unsubscr...@hive.apache.org

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


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

Reply via email to