libenchao commented on code in PR #22259:
URL: https://github.com/apache/flink/pull/22259#discussion_r1148347234


##########
flink-table/flink-sql-jdbc-driver/src/main/java/org/apache/flink/table/jdbc/FlinkResultSet.java:
##########
@@ -0,0 +1,461 @@
+/*
+ * 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.jdbc;
+
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.client.gateway.StatementResult;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.types.RowKind;
+
+import javax.annotation.concurrent.GuardedBy;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.sql.Array;
+import java.sql.Date;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLDataException;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.List;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * ResultSet for flink jdbc driver. Only Batch Mode queries are supported. If 
you force to submit
+ * streaming queries, you may get unrecognized updates, deletions and other 
results.
+ */
+public class FlinkResultSet extends BaseResultSet {
+    private final List<DataType> dataTypeList;
+    private final List<String> columnNameList;
+    private final Statement statement;
+    private final StatementResult result;
+    private RowData currentRow;
+    private boolean wasNull;
+
+    @GuardedBy("this")
+    private boolean closed;
+
+    public FlinkResultSet(Statement statement, StatementResult result) {
+        this.statement = checkNotNull(statement);

Review Comment:
   It's better to provide a error message?



##########
flink-table/flink-sql-jdbc-driver/src/main/java/org/apache/flink/table/jdbc/FlinkResultSet.java:
##########
@@ -0,0 +1,461 @@
+/*
+ * 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.jdbc;
+
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.client.gateway.StatementResult;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.types.RowKind;
+
+import javax.annotation.concurrent.GuardedBy;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.sql.Array;
+import java.sql.Date;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLDataException;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.List;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * ResultSet for flink jdbc driver. Only Batch Mode queries are supported. If 
you force to submit
+ * streaming queries, you may get unrecognized updates, deletions and other 
results.
+ */
+public class FlinkResultSet extends BaseResultSet {
+    private final List<DataType> dataTypeList;
+    private final List<String> columnNameList;
+    private final Statement statement;
+    private final StatementResult result;
+    private RowData currentRow;
+    private boolean wasNull;
+
+    @GuardedBy("this")
+    private boolean closed;

Review Comment:
   Do we really need to `synchronize` on it? Is `volatile` modifier enough?



##########
flink-table/flink-sql-jdbc-driver/src/test/java/org/apache/flink/table/jdbc/FlinkResultSetTest.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.jdbc;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ResultKind;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.client.gateway.StatementResult;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.util.CloseableIterator;
+
+import org.junit.jupiter.api.Test;
+
+import java.sql.ResultSet;
+import java.sql.SQLDataException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
+
+/** Tests for {@link FlinkResultSet}. */
+public class FlinkResultSetTest {
+    private static final int RECORD_SIZE = 5000;
+
+    @Test
+    public void testResultSet() throws Exception {
+        List<Integer> dataList =
+                IntStream.range(0, 
RECORD_SIZE).boxed().collect(Collectors.toList());
+        CloseableIterator<RowData> data =
+                CloseableIterator.adapterForIterator(
+                        dataList.stream().map(i -> (RowData) 
GenericRowData.of(i)).iterator());
+        List<Integer> resultList = new ArrayList<>();
+        try (ResultSet resultSet =
+                new FlinkResultSet(
+                        new TestingStatement(),
+                        new StatementResult(
+                                ResolvedSchema.of(Column.physical("id", 
DataTypes.INT())),
+                                data,
+                                true,
+                                ResultKind.SUCCESS,
+                                JobID.generate()))) {
+            while (resultSet.next()) {
+                assertEquals(resultSet.getInt(1), resultSet.getInt("id"));
+                resultList.add(resultSet.getInt(1));

Review Comment:
   How about add test for all `getXXX` methods?



##########
flink-table/flink-sql-jdbc-driver/pom.xml:
##########
@@ -35,6 +35,11 @@
        <packaging>jar</packaging>
 
        <dependencies>
+               <dependency>
+                       <groupId>org.apache.flink</groupId>
+                       <artifactId>flink-sql-client</artifactId>

Review Comment:
   This should also be included in `flink-sql-jdbc-driver-bundle`.



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