Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 178292693 -> ea66af60f
  refs/heads/4.x-HBase-1.0 7660e5eff -> 37e8948ec
  refs/heads/4.x-HBase-1.1 dcda00cea -> 847e90c4b
  refs/heads/master 0acabcdab -> bfda226ee


PHOENIX-3013 TO_CHAR fails to handle indexed null value (Junegunn Choi)


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

Branch: refs/heads/master
Commit: bfda226ee2c89dd57a5d3a6fa4552980775bc525
Parents: 0acabcd
Author: Josh Elser <[email protected]>
Authored: Tue Jun 21 18:50:47 2016 -0400
Committer: Josh Elser <[email protected]>
Committed: Tue Jun 21 21:23:41 2016 -0400

----------------------------------------------------------------------
 .../apache/phoenix/end2end/ToCharFunctionIT.java | 19 +++++++++++++++++++
 .../expression/function/ToCharFunction.java      |  3 +++
 2 files changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/bfda226e/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
index 7cb4b54..72544f2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
@@ -255,4 +255,23 @@ public class ToCharFunctionIT extends 
BaseHBaseManagedTimeTableReuseIT {
         assertEquals("Unexpected value for date ", String.valueOf(1234), 
rs.getString(1));
         assertFalse(rs.next());
     }
+
+    @Test
+    public void testIndexedNull() throws SQLException {
+        final String tableName = generateRandomString();
+        Connection conn = DriverManager.getConnection(getUrl());
+        conn.createStatement().execute("create table " + tableName +
+                " (id integer primary key, ts1 timestamp, ts2 timestamp)");
+        conn.createStatement().execute("create index t_ts2_idx on " + 
tableName + " (ts2)");
+        conn.createStatement().execute("upsert into " + tableName + " values 
(1, null, null)");
+        conn.commit();
+        for (String columnName : new String[]{"ts1", "ts2"}) {
+            try (ResultSet rs = conn.createStatement().executeQuery(
+                    String.format("select to_char(%s) from %s", columnName, 
tableName))) {
+                assertTrue(rs.next());
+                assertEquals(null, rs.getString(1));
+            }
+        }
+        conn.close();
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bfda226e/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
index d284e25..be40723 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
@@ -102,6 +102,9 @@ public class ToCharFunction extends ScalarFunction {
         if (!expression.evaluate(tuple, ptr)) {
             return false;
         }
+        if (ptr.getLength() == 0) {
+            return true;
+        }
         PDataType type = expression.getDataType();
         Object value = formatter.format(type.toObject(ptr, 
expression.getSortOrder()));
         byte[] b = getDataType().toBytes(value);

Reply via email to