DecimalStringSplit implements org.apache.hadoop.hbase.util.RegionSplitter.SplitAlgorithm { @Override public byte[] split(byte[] start, byte[] end) { throw new IllegalStateException("Not implemented yet"); } DecimalStringSplit(int cardinality); @Override byte[] split(byte[] start, byte[] end); @Override byte[][] split(int numRegions); @Override byte[] firstRow(); @Override byte[] lastRow(); @Override void setFirstRow(String userInput); @Override void setLastRow(String userInput); @Override byte[] strToRow(String input); @Override String rowToStr(byte[] row); @Override String separator(); void setFirstRow(byte[] userInput); void setLastRow(byte[] userInput);  }
@Test public void testSplit10_10() throws Exception { int numRegions = 10; int cardinality = 10; RegionSplitter.SplitAlgorithm splitAlgorithm = new DecimalStringSplit(cardinality); byte[][] splits = splitAlgorithm.split(numRegions); assertEquals(numRegions - 1, splits.length); int digits = 2; assertEquals(String.format("%0" + digits + "d", 1), Bytes.toString(splits[0])); assertEquals(String.format("%0" + digits + "d", 9), Bytes.toString(splits[numRegions - 2])); }
@Test public void testSplit3_10() throws Exception { int numRegions = 3; int cardinality = 10; RegionSplitter.SplitAlgorithm splitAlgorithm = new DecimalStringSplit(cardinality); byte[][] splits = splitAlgorithm.split(numRegions); assertEquals(numRegions - 1, splits.length); int digits = 2; assertEquals(String.format("%0" + digits + "d", 3), Bytes.toString(splits[0])); assertEquals(String.format("%0" + digits + "d", 6), Bytes.toString(splits[numRegions - 2])); }
@Test public void testSplit300_1000() throws Exception { int numRegions = 300; int cardinality = 1000; RegionSplitter.SplitAlgorithm splitAlgorithm = new DecimalStringSplit(cardinality); byte[][] splits = splitAlgorithm.split(numRegions); assertEquals(numRegions - 1, splits.length); int digits = 4; assertEquals(String.format("%0" + digits + "d", 3), Bytes.toString(splits[0])); assertEquals(String.format("%0" + digits + "d", 6), Bytes.toString(splits[1])); assertEquals(String.format("%0" + digits + "d", 10), Bytes.toString(splits[2])); assertEquals(String.format("%0" + digits + "d", 996), Bytes.toString(splits[numRegions - 2])); }