wuchong commented on a change in pull request #15006:
URL: https://github.com/apache/flink/pull/15006#discussion_r591160927



##########
File path: 
flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/gateway/context/SessionContext.java
##########
@@ -0,0 +1,269 @@
+/*
+ * 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.table.client.gateway.context;
+
+import org.apache.flink.client.ClientUtils;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.catalog.Catalog;
+import org.apache.flink.table.catalog.CatalogManager;
+import org.apache.flink.table.catalog.FunctionCatalog;
+import org.apache.flink.table.catalog.GenericInMemoryCatalog;
+import org.apache.flink.table.client.config.Environment;
+import org.apache.flink.table.client.gateway.Executor;
+import org.apache.flink.table.client.gateway.SqlExecutionException;
+import org.apache.flink.table.module.ModuleManager;
+import org.apache.flink.util.TemporaryClassLoaderContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.URLClassLoader;
+import java.util.Collections;
+import java.util.Objects;
+
+/**
+ * Context describing a session, it's mainly used for user to open a new 
session in the backend. If
+ * client request to open a new session, the backend {@link Executor} will 
maintain the session
+ * context map util users close it.
+ */
+public class SessionContext {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(SessionContext.class);
+
+    private final String sessionId;
+    private final DefaultContext defaultContext;
+
+    private Environment sessionEnv;
+    private final Configuration sessionConfiguration;
+
+    private final SessionState sessionState;
+    private final URLClassLoader classLoader;
+    private ExecutionContext executionContext;
+
+    public SessionContext(
+            DefaultContext defaultContext,
+            String sessionId,
+            Environment sessionEnv,
+            Configuration sessionConfiguration,
+            URLClassLoader classLoader,
+            SessionState sessionState,
+            ExecutionContext executionContext) {
+        this.defaultContext = defaultContext;
+        this.sessionId = sessionId;
+        this.sessionEnv = sessionEnv;
+        this.sessionConfiguration = sessionConfiguration;
+        this.classLoader = classLoader;
+        this.sessionState = sessionState;
+        this.executionContext = executionContext;
+    }
+
+    // 
--------------------------------------------------------------------------------------------
+    // Getter method
+    // 
--------------------------------------------------------------------------------------------
+
+    public String getSessionId() {
+        return this.sessionId;
+    }
+
+    public Environment getSessionEnvironment() {
+        return this.sessionEnv;
+    }
+
+    public ExecutionContext getExecutionContext() {
+        return this.executionContext;
+    }
+
+    // 
--------------------------------------------------------------------------------------------
+    // Method to execute commands
+    // 
--------------------------------------------------------------------------------------------
+
+    /** Reset properties to default. It will rebuild a new {@link 
ExecutionContext}. */
+    public void reset() {
+        sessionEnv = defaultContext.getDefaultEnv().clone();
+        for (String key : sessionConfiguration.toMap().keySet()) {
+            // Don't care the type of the option
+            ConfigOption<String> keyToDelete = 
ConfigOptions.key(key).stringType().noDefaultValue();
+            sessionConfiguration.removeConfig(keyToDelete);
+        }
+        sessionConfiguration.addAll(defaultContext.getFlinkConfig());

Review comment:
       I see, could you add comment to mention this? 




----------------------------------------------------------------
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


Reply via email to