You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "FangYongs (via GitHub)" <gi...@apache.org> on 2023/03/24 01:09:06 UTC

[GitHub] [flink] FangYongs opened a new pull request, #22259: [FLINK-31522] Introduce FlinkResultSet for jdbc driver

FangYongs opened a new pull request, #22259:
URL: https://github.com/apache/flink/pull/22259

   ## What is the purpose of the change
   
   This PR aims to introduce FlinkResultSet for jdbc driver
   
   ## Brief change log
     - Added BaseResultSet for unsupported feature in ResultSet
     - Add FlinkResultSet to read data from StatementResult
   
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - Added FlinkResultSetTest to read data from FlinkResultSet
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / no) no
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / no) no
     - The serializers: (yes / no / don't know) no
     - The runtime per-record code paths (performance sensitive): (yes / no / don't know) no
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / no / don't know) no
     - The S3 file system connector: (yes / no / don't know) no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes / no) no
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] FangYongs commented on pull request #22259: [FLINK-31522] Introduce FlinkResultSet for jdbc driver

Posted by "FangYongs (via GitHub)" <gi...@apache.org>.
FangYongs commented on PR #22259:
URL: https://github.com/apache/flink/pull/22259#issuecomment-1486688378

   Thanks @libenchao , rebased and updated


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] FangYongs commented on pull request #22259: [FLINK-31522] Introduce FlinkResultSet for jdbc driver

Posted by "FangYongs (via GitHub)" <gi...@apache.org>.
FangYongs commented on PR #22259:
URL: https://github.com/apache/flink/pull/22259#issuecomment-1486112232

   Thanks @libenchao , updated


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] flinkbot commented on pull request #22259: [FLINK-31522] Introduce FlinkResultSet for jdbc driver

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #22259:
URL: https://github.com/apache/flink/pull/22259#issuecomment-1482114819

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "29e85520f4073c4e1b14f63b2fa52d1f00cd124c",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "29e85520f4073c4e1b14f63b2fa52d1f00cd124c",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 29e85520f4073c4e1b14f63b2fa52d1f00cd124c UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] libenchao closed pull request #22259: [FLINK-31522] Introduce FlinkResultSet for jdbc driver

Posted by "libenchao (via GitHub)" <gi...@apache.org>.
libenchao closed pull request #22259: [FLINK-31522] Introduce FlinkResultSet for jdbc driver
URL: https://github.com/apache/flink/pull/22259


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] libenchao commented on a diff in pull request #22259: [FLINK-31522] Introduce FlinkResultSet for jdbc driver

Posted by "libenchao (via GitHub)" <gi...@apache.org>.
libenchao commented on code in PR #22259:
URL: https://github.com/apache/flink/pull/22259#discussion_r1150393962


##########
flink-table/flink-sql-jdbc-driver/src/main/java/org/apache/flink/table/jdbc/FlinkResultSet.java:
##########
@@ -0,0 +1,453 @@
+/*
+ * 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 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;
+
+    private volatile boolean closed;
+
+    public FlinkResultSet(Statement statement, StatementResult result) {
+        // TODO use Utils.checkNotNull to get rid of flink-core

Review Comment:
   Since FLINK-31538 has been merged, could you rebase to the latest master?



##########
flink-table/flink-sql-jdbc-driver-bundle/pom.xml:
##########
@@ -39,11 +39,19 @@
 			<groupId>org.apache.flink</groupId>
 			<artifactId>flink-sql-jdbc-driver</artifactId>
 			<version>${project.version}</version>
+			<scope>provided</scope>

Review Comment:
   IIUC, `scope` is unnecessary when we use shade plugin with 'include' (a.k.a, white list). See also 'flink-table-api-java-uber'.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] libenchao commented on a diff in pull request #22259: [FLINK-31522] Introduce FlinkResultSet for jdbc driver

Posted by "libenchao (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] FangYongs commented on pull request #22259: [FLINK-31522] Introduce FlinkResultSet for jdbc driver

Posted by "FangYongs (via GitHub)" <gi...@apache.org>.
FangYongs commented on PR #22259:
URL: https://github.com/apache/flink/pull/22259#issuecomment-1482115641

   Hi @libenchao Please help to review this PR when you are free


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org