You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by jx...@apache.org on 2015/11/06 18:32:58 UTC

[16/55] [abbrv] hive git commit: HIVE-11718 JDBC ResultSet.setFetchSize(0) returns no results (Aleksei Statkevich via Alan Gates)

HIVE-11718 JDBC ResultSet.setFetchSize(0) returns no results (Aleksei Statkevich via Alan Gates)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/902a548e
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/902a548e
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/902a548e

Branch: refs/heads/master-fixed
Commit: 902a548ea5f52481436c2ef99753d8cd34c666dc
Parents: de1fe68
Author: Alan Gates <ga...@hortonworks.com>
Authored: Mon Nov 2 16:14:32 2015 -0800
Committer: Alan Gates <ga...@hortonworks.com>
Committed: Mon Nov 2 16:14:32 2015 -0800

----------------------------------------------------------------------
 jdbc/pom.xml                                    |  8 +++++
 .../org/apache/hive/jdbc/HiveStatement.java     | 14 +++++++--
 .../org/apache/hive/jdbc/HiveStatementTest.java | 31 ++++++++++++++++++++
 3 files changed, 51 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/902a548e/jdbc/pom.xml
----------------------------------------------------------------------
diff --git a/jdbc/pom.xml b/jdbc/pom.xml
index dadf9c3..ea961a4 100644
--- a/jdbc/pom.xml
+++ b/jdbc/pom.xml
@@ -104,6 +104,13 @@
       <version>${hadoop.version}</version>
       <optional>true</optional>
     </dependency>
+    <!-- test inter-project -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${junit.version}</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <profiles>
@@ -117,6 +124,7 @@
 
   <build>
     <sourceDirectory>${basedir}/src/java</sourceDirectory>
+    <testSourceDirectory>${basedir}/src/test</testSourceDirectory>
     <resources>
       <resource>
         <directory>${basedir}/src/resources</directory>

http://git-wip-us.apache.org/repos/asf/hive/blob/902a548e/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
----------------------------------------------------------------------
diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
index 25456af..180f99e8 100644
--- a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
+++ b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
@@ -53,12 +53,13 @@ import org.slf4j.LoggerFactory;
  */
 public class HiveStatement implements java.sql.Statement {
   public static final Logger LOG = LoggerFactory.getLogger(HiveStatement.class.getName());
+  private static final int DEFAULT_FETCH_SIZE = 1000;
   private final HiveConnection connection;
   private TCLIService.Iface client;
   private TOperationHandle stmtHandle = null;
   private final TSessionHandle sessHandle;
   Map<String,String> sessConf = new HashMap<String,String>();
-  private int fetchSize = 1000;
+  private int fetchSize = DEFAULT_FETCH_SIZE;
   private boolean isScrollableResultset = false;
   /**
    * We need to keep a reference to the result set to support the following:
@@ -673,7 +674,16 @@ public class HiveStatement implements java.sql.Statement {
   @Override
   public void setFetchSize(int rows) throws SQLException {
     checkConnection("setFetchSize");
-    fetchSize = rows;
+    if (rows > 0) {
+      fetchSize = rows;
+    } else if (rows == 0) {
+      // Javadoc for Statement interface states that if the value is zero
+      // then "fetch size" hint is ignored.
+      // In this case it means reverting it to the default value.
+      fetchSize = DEFAULT_FETCH_SIZE;
+    } else {
+      throw new SQLException("Fetch size must be greater or equal to 0");
+    }
   }
 
   /*

http://git-wip-us.apache.org/repos/asf/hive/blob/902a548e/jdbc/src/test/org/apache/hive/jdbc/HiveStatementTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/org/apache/hive/jdbc/HiveStatementTest.java b/jdbc/src/test/org/apache/hive/jdbc/HiveStatementTest.java
new file mode 100644
index 0000000..be23b10
--- /dev/null
+++ b/jdbc/src/test/org/apache/hive/jdbc/HiveStatementTest.java
@@ -0,0 +1,31 @@
+package org.apache.hive.jdbc;
+
+import org.junit.Test;
+
+import java.sql.SQLException;
+
+import static org.junit.Assert.assertEquals;
+
+public class HiveStatementTest {
+
+  @Test
+  public void testSetFetchSize1() throws SQLException {
+    HiveStatement stmt = new HiveStatement(null, null, null);
+    stmt.setFetchSize(123);
+    assertEquals(123, stmt.getFetchSize());
+  }
+
+  @Test
+  public void testSetFetchSize2() throws SQLException {
+    HiveStatement stmt = new HiveStatement(null, null, null);
+    int initial = stmt.getFetchSize();
+    stmt.setFetchSize(0);
+    assertEquals(initial, stmt.getFetchSize());
+  }
+
+  @Test(expected = SQLException.class)
+  public void testSetFetchSize3() throws SQLException {
+    HiveStatement stmt = new HiveStatement(null, null, null);
+    stmt.setFetchSize(-1);
+  }
+}