Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 4d344b347 -> 0c86c7e3d


PHOENIX-2952 array_length return negative value (Joseph Sun)


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 0c86c7e3d63431aa100df87ee6731eb744b2be21
Parents: 4d344b3
Author: Ramkrishna <ramkrishna.s.vasude...@intel.com>
Authored: Mon Jun 20 09:57:24 2016 +0530
Committer: Ramkrishna <ramkrishna.s.vasude...@intel.com>
Committed: Mon Jun 20 10:00:28 2016 +0530

----------------------------------------------------------------------
 .../phoenix/end2end/RegexpSplitFunctionIT.java     | 17 +++++++++++++++++
 .../phoenix/schema/types/PArrayDataType.java       |  5 ++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/0c86c7e3/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
index 50b7a80..6df4829 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
@@ -86,6 +86,23 @@ public class RegexpSplitFunctionIT extends 
BaseHBaseManagedTimeTableReuseIT {
     }
 
     @Test
+    public void testArrayLenWithRegExpSplit() throws SQLException {
+       Connection conn = DriverManager.getConnection(getUrl());
+       String val = "T";
+       for(int i = 1; i < Short.MAX_VALUE + 500; i++) {
+               val += ",T";
+       }
+       
+        initTable(conn, val);
+
+        ResultSet rs = conn.createStatement().executeQuery(
+            "SELECT array_length(REGEXP_SPLIT(VAL, ',')) FROM " + SPLIT_TEST);
+        assertTrue(rs.next());
+        assertEquals(33267, rs.getInt(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
     public void testSplit_InFilter() throws SQLException {
         Connection conn = DriverManager.getConnection(getUrl());
         initTable(conn, "ONE,TWO,THREE");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/0c86c7e3/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
index 29af86e..e666a7a 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
@@ -1183,7 +1183,10 @@ public abstract class PArrayDataType<T> extends 
PDataType<T> {
             int elemLength = maxLength == null ? baseType.getByteSize() : 
maxLength;
             return (ptr.getLength() / elemLength);
         }
-        return Bytes.toInt(bytes, (ptr.getOffset() + ptr.getLength() - 
(Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT)));
+        // In case where the number of elements is greater than 
SHORT.MAX_VALUE we do negate the number of
+        // elements. So it is always better to return the absolute value
+               return Math
+                               .abs(Bytes.toInt(bytes, (ptr.getOffset() + 
ptr.getLength() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT))));
     }
 
     public static int estimateSize(int size, PDataType baseType) {

Reply via email to