phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndimi...@apache.org
Subject phoenix git commit: PHOENIX-2372 Ensure null values are returned immediatedly in PhoenixResultSet.
Date Sat, 14 Nov 2015 19:27:52 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master 6a48b98cc -> 016b2b96e


PHOENIX-2372 Ensure null values are returned immediatedly in PhoenixResultSet.

Added a trivial test that exhibited the problem for Dates. BigDecimal
also had a similar problem on calling setScale on a null BigDecimal.


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/016b2b96
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/016b2b96
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/016b2b96

Branch: refs/heads/master
Commit: 016b2b96ec4afdf296967d1f2b7a2bb67b94b58e
Parents: 6a48b98
Author: Josh Elser <elserj@apache.org>
Authored: Wed Nov 4 15:32:21 2015 -0500
Committer: Nick Dimiduk <ndimiduk@apache.org>
Committed: Sat Nov 14 11:26:24 2015 -0800

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/DateTimeIT.java  | 34 ++++++++++++++++++++
 .../org/apache/phoenix/end2end/QueryMoreIT.java | 33 +++++++++++++++++++
 .../apache/phoenix/jdbc/PhoenixResultSet.java   |  7 ++++
 3 files changed, 74 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/016b2b96/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
index 0db36df..b4876a5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
@@ -34,6 +34,8 @@ import static org.apache.phoenix.util.TestUtil.ROW8;
 import static org.apache.phoenix.util.TestUtil.ROW9;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.math.BigDecimal;
@@ -47,6 +49,7 @@ import java.sql.Statement;
 import java.sql.Types;
 import java.text.Format;
 import java.util.Calendar;
+import java.util.GregorianCalendar;
 
 import org.apache.phoenix.util.DateUtil;
 import org.junit.After;
@@ -59,6 +62,7 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT {
     protected Connection conn;
     protected Date date;
     protected static final String tenantId = getOrganizationId();
+    protected final static String ROW10 = "00D123122312312";
 
     public DateTimeIT() throws Exception {
         super();
@@ -264,6 +268,25 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT {
         stmt.setDouble(16, 0.0009);
         stmt.execute();
 
+        stmt.setString(1, tenantId);
+        stmt.setString(2, ROW10);
+        stmt.setString(3, B_VALUE);
+        stmt.setString(4, B_VALUE);
+        stmt.setInt(5, 7);
+        // Intentionally null
+        stmt.setDate(6, null);
+        stmt.setBigDecimal(7, BigDecimal.valueOf(0.1));
+        stmt.setLong(8, 5L);
+        stmt.setInt(9, 5);
+        stmt.setNull(10, Types.INTEGER);
+        stmt.setByte(11, (byte)7);
+        stmt.setShort(12, (short) 134);
+        stmt.setFloat(13, 0.07f);
+        stmt.setDouble(14, 0.0007);
+        stmt.setFloat(15, 0.07f);
+        stmt.setDouble(16, 0.0007);
+        stmt.execute();
+
         conn.commit();
     }
 
@@ -634,4 +657,15 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT {
         assertEquals(26, rs.getInt(3));
         assertFalse(rs.next());
     }
+
+    @Test
+    public void testNullDate() throws Exception {
+        ResultSet rs = conn.createStatement().executeQuery("SELECT a_date, entity_id from
" + ATABLE_NAME + " WHERE entity_id = '" + ROW10 + "'");
+        assertNotNull(rs);
+        assertTrue(rs.next());
+        assertEquals(ROW10, rs.getString(2));
+        assertNull(rs.getDate(1));
+        assertNull(rs.getDate(1, GregorianCalendar.getInstance()));
+        assertFalse(rs.next());
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/016b2b96/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java
index a29cb0e..8f2bc73 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java
@@ -19,6 +19,8 @@ package org.apache.phoenix.end2end;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.sql.Connection;
@@ -26,6 +28,7 @@ import java.sql.Date;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -328,4 +331,34 @@ public class QueryMoreIT extends BaseHBaseManagedTimeIT {
         rs.getObject("NEW_VALUE");
         assertFalse(rs.next());
     }
+
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testNullBigDecimalWithScale() throws Exception {
+        final String table = "NULLBIGDECIMAL";
+        final Connection conn = DriverManager.getConnection(getUrl());
+        conn.setAutoCommit(true);
+        try (Statement stmt = conn.createStatement()) {
+            assertFalse(stmt.execute("CREATE TABLE IF NOT EXISTS " + table + " (\n" +
+                "PK VARCHAR(15) NOT NULL\n," +
+                "DEC DECIMAL,\n" +
+                "CONSTRAINT TABLE_PK PRIMARY KEY (PK))"));
+        }
+
+        try (PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table + " (PK,
DEC) VALUES(?, ?)")) {
+            stmt.setString(1, "key");
+            stmt.setBigDecimal(2, null);
+            assertFalse(stmt.execute());
+            assertEquals(1, stmt.getUpdateCount());
+        }
+
+        try (Statement stmt = conn.createStatement()) {
+            final ResultSet rs = stmt.executeQuery("SELECT * FROM " + table);
+            assertNotNull(rs);
+            assertTrue(rs.next());
+            assertEquals("key", rs.getString(1));
+            assertNull(rs.getBigDecimal(2));
+            assertNull(rs.getBigDecimal(2, 10));
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/016b2b96/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
index 60a6957..c1bbe81 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
@@ -242,6 +242,9 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
         BigDecimal value = getBigDecimal(columnIndex);
+        if (wasNull) {
+            return null;
+        }
         return value.setScale(scale);
     }
 
@@ -383,6 +386,10 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
         checkCursorState();
         Date value = (Date)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
             PDate.INSTANCE, ptr);
+        wasNull = (value == null);
+        if (wasNull) {
+            return null;
+        }
         cal.setTime(value);
         return new Date(cal.getTimeInMillis());
     }


Mime
View raw message