wuchong commented on code in PR #20298:
URL: https://github.com/apache/flink/pull/20298#discussion_r930738752


##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/context/SessionContext.java:
##########
@@ -154,7 +160,11 @@ public void registerCatalog(String catalogName, Catalog 
catalog) {
     }
 
     public void registerModule(String moduleName, Module module) {
+        Deque<String> moduleNames = new 
ArrayDeque<>(sessionState.moduleManager.listModules());
+        moduleNames.addFirst(moduleName);

Review Comment:
   If the semantic of this method is registering the module at the head, the 
method name should be called `registerModuleAtHead` (the same as 
`SessionEnvironment.Builder#registerModule`). 



##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/endpoint/hive/HiveServer2EndpointStatementITCase.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.endpoint.hive;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.endpoint.hive.util.HiveServer2EndpointExtension;
+import org.apache.flink.table.endpoint.hive.util.ThriftObjectConversions;
+import org.apache.flink.table.gateway.AbstractSqlGatewayStatementITCase;
+import org.apache.flink.table.gateway.api.session.SessionHandle;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.utils.DataTypeUtils;
+
+import org.apache.hive.jdbc.HiveConnection;
+import org.apache.hive.service.rpc.thrift.TSessionHandle;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.lang.reflect.Field;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Stream;
+
+import static 
org.apache.flink.table.api.internal.StaticResultProvider.SIMPLE_ROW_DATA_TO_STRING_CONVERTER;
+
+/** ITCase to verify the statements. */
+public class HiveServer2EndpointStatementITCase extends 
AbstractSqlGatewayStatementITCase {
+
+    @RegisterExtension
+    @Order(3)
+    public static final HiveServer2EndpointExtension ENDPOINT_EXTENSION =
+            new 
HiveServer2EndpointExtension(SQL_GATEWAY_SERVICE_EXTENSION::getService);
+
+    private Connection connection;
+
+    @BeforeEach
+    @Override
+    public void before(@TempDir Path temporaryFolder) throws Exception {
+        super.before(temporaryFolder);
+        connection = ENDPOINT_EXTENSION.getConnection();
+    }
+
+    @AfterEach
+    public void after() throws Exception {
+        connection.close();
+    }
+
+    public static Stream<String> listHiveSqlTests() throws Exception {
+        return listTestSpecInTheSameModule("endpoint");
+    }
+
+    @ParameterizedTest
+    @MethodSource("listHiveSqlTests")
+    public void testHiveSqlStatements(String sqlPath) throws Exception {
+        runTest(sqlPath);
+    }
+
+    @Override
+    protected String runSingleStatement(String sql) throws Exception {
+        Statement statement = connection.createStatement();
+        statement.execute(sql);
+
+        ResultSet resultSet = statement.getResultSet();
+        ResultSetMetaData metaData = resultSet.getMetaData();
+
+        int columnSize = metaData.getColumnCount();
+        List<RowData> rows = new ArrayList<>();
+        DataType type = toStringifiedType(metaData);
+        while (resultSet.next()) {
+            GenericRowData stringifiedRowData = new GenericRowData(columnSize);
+            for (int i = 0; i < columnSize; i++) {
+                Object field = resultSet.getObject(i + 1);
+                // Similar to SIMPLE_ROW_DATA_TO_STRING_CONVERTER
+                if (field != null) {
+                    if (field instanceof Boolean) {
+                        stringifiedRowData.setField(i, field);
+                    } else if (field instanceof byte[]) {
+                        stringifiedRowData.setField(
+                                i,
+                                StringData.fromString(
+                                        new String((byte[]) field, 
StandardCharsets.UTF_8)));
+                    } else {
+                        stringifiedRowData.setField(i, 
StringData.fromString(field.toString()));
+                    }
+                }
+            }
+            rows.add(stringifiedRowData);
+        }
+
+        StatementType statementType = StatementType.match(sql);
+
+        return toString(
+                statementType,
+                DataTypeUtils.expandCompositeTypeToSchema(type),
+                SIMPLE_ROW_DATA_TO_STRING_CONVERTER,
+                rows.iterator());
+    }
+
+    @Override
+    protected String stringifyException(Throwable t) {
+        return t.getMessage().trim();
+    }
+
+    @Override
+    protected boolean isStreaming() throws Exception {
+        Field sessHandleField = 
HiveConnection.class.getDeclaredField("sessHandle");
+        // Set the accessibility as true
+        sessHandleField.setAccessible(true);
+        SessionHandle sessionHandle =
+                ThriftObjectConversions.toSessionHandle(
+                        (TSessionHandle) sessHandleField.get(connection));
+        return Configuration.fromMap(service.getSessionConfig(sessionHandle))
+                .get(ExecutionOptions.RUNTIME_MODE)
+                .equals(RuntimeExecutionMode.STREAMING);
+    }
+
+    @Override
+    protected void initializeSession() throws Exception {

Review Comment:
   This method looks very strange to me. I was thinking it's a pre-action for 
`testHiveSqlStatements` as well. Rename the method to 
`resetSessionForFlinkSqlStatements` ?  Alternatively, we can separate 
`testFlinkSqlStatements` and `testHiveSqlStatements` into different test 
classes. 



##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/endpoint/hive/HiveServer2EndpointStatementITCase.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.endpoint.hive;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.endpoint.hive.util.HiveServer2EndpointExtension;
+import org.apache.flink.table.endpoint.hive.util.ThriftObjectConversions;
+import org.apache.flink.table.gateway.AbstractSqlGatewayStatementITCase;
+import org.apache.flink.table.gateway.api.session.SessionHandle;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.utils.DataTypeUtils;
+
+import org.apache.hive.jdbc.HiveConnection;
+import org.apache.hive.service.rpc.thrift.TSessionHandle;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.lang.reflect.Field;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Stream;
+
+import static 
org.apache.flink.table.api.internal.StaticResultProvider.SIMPLE_ROW_DATA_TO_STRING_CONVERTER;
+
+/** ITCase to verify the statements. */
+public class HiveServer2EndpointStatementITCase extends 
AbstractSqlGatewayStatementITCase {
+
+    @RegisterExtension
+    @Order(3)
+    public static final HiveServer2EndpointExtension ENDPOINT_EXTENSION =
+            new 
HiveServer2EndpointExtension(SQL_GATEWAY_SERVICE_EXTENSION::getService);
+
+    private Connection connection;
+
+    @BeforeEach
+    @Override
+    public void before(@TempDir Path temporaryFolder) throws Exception {
+        super.before(temporaryFolder);
+        connection = ENDPOINT_EXTENSION.getConnection();
+    }
+
+    @AfterEach
+    public void after() throws Exception {
+        connection.close();
+    }
+
+    public static Stream<String> listHiveSqlTests() throws Exception {
+        return listTestSpecInTheSameModule("endpoint");
+    }
+
+    @ParameterizedTest
+    @MethodSource("listHiveSqlTests")
+    public void testHiveSqlStatements(String sqlPath) throws Exception {
+        runTest(sqlPath);
+    }
+
+    @Override
+    protected String runSingleStatement(String sql) throws Exception {
+        Statement statement = connection.createStatement();
+        statement.execute(sql);
+
+        ResultSet resultSet = statement.getResultSet();
+        ResultSetMetaData metaData = resultSet.getMetaData();
+
+        int columnSize = metaData.getColumnCount();
+        List<RowData> rows = new ArrayList<>();
+        DataType type = toStringifiedType(metaData);
+        while (resultSet.next()) {
+            GenericRowData stringifiedRowData = new GenericRowData(columnSize);
+            for (int i = 0; i < columnSize; i++) {
+                Object field = resultSet.getObject(i + 1);
+                // Similar to SIMPLE_ROW_DATA_TO_STRING_CONVERTER
+                if (field != null) {
+                    if (field instanceof Boolean) {
+                        stringifiedRowData.setField(i, field);
+                    } else if (field instanceof byte[]) {
+                        stringifiedRowData.setField(
+                                i,
+                                StringData.fromString(
+                                        new String((byte[]) field, 
StandardCharsets.UTF_8)));
+                    } else {
+                        stringifiedRowData.setField(i, 
StringData.fromString(field.toString()));
+                    }
+                }
+            }
+            rows.add(stringifiedRowData);
+        }
+
+        StatementType statementType = StatementType.match(sql);
+
+        return toString(
+                statementType,
+                DataTypeUtils.expandCompositeTypeToSchema(type),
+                SIMPLE_ROW_DATA_TO_STRING_CONVERTER,
+                rows.iterator());
+    }
+
+    @Override
+    protected String stringifyException(Throwable t) {
+        return t.getMessage().trim();
+    }
+
+    @Override
+    protected boolean isStreaming() throws Exception {
+        Field sessHandleField = 
HiveConnection.class.getDeclaredField("sessHandle");

Review Comment:
   nit: In theory, the configuration can be got by executing a `SET` statement, 
right?



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2Endpoint.java:
##########
@@ -126,13 +145,15 @@ public class HiveServer2Endpoint implements 
TCLIService.Iface, SqlGatewayEndpoin
     // 
--------------------------------------------------------------------------------------------
 
     private final SqlGatewayService service;
+    private final String host;

Review Comment:
   Print the ip address when hiveserver is started. 
   
   ```
   LOG.info("HiveServer2 Endpoint begins to listen on {}:{}.", address, port);
   ```



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/result/ResultFetcher.java:
##########
@@ -213,11 +187,7 @@ public synchronized ResultSet fetchResults(long token, int 
maxFetchSize) {
                 throw new SqlExecutionException(msg);
             }
             return new ResultSet(
-                    ResultSet.ResultType.PAYLOAD,
-                    currentToken,
-                    resultSchema,
-                    converter,
-                    new LinkedList<>(bufferedPrevResults));
+                    ResultSet.ResultType.PAYLOAD, currentToken, resultSchema, 
bufferedPrevResults);

Review Comment:
   Is the coping of `bufferedPrevResults` necessary? It seems there might be a 
new `fetchResult()` be called before the `ResultSet` is consumed. 



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2EndpointConfigOptions.java:
##########
@@ -35,6 +35,15 @@ public class HiveServer2EndpointConfigOptions {
     // Server Options
     // 
--------------------------------------------------------------------------------------------
 
+    public static final ConfigOption<String> THRIFT_HOST =
+            ConfigOptions.key("thrift.host")
+                    .stringType()
+                    .defaultValue("")
+                    .withDescription(
+                            "The server address of HiverServer2 host to be 
used for communication."
+                                    + "Default is empty, which means the to 
bind to the localhost. "

Review Comment:
   If default is localhost, why not use it as default value?



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