UniformRangePartition extends RangePartitionAlgorithm { @Override public TupleRange[] partition(int partNum) { Preconditions.checkArgument(partNum > 0, "The number of partitions must be positive, but the given number: " + partNum); Preconditions.checkArgument(totalCard.compareTo(BigInteger.valueOf(partNum)) >= 0, "the number of partition cannot exceed total cardinality (" + totalCard + ")"); int varId; for (varId = 0; varId < cardForEachDigit.length; varId++) { if (cardForEachDigit[varId].compareTo(BigInteger.valueOf(partNum)) >= 0) break; } this.variableId = varId; BigInteger [] reverseCardsForDigit = new BigInteger[variableId+1]; for (int i = variableId; i >= 0; i--) { if (i == variableId) { reverseCardsForDigit[i] = colCards[i]; } else { reverseCardsForDigit[i] = reverseCardsForDigit[i+1].multiply(colCards[i]); } } List<TupleRange> ranges = Lists.newArrayList(); BigDecimal x = new BigDecimal(reverseCardsForDigit[0]); BigInteger term = x.divide(BigDecimal.valueOf(partNum), RoundingMode.CEILING).toBigInteger(); BigInteger reminder = reverseCardsForDigit[0]; Tuple last = mergedRange.getStart(); TupleRange tupleRange; while(reminder.compareTo(BigInteger.ZERO) > 0) { if (reminder.compareTo(term) <= 0) { tupleRange = new TupleRange(sortSpecs, last, mergedRange.getEnd()); } else { Tuple next = increment(last, term, variableId); tupleRange = new TupleRange(sortSpecs, last, next); } ranges.add(tupleRange); last = ranges.get(ranges.size() - 1).getEnd(); reminder = reminder.subtract(term); } ranges.get(0).setStart(originalRange.getStart()); ranges.get(ranges.size() - 1).setEnd(originalRange.getEnd()); for (int i = 0; i < ranges.size(); i++) { if (i > 1) { Preconditions.checkState(ranges.get(i - 2).compareTo(ranges.get(i - 1)) < 0, "Computed ranges are not totally ordered. Previous key=" + ranges.get(i - 2) + ", Current Key=" + ranges.get(i - 1)); } } return ranges.toArray(new TupleRange[ranges.size()]); } UniformRangePartition(final TupleRange entireRange, final SortSpec[] sortSpecs, boolean inclusive);  UniformRangePartition(TupleRange range, SortSpec [] sortSpecs); @Override TupleRange[] partition(int partNum); void normalize(final SortSpec [] sortSpecs, TupleRange range); boolean isOverflow(int colId, Datum last, BigInteger inc, SortSpec [] sortSpecs); long incrementAndGetReminder(int colId, Datum last, long inc); Tuple increment(final Tuple last, BigInteger interval, final int baseDigit); static BigInteger charsToBigInteger(char [] chars);  }
@Test public void testPartitionForINT2Asc() { Schema schema = new Schema() .addColumn("col1", Type.INT2); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createInt2((short) 1)); e.put(0, DatumFactory.createInt2((short) 30000)); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForINT2Desc() { Schema schema = new Schema() .addColumn("col1", Type.INT2); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createInt2((short) 30000)); e.put(0, DatumFactory.createInt2((short) 1)); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForINT4Asc() { Schema schema = new Schema() .addColumn("col1", Type.INT4); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createInt4(1)); e.put(0, DatumFactory.createInt4(10000)); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForINT4Desc() { Schema schema = new Schema() .addColumn("col1", Type.INT4); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createInt4(10000)); e.put(0, DatumFactory.createInt4(1)); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForINT8Asc() { Schema schema = new Schema() .addColumn("col1", Type.INT8); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createInt8(1)); e.put(0, DatumFactory.createInt8(10000)); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForInt8Desc() { Schema schema = new Schema() .addColumn("col1", Type.INT8); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createInt8(10000)); e.put(0, DatumFactory.createInt8(1)); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForFloat4Asc() { Schema schema = new Schema() .addColumn("col1", Type.FLOAT4); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createFloat4((float) 1.0)); e.put(0, DatumFactory.createFloat4((float) 10000.0)); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForFloat4Desc() { Schema schema = new Schema() .addColumn("col1", Type.FLOAT4); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createFloat4((float) 10000.0)); e.put(0, DatumFactory.createFloat4((float) 1.0)); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForFloat8Asc() { Schema schema = new Schema() .addColumn("col1", Type.FLOAT8); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createFloat8(1.0)); e.put(0, DatumFactory.createFloat8(10000.0)); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForFloat8Desc() { Schema schema = new Schema() .addColumn("col1", Type.FLOAT8); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createFloat8((float) 10000.0)); e.put(0, DatumFactory.createFloat8((float) 1.0)); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testIncrementOfUnicodeOneCharSinglePartition() { Schema schema = new Schema() .addColumn("col1", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); s.put(0, DatumFactory.createText("가")); Tuple e = new VTuple(1); e.put(0, DatumFactory.createText("다")); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 1; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testIncrementOfUnicodeOneCharMultiPartition() { Schema schema = new Schema() .addColumn("col1", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); s.put(0, DatumFactory.createText("가")); Tuple e = new VTuple(1); e.put(0, DatumFactory.createText("꽥")); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 8; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForUnicodeTextAsc() { Schema schema = new Schema() .addColumn("col1", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createText("가가가")); e.put(0, DatumFactory.createText("하하하")); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForUnicodeDiffLenBeginTextAsc() { Schema schema = new Schema() .addColumn("col1", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createText("가")); e.put(0, DatumFactory.createText("하하하")); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForUnicodeDiffLenEndTextAsc() { Schema schema = new Schema() .addColumn("col1", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createText("가가가")); e.put(0, DatumFactory.createText("하")); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForUnicodeTextDesc() { Schema schema = new Schema() .addColumn("col1", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createText("하하하")); e.put(0, DatumFactory.createText("가가가")); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForUnicodeDiffLenBeginTextDesc() { Schema schema = new Schema() .addColumn("col1", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createText("하")); e.put(0, DatumFactory.createText("가가가")); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForUnicodeDiffLenEndTextDesc() { Schema schema = new Schema() .addColumn("col1", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); Tuple s = new VTuple(1); Tuple e = new VTuple(1); s.put(0, DatumFactory.createText("하")); e.put(0, DatumFactory.createText("가가가")); TupleRange expected = new TupleRange(sortSpecs, s, e); UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs); int partNum = 64; TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartition() { Schema schema = new Schema(); schema.addColumn("l_returnflag", Type.TEXT); schema.addColumn("l_linestatus", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(2); s.put(0, DatumFactory.createText("A")); s.put(1, DatumFactory.createText("F")); Tuple e = new VTuple(2); e.put(0, DatumFactory.createText("R")); e.put(1, DatumFactory.createText("O")); TupleRange expected = new TupleRange(sortSpecs, s, e); RangePartitionAlgorithm partitioner = new UniformRangePartition(expected, sortSpecs, true); TupleRange [] ranges = partitioner.partition(31); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } }
@Test public void testPartitionForOnePartNum() { Schema schema = new Schema() .addColumn("l_returnflag", Type.TEXT) .addColumn("l_linestatus", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(2); s.put(0, DatumFactory.createText("A")); s.put(1, DatumFactory.createText("F")); Tuple e = new VTuple(2); e.put(0, DatumFactory.createText("R")); e.put(1, DatumFactory.createText("O")); TupleRange expected = new TupleRange(sortSpecs, s, e); RangePartitionAlgorithm partitioner = new UniformRangePartition(expected, sortSpecs, true); TupleRange [] ranges = partitioner.partition(1); assertEquals(expected, ranges[0]); }
@Test public void testPartitionForOnePartNumWithOneOfTheValueNull() { Schema schema = new Schema() .addColumn("l_returnflag", Type.TEXT) .addColumn("l_linestatus", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(2); s.put(0, DatumFactory.createNullDatum()); s.put(1, DatumFactory.createText("F")); Tuple e = new VTuple(2); e.put(0, DatumFactory.createText("R")); e.put(1, DatumFactory.createNullDatum()); TupleRange expected = new TupleRange(sortSpecs, s, e); RangePartitionAlgorithm partitioner = new UniformRangePartition(expected, sortSpecs, true); TupleRange [] ranges = partitioner.partition(1); assertEquals(expected, ranges[0]); }
@Test public void testPartitionForMultipleChars() { Schema schema = new Schema() .addColumn("KEY1", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); s.put(0, DatumFactory.createText("AAA")); Tuple e = new VTuple(1); e.put(0, DatumFactory.createText("ZZZ")); TupleRange expected = new TupleRange(sortSpecs, s, e); RangePartitionAlgorithm partitioner = new UniformRangePartition(expected, sortSpecs, true); TupleRange [] ranges = partitioner.partition(48); TupleRange prev = null; for (int i = 0; i < ranges.length; i++) { if (prev != null) { assertTrue(i + "th, prev=" + prev + ",cur=" + ranges[i], prev.compareTo(ranges[i]) < 0); } prev = ranges[i]; } assertEquals(48, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[47].getEnd().equals(e)); }
@Test public void testPartitionForMultipleChars2() { Schema schema = new Schema() .addColumn("KEY1", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); s.put(0, DatumFactory.createText("A1")); Tuple e = new VTuple(1); e.put(0, DatumFactory.createText("A999975")); final int partNum = 2; TupleRange expected = new TupleRange(sortSpecs, s, e); RangePartitionAlgorithm partitioner = new UniformRangePartition(expected, sortSpecs, true); TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForMultipleChars2Desc() { Schema schema = new Schema() .addColumn("KEY1", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); Tuple s = new VTuple(1); s.put(0, DatumFactory.createText("A999975")); Tuple e = new VTuple(1); e.put(0, DatumFactory.createText("A1")); final int partNum = 48; TupleRange expected = new TupleRange(sortSpecs, s, e); RangePartitionAlgorithm partitioner = new UniformRangePartition(expected, sortSpecs, true); TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForMultipleCharsWithSameFirstChar() { Schema schema = new Schema() .addColumn("KEY1", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(1); s.put(0, DatumFactory.createText("AAA")); Tuple e = new VTuple(1); e.put(0, DatumFactory.createText("AAZ")); final int partNum = 4; TupleRange expected = new TupleRange(sortSpecs, s, e); RangePartitionAlgorithm partitioner = new UniformRangePartition(expected, sortSpecs, true); TupleRange [] ranges = partitioner.partition(partNum); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } assertEquals(partNum, ranges.length); assertTrue(ranges[0].getStart().equals(s)); assertTrue(ranges[partNum - 1].getEnd().equals(e)); }
@Test public void testPartitionForOnePartNumWithBothValueNull() { Schema schema = new Schema() .addColumn("l_returnflag", Type.TEXT) .addColumn("l_linestatus", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(2); s.put(0, DatumFactory.createNullDatum()); s.put(1, DatumFactory.createNullDatum()); Tuple e = new VTuple(2); e.put(0, DatumFactory.createNullDatum()); e.put(1, DatumFactory.createNullDatum()); TupleRange expected = new TupleRange(sortSpecs, s, e); RangePartitionAlgorithm partitioner = new UniformRangePartition(expected, sortSpecs, true); TupleRange [] ranges = partitioner.partition(1); assertEquals(expected, ranges[0]); }
@Test public void testPartitionWithNull() { Schema schema = new Schema(); schema.addColumn("l_returnflag", Type.TEXT); schema.addColumn("l_linestatus", Type.TEXT); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(2); s.put(0, DatumFactory.createNullDatum()); s.put(1, DatumFactory.createText("F")); Tuple e = new VTuple(2); e.put(0, DatumFactory.createNullDatum()); e.put(1, DatumFactory.createText("O")); TupleRange expected = new TupleRange(sortSpecs, s, e); RangePartitionAlgorithm partitioner = new UniformRangePartition(expected, sortSpecs, true); TupleRange [] ranges = partitioner.partition(10); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } }
@Test public void testPartitionWithINET4() { Schema schema = new Schema(); schema.addColumn("l_returnflag", Type.INET4); schema.addColumn("l_linestatus", Type.INET4); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); Tuple s = new VTuple(2); s.put(0, DatumFactory.createInet4("127.0.1.10")); s.put(1, DatumFactory.createInet4("127.0.2.10")); Tuple e = new VTuple(2); e.put(0, DatumFactory.createInet4("127.0.1.20")); e.put(1, DatumFactory.createInet4("127.0.2.20")); TupleRange expected = new TupleRange(sortSpecs, s, e); RangePartitionAlgorithm partitioner = new UniformRangePartition(expected, sortSpecs, true); TupleRange [] ranges = partitioner.partition(10); TupleRange prev = null; for (TupleRange r : ranges) { if (prev != null) { assertTrue(prev.compareTo(r) < 0); } prev = r; } }