aljoscha commented on a change in pull request #9690: [FLINK-14067] Decouple 
PlanExecutor from JSON plan generation
URL: https://github.com/apache/flink/pull/9690#discussion_r325057597
 
 

 ##########
 File path: 
flink-java/src/main/java/org/apache/flink/api/java/ExecutionPlanUtil.java
 ##########
 @@ -0,0 +1,76 @@
+/*
+ * 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.flink.api.java;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.Plan;
+
+/**
+ * A utility for extracting an execution plan (as JSON) from a {@link Plan}.
+ */
+@Internal
+public class ExecutionPlanUtil {
+
+       private static final String PLAN_GENERATOR_CLASS_NAME = 
"org.apache.flink.optimizer.plandump.ExecutionPlanJSONGenerator";
+
+       /**
+        * Extracts the execution plan (as JSON) from the given {@link Plan}.
+        */
+       public static String getExecutionPlanAsJSON(Plan plan) {
+               ExecutionPlanJSONGenerator jsonGenerator = getJSONGenerator();
+               return jsonGenerator.getExecutionPlan(plan);
+       }
+
+       private static ExecutionPlanJSONGenerator getJSONGenerator() {
+               Class<? extends ExecutionPlanJSONGenerator> planGeneratorClass 
= loadJSONGeneratorClass(
+                               PLAN_GENERATOR_CLASS_NAME);
+
+               try {
+                       return 
planGeneratorClass.getConstructor().newInstance();
+               } catch (Throwable t) {
+                       throw new RuntimeException("An error occurred while 
loading the plan generator ("
+                                       + PLAN_GENERATOR_CLASS_NAME + ").", t);
+               }
+       }
+
+       private static Class<? extends ExecutionPlanJSONGenerator> 
loadJSONGeneratorClass(String className) {
+               try {
+                       Class<?> generatorClass = Class.forName(
+                                       
"org.apache.flink.optimizer.plandump.ExecutionPlanJSONGenerator");
 
 Review comment:
   fixing

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to