@Test public void testPartitionForINT4Desc() { Schema schema = SchemaBuilder.builder().add("col1", Type.INT4).build(); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); VTuple s = new VTuple(1); VTuple 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 testPartitionForUnicodeDiffLenBeginTextDesc() { Schema schema = SchemaBuilder.builder().add("col1", Type.TEXT).build(); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); VTuple s = new VTuple(1); VTuple 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 = SchemaBuilder.builder() .add("col1", Type.TEXT) .build(); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); VTuple s = new VTuple(1); VTuple 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 testPartitionForFloat4Desc() { Schema schema = SchemaBuilder.builder() .add("col1", Type.FLOAT4) .build(); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); VTuple s = new VTuple(1); VTuple 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 testPartitionForUnicodeTextDesc() { Schema schema = SchemaBuilder.builder().add("col1", Type.TEXT).build(); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); VTuple s = new VTuple(1); VTuple 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 testPartitionForMultipleChars2Desc() { Schema schema = SchemaBuilder.builder() .add("KEY1", Type.TEXT) .build(); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); VTuple s = new VTuple(1); s.put(0, DatumFactory.createText("A999975")); VTuple 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 testPartitionForINT2Desc() { Schema schema = SchemaBuilder.builder() .add("col1", Type.INT2) .build(); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); VTuple s = new VTuple(1); VTuple 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 testPartitionForInt8Desc() { Schema schema = SchemaBuilder.builder() .add("col1", Type.INT8) .build(); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); VTuple s = new VTuple(1); VTuple 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 testPartitionForFloat8Desc() { Schema schema = SchemaBuilder.builder() .add("col1", Type.FLOAT8) .build(); SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema); sortSpecs[0].setDescOrder(); VTuple s = new VTuple(1); VTuple 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)); }