fsk119 commented on code in PR #21629:
URL: https://github.com/apache/flink/pull/21629#discussion_r1070221406


##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/session/FunctionCreator.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.gateway.api.session;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.catalog.Catalog;
+import org.apache.flink.table.module.Module;
+
+import java.util.Map;
+
+/**
+ * An interface used to create {@link Module} or {@link Catalog}.
+ *
+ * @param <R> type of the return value
+ */
+@PublicEvolving
+public interface FunctionCreator<R> {

Review Comment:
   I think it's better we move this inside the `SessionEnvironment` and add 
interface `ModuleCreator` and `CatalogCreator`.



##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/session/FunctionCreator.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.gateway.api.session;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.catalog.Catalog;
+import org.apache.flink.table.module.Module;
+
+import java.util.Map;
+
+/**
+ * An interface used to create {@link Module} or {@link Catalog}.
+ *
+ * @param <R> type of the return value
+ */
+@PublicEvolving
+public interface FunctionCreator<R> {
+
+    /**
+     * Applies this function to the given arguments.
+     *
+     * @return the function result
+     */
+    R create(Map<String, String> options, ReadableConfig configuration, 
ClassLoader classLoader);

Review Comment:
   I think we should not let the SqlGatewayService determine the options. It's 
the `Endpoint`'s responsibility to determine the options.



##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/session/FunctionCreator.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.gateway.api.session;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.catalog.Catalog;
+import org.apache.flink.table.module.Module;
+
+import java.util.Map;
+
+/**
+ * An interface used to create {@link Module} or {@link Catalog}.
+ *
+ * @param <R> type of the return value
+ */
+@PublicEvolving
+public interface FunctionCreator<R> {
+
+    /**
+     * Applies this function to the given arguments.
+     *
+     * @return the function result

Review Comment:
   Add a description of the input parameters as well.



##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/session/SessionEnvironment.java:
##########
@@ -81,7 +81,7 @@ public Map<String, Catalog> getRegisteredCatalogs() {
         return Collections.unmodifiableMap(registeredCatalogs);
     }
 
-    public Map<String, Module> getRegisteredModules() {
+    public Map<String, FunctionCreator<Module>> getRegisteredModules() {

Review Comment:
   rename to `getRegisteredModuleCreators`.
   
   By the way, I think we should also modify the `getRegisteredCatalogs` and 
return the `Map<String, CatalogCreator>`.



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2Endpoint.java:
##########
@@ -310,7 +311,11 @@ public TOpenSessionResp OpenSession(TOpenSessionReq 
tOpenSessionReq) throws TExc
             // all the alive PersistenceManager in the ObjectStore, which may 
get error like
             // "Persistence Manager has been closed" in the later connection.
             hiveCatalog.open();
-            Module hiveModule = new HiveModule();
+            // create hive module lazily
+            FunctionCreator<Module> hiveModuleCreator =
+                    (options, readableConfig, classLoader) ->
+                            FactoryUtil.createModule(

Review Comment:
   Notice: Factory#createModule still uses the AppClassloader to find the 
Factory. Please take at look at the `FactoryUtil#createModule` Line 486



##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/session/SessionEnvironment.java:
##########
@@ -166,13 +166,14 @@ public Builder registerCatalog(String catalogName, 
Catalog catalog) {
             return this;
         }
 
-        public Builder registerModuleAtHead(String moduleName, Module module) {
+        public Builder registerModuleAtHead(

Review Comment:
   Can we keep this method unchanged and add another method with different 
parameters? The `Builder` is used by the Endpoint Developer. The 
`SessionEnvironment` is the POJO used by the SessionContext.



##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/session/FunctionCreator.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.gateway.api.session;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.catalog.Catalog;
+import org.apache.flink.table.module.Module;
+
+import java.util.Map;
+
+/**
+ * An interface used to create {@link Module} or {@link Catalog}.
+ *
+ * @param <R> type of the return value
+ */
+@PublicEvolving

Review Comment:
   Can we mark the getter about the Catalog/Module with Inner annotation to 
escape the check?



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

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to