Return-Path: Delivered-To: apmail-hive-commits-archive@www.apache.org Received: (qmail 27003 invoked from network); 18 Mar 2011 04:16:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Mar 2011 04:16:06 -0000 Received: (qmail 60858 invoked by uid 500); 18 Mar 2011 04:16:05 -0000 Delivered-To: apmail-hive-commits-archive@hive.apache.org Received: (qmail 60780 invoked by uid 500); 18 Mar 2011 04:16:03 -0000 Mailing-List: contact commits-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hive-dev@hive.apache.org Delivered-To: mailing list commits@hive.apache.org Received: (qmail 60772 invoked by uid 99); 18 Mar 2011 04:16:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Mar 2011 04:16:02 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Mar 2011 04:16:01 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4B233238889B; Fri, 18 Mar 2011 04:15:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1082819 - in /hive/trunk/jdbc/src: java/org/apache/hadoop/hive/jdbc/HiveQueryResultSet.java java/org/apache/hadoop/hive/jdbc/HiveStatement.java test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java Date: Fri, 18 Mar 2011 04:15:38 -0000 To: commits@hive.apache.org From: nzhang@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110318041538.4B233238889B@eris.apache.org> Author: nzhang Date: Fri Mar 18 04:15:37 2011 New Revision: 1082819 URL: http://svn.apache.org/viewvc?rev=1082819&view=rev Log: HIVE-1851. The class HiveResultSet should implement batch fetching (Bennie Schut via Ning Zhang) Modified: hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveQueryResultSet.java hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveStatement.java hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java Modified: hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveQueryResultSet.java URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveQueryResultSet.java?rev=1082819&r1=1082818&r2=1082819&view=diff ============================================================================== --- hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveQueryResultSet.java (original) +++ hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveQueryResultSet.java Fri Mar 18 04:15:37 2011 @@ -21,6 +21,7 @@ package org.apache.hadoop.hive.jdbc; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.List; import java.util.Properties; @@ -54,6 +55,10 @@ public class HiveQueryResultSet extends private int maxRows = 0; private int rowsFetched = 0; + private int fetchSize = 50; + + private List fetchedRows; + private Iterator fetchedRowsItr; public HiveQueryResultSet(HiveInterface client, int maxRows) throws SQLException { this.client = client; @@ -96,18 +101,18 @@ public class HiveQueryResultSet extends serde = new LazySimpleSerDe(); Properties props = new Properties(); if (names.length() > 0) { - LOG.info("Column names: " + names); + LOG.debug("Column names: " + names); props.setProperty(Constants.LIST_COLUMNS, names); } if (types.length() > 0) { - LOG.info("Column types: " + types); + LOG.debug("Column types: " + types); props.setProperty(Constants.LIST_COLUMN_TYPES, types); } serde.initialize(new Configuration(), props); } catch (Exception ex) { ex.printStackTrace(); - throw new SQLException("Could not create ResultSet: " + ex.getMessage()); + throw new SQLException("Could not create ResultSet: " + ex.getMessage(), ex); } } @@ -128,9 +133,19 @@ public class HiveQueryResultSet extends return false; } - String rowStr = ""; try { - rowStr = (String) client.fetchOne(); + if (fetchedRows == null || !fetchedRowsItr.hasNext()) { + fetchedRows = client.fetchN(fetchSize); + fetchedRowsItr = fetchedRows.iterator(); + } + + String rowStr = ""; + if (fetchedRowsItr.hasNext()) { + rowStr = fetchedRowsItr.next(); + } else { + return false; + } + rowsFetched++; if (LOG.isDebugEnabled()) { LOG.debug("Fetched row string: " + rowStr); @@ -165,6 +180,16 @@ public class HiveQueryResultSet extends return true; } + @Override + public void setFetchSize(int rows) throws SQLException { + fetchSize = rows; + } + + @Override + public int getFetchSize() throws SQLException { + return fetchSize; + } + /** * Convert a LazyObject to a standard Java object in compliance with JDBC 3.0 (see JDBC 3.0 * Specification, Table B-3: Mapping from JDBC Types to Java Object Types). Modified: hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveStatement.java URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveStatement.java?rev=1082819&r1=1082818&r2=1082819&view=diff ============================================================================== --- hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveStatement.java (original) +++ hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveStatement.java Fri Mar 18 04:15:37 2011 @@ -33,6 +33,8 @@ import org.apache.hadoop.hive.service.Hi public class HiveStatement implements java.sql.Statement { private JdbcSessionState session; private HiveInterface client; + private int fetchSize = 50; + /** * We need to keep a reference to the result set to support the following: * @@ -191,6 +193,7 @@ public class HiveStatement implements ja throw new SQLException(ex.toString(), "08S01"); } resultSet = new HiveQueryResultSet(client, maxRows); + resultSet.setFetchSize(fetchSize); return resultSet; } @@ -266,7 +269,7 @@ public class HiveStatement implements ja */ public int getFetchSize() throws SQLException { - throw new SQLException("Method not supported"); + return fetchSize; } /* @@ -446,7 +449,7 @@ public class HiveStatement implements ja */ public void setFetchSize(int rows) throws SQLException { - throw new SQLException("Method not supported"); + fetchSize = rows; } /* Modified: hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java?rev=1082819&r1=1082818&r2=1082819&view=diff ============================================================================== --- hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java (original) +++ hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java Fri Mar 18 04:15:37 2011 @@ -192,19 +192,23 @@ public class TestJdbcDriver extends Test } public final void testSelectAll() throws Exception { - doTestSelectAll(tableName, -1); // tests not setting maxRows (return all) - doTestSelectAll(tableName, 0); // tests setting maxRows to 0 (return all) + doTestSelectAll(tableName, -1, -1); // tests not setting maxRows (return all) + doTestSelectAll(tableName, 0, -1); // tests setting maxRows to 0 (return all) } public final void testSelectAllPartioned() throws Exception { - doTestSelectAll(partitionedTableName, -1); // tests not setting maxRows + doTestSelectAll(partitionedTableName, -1, -1); // tests not setting maxRows // (return all) - doTestSelectAll(partitionedTableName, 0); // tests setting maxRows to 0 + doTestSelectAll(partitionedTableName, 0, -1); // tests setting maxRows to 0 // (return all) } public final void testSelectAllMaxRows() throws Exception { - doTestSelectAll(tableName, 100); + doTestSelectAll(tableName, 100, -1); + } + + public final void testSelectAllFetchSize() throws Exception { + doTestSelectAll(tableName, 100, 20); } public void testDataTypes() throws Exception { @@ -267,11 +271,15 @@ public class TestJdbcDriver extends Test assertFalse(res.next()); } - private void doTestSelectAll(String tableName, int maxRows) throws Exception { + private void doTestSelectAll(String tableName, int maxRows, int fetchSize) throws Exception { Statement stmt = con.createStatement(); if (maxRows >= 0) { stmt.setMaxRows(maxRows); } + if (fetchSize > 0) { + stmt.setFetchSize(fetchSize); + assertEquals(fetchSize, stmt.getFetchSize()); + } // JDBC says that 0 means return all, which is the default int expectedMaxRows = maxRows < 1 ? 0 : maxRows;