You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ra...@apache.org on 2016/06/20 04:29:24 UTC

phoenix git commit: PHOENIX-2952 array_length return negative value (Joseph Sun)

Repository: phoenix
Updated Branches:
  refs/heads/master f840d558c -> 5e64eb3b9


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/5e64eb3b
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/5e64eb3b
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/5e64eb3b

Branch: refs/heads/master
Commit: 5e64eb3b9d8a77f18a770b37fc3d089d249bba33
Parents: f840d55
Author: Ramkrishna <ra...@intel.com>
Authored: Mon Jun 20 09:57:24 2016 +0530
Committer: Ramkrishna <ra...@intel.com>
Committed: Mon Jun 20 09:58:51 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/5e64eb3b/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/5e64eb3b/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) {