You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by za...@apache.org on 2022/12/22 08:42:02 UTC

[calcite-avatica] branch main updated: [CALCITE-2322] Support fetch size in connection url and JDBC statement

This is an automated email from the ASF dual-hosted git repository.

zabetak pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite-avatica.git


The following commit(s) were added to refs/heads/main by this push:
     new 5047b566d [CALCITE-2322] Support fetch size in connection url and JDBC statement
5047b566d is described below

commit 5047b566d139fb9c4c691ccda3e5c18e15fc621f
Author: Kevin Minder <ke...@oracle.com>
AuthorDate: Tue May 22 21:46:23 2018 -0400

    [CALCITE-2322] Support fetch size in connection url and JDBC statement
    
    Co-authored-by: Zac Farrell <za...@modeanalytics.com>
    
    Close apache/calcite-avatica#49
    Close apache/calcite-avatica#148
---
 .../main/java/org/apache/calcite/avatica/AvaticaStatement.java |  3 ++-
 .../org/apache/calcite/avatica/BuiltInConnectionProperty.java  |  5 ++++-
 .../main/java/org/apache/calcite/avatica/ConnectionConfig.java |  2 ++
 .../java/org/apache/calcite/avatica/ConnectionConfigImpl.java  |  4 ++++
 core/src/main/java/org/apache/calcite/avatica/MetaImpl.java    | 10 +++++++++-
 site/_docs/client_reference.md                                 | 10 ++++++++++
 6 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java b/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
index 2d3c75689..1eff01bad 100644
--- a/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
+++ b/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
@@ -66,7 +66,7 @@ public abstract class AvaticaStatement
   final int resultSetType;
   final int resultSetConcurrency;
   final int resultSetHoldability;
-  private int fetchSize = DEFAULT_FETCH_SIZE;
+  private int fetchSize;
   private int fetchDirection;
   protected long maxRowCount = 0;
 
@@ -108,6 +108,7 @@ public abstract class AvaticaStatement
     this.resultSetType = resultSetType;
     this.resultSetConcurrency = resultSetConcurrency;
     this.resultSetHoldability = resultSetHoldability;
+    this.fetchSize = connection.config().fetchSize(); // Default to connection config value
     this.signature = signature;
     this.closed = false;
     if (h == null) {
diff --git a/core/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java b/core/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java
index 0313e4cc5..62c570298 100644
--- a/core/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java
+++ b/core/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java
@@ -88,7 +88,10 @@ public enum BuiltInConnectionProperty implements ConnectionProperty {
   HOSTNAME_VERIFICATION("hostname_verification", Type.ENUM, HostnameVerification.STRICT,
       HostnameVerification.class, false),
 
-  TRANSPARENT_RECONNECTION("transparent_reconnection", Type.BOOLEAN, Boolean.FALSE, false);
+  TRANSPARENT_RECONNECTION("transparent_reconnection", Type.BOOLEAN, Boolean.FALSE, false),
+
+  /** Number of rows to fetch per call. */
+  FETCH_SIZE("fetch_size", Type.NUMBER, AvaticaStatement.DEFAULT_FETCH_SIZE, false);
 
   private final String camelName;
   private final Type type;
diff --git a/core/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java b/core/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java
index 30d0c574e..bc06f8af5 100644
--- a/core/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java
+++ b/core/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java
@@ -64,6 +64,8 @@ public interface ConnectionConfig {
   HostnameVerification hostnameVerification();
   /** @see BuiltInConnectionProperty#TRANSPARENT_RECONNECTION */
   boolean transparentReconnectionEnabled();
+  /** @see BuiltInConnectionProperty#FETCH_SIZE */
+  int fetchSize();
 }
 
 // End ConnectionConfig.java
diff --git a/core/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java b/core/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java
index 7a2cbe411..0bb367732 100644
--- a/core/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java
+++ b/core/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java
@@ -133,6 +133,10 @@ public class ConnectionConfigImpl implements ConnectionConfig {
        .getBoolean();
   }
 
+  public int fetchSize() {
+    return BuiltInConnectionProperty.FETCH_SIZE.wrap(properties).getInt();
+  }
+
   /** Converts a {@link Properties} object containing (name, value)
    * pairs into a map whose keys are
    * {@link org.apache.calcite.avatica.InternalProperty} objects.
diff --git a/core/src/main/java/org/apache/calcite/avatica/MetaImpl.java b/core/src/main/java/org/apache/calcite/avatica/MetaImpl.java
index 1b3b20ec5..c41f8edfc 100644
--- a/core/src/main/java/org/apache/calcite/avatica/MetaImpl.java
+++ b/core/src/main/java/org/apache/calcite/avatica/MetaImpl.java
@@ -1543,6 +1543,7 @@ public abstract class MetaImpl implements Meta {
   private class FetchIterator implements Iterator<Object> {
     private final AvaticaStatement stmt;
     private final QueryState state;
+    private final int fetchSize;
     private Frame frame;
     private Iterator<Object> rows;
     private long currentOffset = 0;
@@ -1550,6 +1551,13 @@ public abstract class MetaImpl implements Meta {
     private FetchIterator(AvaticaStatement stmt, QueryState state, Frame firstFrame) {
       this.stmt = stmt;
       this.state = state;
+      int fetchRowCount;
+      try {
+        fetchRowCount = stmt.getFetchSize();
+      } catch (SQLException e) {
+        fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE;
+      }
+      this.fetchSize = fetchRowCount;
       if (firstFrame == null) {
         frame = Frame.MORE;
         rows = EmptyIterator.INSTANCE;
@@ -1589,7 +1597,7 @@ public abstract class MetaImpl implements Meta {
         }
         try {
           // currentOffset updated after element is read from `rows` iterator
-          frame = fetch(stmt.handle, currentOffset, AvaticaStatement.DEFAULT_FETCH_SIZE);
+          frame = fetch(stmt.handle, currentOffset, fetchSize);
         } catch (NoSuchStatementException e) {
           resetStatement();
           // re-fetch the batch where we left off
diff --git a/site/_docs/client_reference.md b/site/_docs/client_reference.md
index f49372ab5..060612e62 100644
--- a/site/_docs/client_reference.md
+++ b/site/_docs/client_reference.md
@@ -172,3 +172,13 @@ on-hover images for the permalink, but oh well.
 : _Default_: `null`.
 
 : _Required_: Only if `truststore` was provided.
+
+<strong><a name="fetch_size" href="#fetch_size">fetch_size</a></strong>
+
+: _Description_: The number of rows to fetch. If
+    <a href="https://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html#setFetchSize-int-">
+    Statement:setFetchSize</a> is set, that value overrides fetch_size.
+
+: _Default_: `100`.
+
+: _Required_: No.