becketqin commented on a change in pull request #9184: [FLINK-13339][ml] Add an 
implementation of pipeline's api
URL: https://github.com/apache/flink/pull/9184#discussion_r333551907
 
 

 ##########
 File path: 
flink-ml-parent/flink-ml-lib/src/main/java/org/apache/flink/ml/common/MLEnvironment.java
 ##########
 @@ -0,0 +1,130 @@
+/*
+ * 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.ml.common;
+
+import org.apache.flink.api.java.ExecutionEnvironment;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.java.BatchTableEnvironment;
+import org.apache.flink.table.api.java.StreamTableEnvironment;
+
+/**
+ * The MLEnvironment stores the necessary context in Flink.
+ * Each MLEnvironment will be associated with a unique ID.
+ * The operations associated with the same MLEnvironment ID
+ * will share the same Flink job context.
+ *
+ * <p>Both MLEnvironment ID and MLEnvironment can only be retrieved from 
MLEnvironmentFactory.
+ *
+ * @see ExecutionEnvironment
+ * @see StreamExecutionEnvironment
+ * @see BatchTableEnvironment
+ * @see StreamTableEnvironment
+ */
+public class MLEnvironment {
+       private ExecutionEnvironment env;
+       private StreamExecutionEnvironment streamEnv;
+       private BatchTableEnvironment batchTableEnv;
+       private StreamTableEnvironment streamTableEnv;
+
+       /**
+        * Construct with null that the class can load the environment in the 
`get` method.
+        */
+       public MLEnvironment() {
+               this(null, null, null, null);
+       }
+
+       /**
+        * Construct with env given by user.
+        *
+        * <p>The env can be null which will be loaded in the `get` method.
+        *
+        * @param batchEnv the ExecutionEnvironment
+        * @param batchTableEnv the BatchTableEnvironment
+        * @param streamEnv the StreamExecutionEnvironment
+        * @param streamTableEnv the StreamTableEnvironment
+        */
+       public MLEnvironment(
+               ExecutionEnvironment batchEnv,
+               BatchTableEnvironment batchTableEnv,
+               StreamExecutionEnvironment streamEnv,
+               StreamTableEnvironment streamTableEnv) {
+               this.env = batchEnv;
+               this.batchTableEnv = batchTableEnv;
+               this.streamEnv = streamEnv;
+               this.streamTableEnv = streamTableEnv;
+       }
+
+       /**
+        * Get the ExecutionEnvironment.
+        * if the ExecutionEnvironment has not been set, it initial the 
ExecutionEnvironment
+        * with default Configuration.
+        *
+        * @return the batch {@link ExecutionEnvironment}
+        */
+       public ExecutionEnvironment getExecutionEnvironment() {
+               if (null == env) {
+                       env = ExecutionEnvironment.getExecutionEnvironment();
+               }
+               return env;
+       }
+
+       /**
+        * Get the StreamExecutionEnvironment.
+        * if the StreamExecutionEnvironment has not been set, it initial the 
StreamExecutionEnvironment
+        * with default Configuration.
+        *
+        * @return the {@link StreamExecutionEnvironment}
+        */
+       public StreamExecutionEnvironment getStreamExecutionEnvironment() {
+               if (null == streamEnv) {
+                       streamEnv = 
StreamExecutionEnvironment.getExecutionEnvironment();
 
 Review comment:
   Can we set the private instance variables in the constructor? This way all 
the instance variables can be final.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to