phoenix-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [phoenix] dbwong commented on a change in pull request #471: PHOENIX-5176 KeyRange.compareUpperRange(KeyRang 1, KeyRang 2) returns wrong result when two key ranges have the same upper bound values but one is inclusive and another is exclusive
Date Tue, 19 Mar 2019 20:45:48 GMT
dbwong commented on a change in pull request #471: PHOENIX-5176 KeyRange.compareUpperRange(KeyRang
1, KeyRang 2) returns wrong result when two key ranges have the same upper bound values but
one is inclusive and another is exclusive
URL: https://github.com/apache/phoenix/pull/471#discussion_r267089232
 
 

 ##########
 File path: phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeMoreTest.java
 ##########
 @@ -192,64 +193,78 @@ public void testListIntersectForBoundary() throws Exception {
 
         listIntersectAndAssert(Arrays.asList(KeyRange.EMPTY_RANGE),Arrays.asList(KeyRange.EVERYTHING_RANGE),Arrays.asList(KeyRange.EMPTY_RANGE));
 
-        rowKeyRanges1=Arrays.asList(
-                PInteger.INSTANCE.getKeyRange(
-                            PInteger.INSTANCE.toBytes(2),
-                            true,
-                            PInteger.INSTANCE.toBytes(5),
-                            true),
-                PInteger.INSTANCE.getKeyRange(
-                            PInteger.INSTANCE.toBytes(8),
-                            true,
-                            KeyRange.UNBOUND,
-                            false));
-        rowKeyRanges2=Arrays.asList(
-                PInteger.INSTANCE.getKeyRange(
-                        KeyRange.UNBOUND,
-                        false,
-                        PInteger.INSTANCE.toBytes(4),
-                        true),
-                PInteger.INSTANCE.getKeyRange(
-                        PInteger.INSTANCE.toBytes(7),
-                        true,
-                        PInteger.INSTANCE.toBytes(10),
-                        true),
-                PInteger.INSTANCE.getKeyRange(
-                    PInteger.INSTANCE.toBytes(13),
-                    true,
-                    PInteger.INSTANCE.toBytes(14),
-                    true),
-                PInteger.INSTANCE.getKeyRange(
-                    PInteger.INSTANCE.toBytes(19),
-                    true,
-                    KeyRange.UNBOUND,
-                    false)
-                );
-        expected=Arrays.asList(
-                PInteger.INSTANCE.getKeyRange(
-                            PInteger.INSTANCE.toBytes(2),
-                            true,
-                            PInteger.INSTANCE.toBytes(4),
-                            true),
-                    PInteger.INSTANCE.getKeyRange(
-                            PInteger.INSTANCE.toBytes(8),
-                            true,
-                            PInteger.INSTANCE.toBytes(10),
-                            true),
-                    PInteger.INSTANCE.getKeyRange(
-                            PInteger.INSTANCE.toBytes(13),
-                            true,
-                            PInteger.INSTANCE.toBytes(14),
-                            true),
-                    PInteger.INSTANCE.getKeyRange(
-                            PInteger.INSTANCE.toBytes(19),
-                            true,
-                            KeyRange.UNBOUND,
-                            false)
-                );
+        rowKeyRanges1 = CreateKeyRangeList(
+                Arrays.asList(2, 5, 8, Integer.MAX_VALUE),
+                Arrays.asList(true, true, true, false));
+        rowKeyRanges2 = CreateKeyRangeList(
+                Arrays.asList(Integer.MIN_VALUE, 4, 7, 10, 13, 14, 19, Integer.MAX_VALUE),
+                Arrays.asList(false, true, true, true, true, true, true, false));
+        expected = CreateKeyRangeList(
+                Arrays.asList(2, 4, 8, 10, 13, 14, 19, Integer.MAX_VALUE),
+                Arrays.asList(true, true, true, true, true, true, true, false));
+        listIntersectAndAssert(rowKeyRanges1, rowKeyRanges2, expected);
+
+        rowKeyRanges1 = CreateKeyRangeList(
+                Arrays.asList(3, 5, 5, 6),
+                Arrays.asList(true, false, true, false));
+        rowKeyRanges2 = CreateKeyRangeList(
+                Arrays.asList(3, 5, 6, 7),
+                Arrays.asList(true, true, true, true));
+        expected = CreateKeyRangeList(
+                Arrays.asList(3, 5),
+                Arrays.asList(true, true));
         listIntersectAndAssert(rowKeyRanges1, rowKeyRanges2, expected);
     }
 
+    @Test
+    public void testKeyRangeCompareUpperRange() throws Exception {
+        List<KeyRange> rowKeyRanges1 = CreateKeyRangeListWithFixedLowerRange(
+                Arrays.asList(Integer.MAX_VALUE, Integer.MAX_VALUE, 10000, 1001, 1000, 1000,
1000, 1000),
+                Arrays.asList(false, false, true, true, true, true, false, true));
+        List<KeyRange> rowKeyRanges2 = CreateKeyRangeListWithFixedLowerRange(
+                Arrays.asList(Integer.MAX_VALUE, 10000, Integer.MAX_VALUE, 1000, 1001, 1000,
1000, 1000),
+                Arrays.asList(false, false, false, true, true, true, false, false));
+        List<Integer> expectedResults = Arrays.asList(0, 1, -1, 1, -1, 0, 0, 1);
+        assertEquals(rowKeyRanges1.size(), rowKeyRanges2.size());
+        assertEquals(rowKeyRanges1.size(), expectedResults.size());
+
+        for (int i = 0; i < expectedResults.size(); i++) {
+            int compareResult = KeyRange.compareUpperRange(rowKeyRanges1.get(i), rowKeyRanges2.get(i));
+            assertEquals(expectedResults.get(i).intValue(), compareResult);
+        }
+    }
+
+    private static List<KeyRange> CreateKeyRangeListWithFixedLowerRange(List<Integer>
keys, List<Boolean> boundaryConditions) {
+        assertEquals(keys.size(), boundaryConditions.size());
+        List<Integer> newKeys = Lists.newArrayListWithCapacity(keys.size() * 2);
+        List<Boolean> newBoundaryConditions = Lists.newArrayListWithCapacity(boundaryConditions.size()
* 2);
+
+        for (int i = 0; i < keys.size(); i++) {
+            newKeys.add(0);
+            newBoundaryConditions.add(true);
+            newKeys.add(keys.get(i));
+            newBoundaryConditions.add(boundaryConditions.get(i));
+        }
+
+        return CreateKeyRangeList(newKeys, newBoundaryConditions);
+    }
+
+    private static List<KeyRange> CreateKeyRangeList(List<Integer> keys, List<Boolean>
boundaryConditions) {
+        assertEquals(keys.size(), boundaryConditions.size());
+        assertTrue(keys.size() % 2 == 0);
+
+        int size = keys.size() / 2;
+        List<KeyRange> keyRangeList = Lists.newArrayListWithCapacity(size);
+
+        for (int i = 0; i < size; i++) {
+            byte[] startKey = keys.get(2*i).equals(Integer.MIN_VALUE) ? KeyRange.UNBOUND
: PInteger.INSTANCE.toBytes(keys.get(2*i));
+            byte[] endKey = keys.get(2*i + 1).equals(Integer.MAX_VALUE) ? KeyRange.UNBOUND
: PInteger.INSTANCE.toBytes(keys.get(2*i + 1));
+            keyRangeList.add(PInteger.INSTANCE.getKeyRange(startKey, boundaryConditions.get(2*i),
endKey, boundaryConditions.get(2*i+1)));
+        }
+
+        return keyRangeList;
+    }
+
     private static void listIntersectAndAssert(List<KeyRange> rowKeyRanges1,List<KeyRange>
rowKeyRanges2,List<KeyRange> expected) {
         for(int i=0;i<200;i++) {
 
 Review comment:
   I see you didn't change this test case but as case as it is non-deterministic and the number
of permutations are O(n!) which grows large even on small subsets beyond the scope of a normal
rng period.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message