drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h.@apache.org
Subject [6/8] drill git commit: DRILL-3766: Fix ResultSet.getRow() (make 1-based; return 0 at end).
Date Tue, 10 Nov 2015 21:49:41 GMT
DRILL-3766:  Fix ResultSet.getRow() (make 1-based; return 0 at end).

Corrected for Avatica's non-JDBC-compliant behavior.

Also purged unused imports.


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/194680c5
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/194680c5
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/194680c5

Branch: refs/heads/master
Commit: 194680c564758b6c4fb0d7ce9f9d5432db270f55
Parents: e4f257b
Author: dbarclay <dbarclay@maprtech.com>
Authored: Wed Sep 23 18:13:56 2015 -0700
Committer: Hanifi Gunes <hanifigunes@gmail.com>
Committed: Mon Nov 9 12:17:03 2015 -0800

----------------------------------------------------------------------
 .../drill/jdbc/impl/DrillResultSetImpl.java     |  4 +-
 .../apache/drill/jdbc/DrillResultSetTest.java   | 61 ++++++++++++--------
 2 files changed, 39 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/194680c5/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillResultSetImpl.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillResultSetImpl.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillResultSetImpl.java
index d7de677..4878251 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillResultSetImpl.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillResultSetImpl.java
@@ -545,7 +545,9 @@ class DrillResultSetImpl extends AvaticaResultSet implements DrillResultSet
{
   @Override
   public int getRow() throws SQLException {
     throwIfClosed();
-    return super.getRow();
+    // Map Avatica's erroneous zero-based row numbers to 1-based, and return 0
+    // after end, per JDBC:
+    return isAfterLast() ? 0 : 1 + super.getRow();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/drill/blob/194680c5/exec/jdbc/src/test/java/org/apache/drill/jdbc/DrillResultSetTest.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/DrillResultSetTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/DrillResultSetTest.java
index 2df173e..8574d28 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/DrillResultSetTest.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/DrillResultSetTest.java
@@ -20,44 +20,23 @@ package org.apache.drill.jdbc;
 import static org.junit.Assert.*;
 
 import java.sql.Connection;
-import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import net.hydromatic.linq4j.Ord;
-
-import org.apache.drill.common.config.DrillConfig;
-import org.apache.drill.common.logical.LogicalPlan;
-import org.apache.drill.common.logical.data.LogicalOperator;
-import org.apache.drill.common.util.Hook;
+
 import org.apache.drill.exec.ExecConstants;
 import org.apache.drill.jdbc.test.JdbcAssert;
 import org.apache.drill.test.DrillTest;
 import org.junit.AfterClass;
-import org.junit.Assert;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.anyOf;
 import static org.hamcrest.core.StringContains.containsString;
 
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.ImmutableSet.Builder;
+
 
 public class DrillResultSetTest extends DrillTest {
 
@@ -85,7 +64,8 @@ public class DrillResultSetTest extends DrillTest {
   public void test_next_blocksFurtherAccessAfterEnd()
       throws SQLException
   {
-    Connection connection = new Driver().connect( "jdbc:drill:zk=local", JdbcAssert.getDefaultProperties()
);
+    Connection connection =
+        new Driver().connect( "jdbc:drill:zk=local", JdbcAssert.getDefaultProperties() );
     Statement statement = connection.createStatement();
     ResultSet resultSet =
         statement.executeQuery( "SELECT 1 AS x \n" +
@@ -125,7 +105,8 @@ public class DrillResultSetTest extends DrillTest {
   public void test_next_blocksFurtherAccessWhenNoRows()
     throws Exception
   {
-    Connection connection = new Driver().connect( "jdbc:drill:zk=local", JdbcAssert.getDefaultProperties()
);
+    Connection connection =
+        new Driver().connect( "jdbc:drill:zk=local", JdbcAssert.getDefaultProperties() );
     Statement statement = connection.createStatement();
     ResultSet resultSet =
         statement.executeQuery( "SELECT 'Hi' AS x \n" +
@@ -155,6 +136,36 @@ public class DrillResultSetTest extends DrillTest {
     // TODO:  Ideally, test all other accessor methods.
   }
 
+  @Test
+  public void test_getRow_isOneBased()
+    throws Exception
+  {
+    Connection connection =
+        new Driver().connect( "jdbc:drill:zk=local", JdbcAssert.getDefaultProperties() );
+    Statement statement = connection.createStatement();
+    ResultSet resultSet =
+        statement.executeQuery( "VALUES (1), (2)" );
+
+    // Expect 0 when before first row:
+    assertThat( "getRow() before first next()", resultSet.getRow(), equalTo( 0 ) );
+
+    resultSet.next();
+
+    // Expect 1 at first row:
+    assertThat( "getRow() at first row", resultSet.getRow(), equalTo( 1 ) );
+
+    resultSet.next();
+
+    // Expect 2 at second row:
+    assertThat( "getRow() at second row", resultSet.getRow(), equalTo( 2 ) );
+
+    resultSet.next();
+
+    // Expect 0 again when after last row:
+    assertThat( "getRow() after last row", resultSet.getRow(), equalTo( 0 ) );
+    resultSet.next();
+    assertThat( "getRow() after last row", resultSet.getRow(), equalTo( 0 ) );
+  }
 
   // TODO:  Ideally, test other methods.
 


Mime
View raw message