phoenix-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [phoenix] twdsilva commented on a change in pull request #463: Phoenix stats Initial Commit
Date Tue, 09 Apr 2019 23:25:05 GMT
twdsilva commented on a change in pull request #463: Phoenix stats Initial Commit
URL: https://github.com/apache/phoenix/pull/463#discussion_r273734396
 
 

 ##########
 File path: phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesIntersectTest.java
 ##########
 @@ -58,12 +67,433 @@ private static void assertIntersect(ScanRanges ranges, String lowerRange,
String
             assertEquals(expectedKeys, filter.getSlots().get(0));
         }
     }
-    
+
+    private static byte[] stringToByteArray(String str){
+        return PVarchar.INSTANCE.toBytes(str);
+    }
+
+    private static String ByteArrayToString(byte[] bytes){
+        String literalString = PVarchar.INSTANCE.toStringLiteral(bytes,null);
+        return literalString.substring(1,literalString.length() - 1);
+    }
+
     private static List<KeyRange> points(String... points) {
         List<KeyRange> keys = Lists.newArrayListWithExpectedSize(points.length);
         for (String point : points) {
-            keys.add(KeyRange.getKeyRange(PVarchar.INSTANCE.toBytes(point)));
+            keys.add(KeyRange.getKeyRange(stringToByteArray(point)));
         }
         return keys;
     }
+
+    private static PDatum SIMPLE_CHAR = new PDatum() {
+        @Override
+        public boolean isNullable() {
+            return false;
+        }
+
+        @Override
+        public PDataType getDataType() {
+            return PChar.INSTANCE;
+        }
+
+        @Override
+        public Integer getMaxLength() {
+            return 1;
+        }
+
+        @Override
+        public Integer getScale() {
+            return null;
+        }
+
+        @Override
+        public SortOrder getSortOrder() {
+            return SortOrder.getDefault();
+        }
+    };
+
+    // Does not handle some edge conditions like empty string
+    private String handleScanNextKey(String key) {
+        char lastChar = key.charAt(key.length() - 1);
+        return key.substring(0, key.length() - 1) + String.valueOf((char)(lastChar + 1));
+    }
+
+    @Test
+    public void getRowKeyRangesTestEverythingRange() {
+        int rowKeySchemaFields = 1;
+        RowKeySchema schema = buildSimpleRowKeySchema(rowKeySchemaFields);
+
+        List<List<KeyRange>> ranges = new ArrayList<>();
+        ranges.add(Lists.newArrayList(KeyRange.EVERYTHING_RANGE));
+        ScanRanges scanRanges = ScanRanges.createSingleSpan(schema, ranges);
+
+        List<KeyRange> rowKeyRanges = scanRanges.getRowKeyRanges();
+        assertEquals(1, rowKeyRanges.size());
+        assertEquals(KeyRange.EVERYTHING_RANGE,rowKeyRanges.get(0));
+    }
+
+    @Test
+    public void getRowKeyRangesTestEmptyRange() {
+        int rowKeySchemaFields = 1;
+        RowKeySchema schema = buildSimpleRowKeySchema(rowKeySchemaFields);
+
+        List<List<KeyRange>> ranges = new ArrayList<>();
+        ranges.add(Lists.newArrayList(KeyRange.EMPTY_RANGE));
+        ScanRanges scanRanges = ScanRanges.createSingleSpan(schema, ranges);
+
+        List<KeyRange> rowKeyRanges = scanRanges.getRowKeyRanges();
+        assertEquals(1, rowKeyRanges.size());
+        assertEquals(KeyRange.EMPTY_RANGE,rowKeyRanges.get(0));
+    }
+
+    @Test
+    public void getRowKeyRangesTestPointLookUp() {
+        String pointString = "A";
+        KeyRange pointKeyRange = KeyRange.getKeyRange(stringToByteArray(pointString));
+        ScanRanges singlePointScanRange = ScanRanges.createPointLookup(Lists.newArrayList(pointKeyRange));
+
+        List<KeyRange> rowKeyRanges = singlePointScanRange.getRowKeyRanges();
+        assertEquals(1, rowKeyRanges.size());
+        assertEquals(false, rowKeyRanges.get(0).isSingleKey());
+        assertEquals(singleKeyToScanRange(pointString), rowKeyRanges.get(0).toString());
+    }
+
+    @Test
+    public void getRowKeyRangesTestPointsLookUp() {
+        String pointString1 = "A";
+        String pointString2 = "B";
+        KeyRange pointKeyRange1 = KeyRange.getKeyRange(stringToByteArray(pointString1));
+        KeyRange pointKeyRange2 = KeyRange.getKeyRange(stringToByteArray(pointString2));
+        ScanRanges singlePointScanRange = ScanRanges
+                .createPointLookup(Lists.newArrayList(pointKeyRange1, pointKeyRange2));
+
+        List<KeyRange> rowKeyRanges = singlePointScanRange.getRowKeyRanges();
+        assertEquals(2, rowKeyRanges.size());
+        assertEquals(false, rowKeyRanges.get(0).isSingleKey());
+        assertEquals(singleKeyToScanRange(pointString1), rowKeyRanges.get(0).toString());
+        assertEquals(false, rowKeyRanges.get(1).isSingleKey());
+        assertEquals(singleKeyToScanRange(pointString2), rowKeyRanges.get(1).toString());
+    }
+
+    @Test
+    public void getRowKeyRangesTestOneRangeLookUp() {
+        RowKeySchema schema = buildSimpleRowKeySchema(1);
+
+        String lowerString = "A";
+        String upperString = "B";
+
+        KeyRange rangeKeyRange = KeyRange.getKeyRange(stringToByteArray(lowerString), stringToByteArray(upperString));
+        List<List<KeyRange>> ranges = new ArrayList<>();
+        ranges.add(Lists.newArrayList(rangeKeyRange));
+        ScanRanges scanRanges = ScanRanges.createSingleSpan(schema, ranges);
+
+        List<KeyRange> rowKeyRanges = scanRanges.getRowKeyRanges();
+        assertEquals(1, rowKeyRanges.size());
+        assertEquals(false, rowKeyRanges.get(0).isSingleKey());
+        assertEquals(lowerString, ByteArrayToString(rowKeyRanges.get(0).getLowerRange()));
+        assertEquals(upperString, ByteArrayToString(rowKeyRanges.get(0).getUpperRange()));
+    }
+
+    @Test
+    public void getRowKeyRangesTestOneExclusiveRangeLookUp() {
+        RowKeySchema schema = buildSimpleRowKeySchema(2);
+
+        String lowerString = "A";
+        String upperString = "C";
+
+        KeyRange rangeKeyRange = KeyRange.getKeyRange(stringToByteArray(lowerString),false,
stringToByteArray(upperString),false);
+        List<List<KeyRange>> ranges = new ArrayList<>();
+        ranges.add(Lists.newArrayList(rangeKeyRange));
+        ScanRanges scanRanges = ScanRanges.createSingleSpan(schema, ranges);
+
+        List<KeyRange> rowKeyRanges = scanRanges.getRowKeyRanges();
+        assertEquals(1, rowKeyRanges.size());
+        assertEquals(false, rowKeyRanges.get(0).isSingleKey());
+        assertEquals("[B - C)", rowKeyRanges.get(0).toString());
+    }
+
+    @Test
+    public void getRowKeyRangesTestOneExclusiveRangeNotFullyQualifiedLookUp() {
+        RowKeySchema schema = buildSimpleRowKeySchema(2);
+
+        String lowerString = "A";
+        String upperString = "C";
+
+        KeyRange rangeKeyRange = KeyRange.getKeyRange(stringToByteArray(lowerString),false,
stringToByteArray(upperString),false);
+        List<List<KeyRange>> ranges = new ArrayList<>();
+        ranges.add(Lists.newArrayList(rangeKeyRange));
+        ScanRanges scanRanges = ScanRanges.createSingleSpan(schema, ranges);
+
+        List<KeyRange> rowKeyRanges = scanRanges.getRowKeyRanges();
+        assertEquals(1, rowKeyRanges.size());
+        assertEquals(false, rowKeyRanges.get(0).isSingleKey());
+        assertEquals("[B - C)", rowKeyRanges.get(0).toString());
+    }
+
+    @Test
+    public void getRowKeyRangesTestTwoRangesLookUp() {
+        int rowKeySchemaFields = 2;
+        RowKeySchema schema = buildSimpleRowKeySchema(rowKeySchemaFields);
+        int[] slotSpan = new int[rowKeySchemaFields];
+
+        String lowerString = "A";
+        String upperString = "B";
+
+        String lowerString2 = "C";
+        String upperString2 = "D";
+
+        KeyRange rangeKeyRange1 = KeyRange.getKeyRange(stringToByteArray(lowerString), true,
+                stringToByteArray(upperString), true);
+        KeyRange rangeKeyRange2 = KeyRange.getKeyRange(stringToByteArray(lowerString2), true,
+                stringToByteArray(upperString2), true);
+
+        List<List<KeyRange>> ranges = new ArrayList<>();
+        ranges.add(Lists.newArrayList(rangeKeyRange1));
+        ranges.add(Lists.newArrayList(rangeKeyRange2));
+
+        ScanRanges scanRanges = ScanRanges.create(schema, ranges, slotSpan, null, true, -1);
+
+        List<KeyRange> rowKeyRanges = scanRanges.getRowKeyRanges();
+        assertEquals(1, rowKeyRanges.size());
+        assertEquals(false, rowKeyRanges.get(0).isSingleKey());
+        assertEquals(lowerString + lowerString2, ByteArrayToString(rowKeyRanges.get(0).getLowerRange()));
+        assertEquals(handleScanNextKey(upperString + upperString2),
+                ByteArrayToString(rowKeyRanges.get(0).getUpperRange()));
+    }
+
+    @Test
+    public void getRowKeyRangesTestNotFullyQualifiedRowKeyLookUp() {
+        int rowKeySchemaFields = 2;
+        RowKeySchema schema = buildSimpleRowKeySchema(rowKeySchemaFields);
+        int[] slotSpan = new int[rowKeySchemaFields];
+
+        String keyString1 = "A";
+        String keyString2 = "B";
+
+        KeyRange rangeKeyRange1 = KeyRange.getKeyRange(stringToByteArray(keyString1));
+        KeyRange rangeKeyRange2 = KeyRange.getKeyRange(stringToByteArray(keyString2));
+
+        List<List<KeyRange>> ranges = new ArrayList<>();
+        ranges.add(Lists.newArrayList(rangeKeyRange1, rangeKeyRange2));
+
+        ScanRanges scanRanges = ScanRanges.create(schema, ranges, slotSpan, null, true, -1);
+
+        List<KeyRange> rowKeyRanges = scanRanges.getRowKeyRanges();
+        assertEquals(2, rowKeyRanges.size());
+        assertEquals(false, rowKeyRanges.get(0).isSingleKey());
+        assertEquals(keyString1, ByteArrayToString(rowKeyRanges.get(0).getLowerRange()));
+        assertEquals(handleScanNextKey(keyString1), ByteArrayToString(rowKeyRanges.get(0).getUpperRange()));
+        assertEquals(false, rowKeyRanges.get(1).isSingleKey());
+        assertEquals(keyString2, ByteArrayToString(rowKeyRanges.get(1).getLowerRange()));
+        assertEquals(handleScanNextKey(keyString2), ByteArrayToString(rowKeyRanges.get(1).getUpperRange()));
+    }
+
+    @Test
+    public void getRowKeyRangesTestValuesAndRangesLookUp() {
+        int rowKeySchemaFields = 2;
+        RowKeySchema schema = buildSimpleRowKeySchema(rowKeySchemaFields);
+        int[] slotSpan = new int[rowKeySchemaFields];
+
+        String point1 = "A";
+        String point2 = "B";
+
+        String lowerString2 = "C";
+        String upperString2 = "D";
+
+        KeyRange pointKeyRange1 = KeyRange.getKeyRange(stringToByteArray(point1));
+        KeyRange pointKeyRange2 = KeyRange.getKeyRange(stringToByteArray(point2));
+
+        KeyRange rangeKeyRange = KeyRange.getKeyRange(stringToByteArray(lowerString2), true,
+                stringToByteArray(upperString2), true);
+
+        List<List<KeyRange>> ranges = new ArrayList<>();
+        ranges.add(Lists.newArrayList(pointKeyRange1, pointKeyRange2));
+        ranges.add(Lists.newArrayList(rangeKeyRange));
+
+        ScanRanges scanRanges = ScanRanges.create(schema, ranges, slotSpan, null, true, -1);
+
+        List<KeyRange> rowKeyRanges = scanRanges.getRowKeyRanges();
+        assertEquals(2, rowKeyRanges.size());
+        assertEquals(false, rowKeyRanges.get(0).isSingleKey());
+        assertEquals(point1 + lowerString2, ByteArrayToString(rowKeyRanges.get(0).getLowerRange()));
+        assertEquals(handleScanNextKey(point1 + upperString2), ByteArrayToString(rowKeyRanges.get(0).getUpperRange()));
+
+        assertEquals(false, rowKeyRanges.get(1).isSingleKey());
+        assertEquals(point2 + lowerString2, ByteArrayToString(rowKeyRanges.get(1).getLowerRange()));
+        assertEquals(handleScanNextKey(point2 + upperString2), ByteArrayToString(rowKeyRanges.get(1).getUpperRange()));
+    }
+
+
+    @Test
+    public void getRowKeyRangesSorted() {
+        int rowKeySchemaFields = 2;
+        RowKeySchema schema = buildSimpleRowKeySchema(rowKeySchemaFields);
+        int[] slotSpan = new int[rowKeySchemaFields];
+
+        String k1a = "A";
+        String k1b = "B";
+        String k1c = "C";
+
+        String k2x = "X";
+        String k2y = "Y";
+        String k2z = "Z";
+
+        KeyRange pointKey1Range1 = KeyRange.getKeyRange(stringToByteArray(k1a));
+        KeyRange pointKey1Range2 = KeyRange.getKeyRange(stringToByteArray(k1b));
+        KeyRange pointKey1Range3 = KeyRange.getKeyRange(stringToByteArray(k1c));
+        KeyRange pointKey2Range1 = KeyRange.getKeyRange(stringToByteArray(k2x));
+        KeyRange pointKey2Range2 = KeyRange.getKeyRange(stringToByteArray(k2y));
+        KeyRange pointKey2Range3 = KeyRange.getKeyRange(stringToByteArray(k2z));
+
+        List<List<KeyRange>> ranges = new ArrayList<>();
+        ranges.add(Lists.newArrayList(pointKey1Range1, pointKey1Range2, pointKey1Range3));
+        ranges.add(Lists.newArrayList(pointKey2Range1,pointKey2Range2,pointKey2Range3));
+
+        ScanRanges scanRanges = ScanRanges.create(schema, ranges, slotSpan, null, true, -1);
+
+        List<KeyRange> rowKeyRanges = scanRanges.getRowKeyRanges();
+        assertEquals(9, rowKeyRanges.size());
+        assertEquals(singleKeyToScanRange("AX"), rowKeyRanges.get(0).toString());
+        assertEquals(singleKeyToScanRange("AY"), rowKeyRanges.get(1).toString());
+        assertEquals(singleKeyToScanRange("AZ"), rowKeyRanges.get(2).toString());
+
+        assertEquals(singleKeyToScanRange("BX"), rowKeyRanges.get(3).toString());
+        assertEquals(singleKeyToScanRange("BY"), rowKeyRanges.get(4).toString());
+        assertEquals(singleKeyToScanRange("BZ"), rowKeyRanges.get(5).toString());
+
+        assertEquals(singleKeyToScanRange("CX"), rowKeyRanges.get(6).toString());
+        assertEquals(singleKeyToScanRange("CY"), rowKeyRanges.get(7).toString());
+        assertEquals(singleKeyToScanRange("CZ"), rowKeyRanges.get(8).toString());
+
+    }
+
+    @Test
+    public void getRowKeyRangesAdjacentSubRanges() {
+        int rowKeySchemaFields = 2;
+        RowKeySchema schema = buildSimpleRowKeySchema(rowKeySchemaFields);
+        int[] slotSpan = new int[rowKeySchemaFields];
+
+        List<KeyRange> keyRanges = new ArrayList<>();
+        keyRanges.add(KeyRange.getKeyRange(stringToByteArray("A"), true,
+                stringToByteArray("C"), false));
+        keyRanges.add(KeyRange.getKeyRange(stringToByteArray("C"), true,
+                stringToByteArray("E"), false));
+        keyRanges.add(KeyRange.getKeyRange(stringToByteArray("E"), true,
+                stringToByteArray("G"), false));
+        keyRanges.add(KeyRange.getKeyRange(stringToByteArray("G"), true,
+                stringToByteArray("I"), false));
+
+        List<List<KeyRange>> ranges = new ArrayList<>();
+        ranges.add(keyRanges);
+
+        ScanRanges scanRanges = ScanRanges.create(schema, ranges, slotSpan, null, true, -1);
+
+        List<KeyRange> rowKeyRanges = scanRanges.getRowKeyRanges();
+        assertEquals(4, rowKeyRanges.size());
+        assertEquals("[A - C)", rowKeyRanges.get(0).toString());
+        assertEquals("[C - E)", rowKeyRanges.get(1).toString());
+        assertEquals("[E - G)", rowKeyRanges.get(2).toString());
+        assertEquals("[G - I)", rowKeyRanges.get(3).toString());
+    }
+
+    @Test
+    public void getRowKeyRangesAdjacentSubRangesUpperInclusive() {
+        int rowKeySchemaFields = 1;
+        RowKeySchema schema = buildSimpleRowKeySchema(rowKeySchemaFields);
+
+        int[] slotSpan = new int[rowKeySchemaFields];
+
+        List<KeyRange> keyRanges = new ArrayList<>();
+        keyRanges.add(KeyRange.getKeyRange(stringToByteArray("A"), false,
+                stringToByteArray("C"), true));
+        keyRanges.add(KeyRange.getKeyRange(stringToByteArray("C"), false,
+                stringToByteArray("E"), true));
+        keyRanges.add(KeyRange.getKeyRange(stringToByteArray("E"), false,
+                stringToByteArray("G"), true));
+        keyRanges.add(KeyRange.getKeyRange(stringToByteArray("G"), false,
+                stringToByteArray("I"), true));
+
+        List<List<KeyRange>> ranges = new ArrayList<>();
+        ranges.add(keyRanges);
+
+        ScanRanges scanRanges = ScanRanges.create(schema, ranges, slotSpan, null, true, -1);
+
+        List<KeyRange> rowKeyRanges = scanRanges.getRowKeyRanges();
+        assertEquals(4, rowKeyRanges.size());
+        assertEquals("[B - D)", rowKeyRanges.get(0).toString());
+        assertEquals("[D - F)", rowKeyRanges.get(1).toString());
+        assertEquals("[F - H)", rowKeyRanges.get(2).toString());
+        assertEquals("[H - J)", rowKeyRanges.get(3).toString());
+    }
+
+    /*
+     * range/single    boundary       bound      increment
+     *  range          inclusive      lower         no
+     *  range          inclusive      upper         yes, at the end if occurs at any slots.
+     *  range          exclusive      lower         yes
+     *  range          exclusive      upper         no
+     *  single         inclusive      lower         no
+     *  single         inclusive      upper         yes, at the end if it is the last slots.
+     */
+
+    @Test
+    public void getRangeKeyExclustiveLowerIncrementedUpperNotIncremented() {
 
 Review comment:
   nit:getRangeKeyExclusiveLowerIncrementedUpperNotIncremented

----------------------------------------------------------------
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