Java Code Examples for org.apache.hadoop.hbase.util.RegionSplitter#SplitAlgorithm

The following examples show how to use org.apache.hadoop.hbase.util.RegionSplitter#SplitAlgorithm . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DecimalStringSplitTest.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
@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]));
}
 
Example 2
Source File: DecimalStringSplitTest.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
@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]));
}
 
Example 3
Source File: TableSnapshotInputFormatImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static RegionSplitter.SplitAlgorithm getSplitAlgo(Configuration conf) throws IOException {
  String splitAlgoClassName = conf.get(SPLIT_ALGO);
  if (splitAlgoClassName == null) {
    return null;
  }
  try {
    return Class.forName(splitAlgoClassName).asSubclass(RegionSplitter.SplitAlgorithm.class)
        .getDeclaredConstructor().newInstance();
  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
      NoSuchMethodException | InvocationTargetException e) {
    throw new IOException("SplitAlgo class " + splitAlgoClassName + " is not found", e);
  }
}
 
Example 4
Source File: DecimalStringSplitTest.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
@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]));
}
 
Example 5
Source File: DecimalStringSplitTest.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
@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]));
}
 
Example 6
Source File: DecimalStringSplitTest.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
@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]));
}
 
Example 7
Source File: DecimalStringSplitTest.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
@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]));
}
 
Example 8
Source File: DecimalStringSplitTest.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
@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]));
}
 
Example 9
Source File: Split.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@Override
public RegionSplitter.SplitAlgorithm createSplitter(int cardinality) {
    return new RegionSplitter.UniformSplit();
}
 
Example 10
Source File: Split.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@Override
public RegionSplitter.SplitAlgorithm createSplitter(int cardinality) {
    return new DecimalStringSplit(cardinality);
}
 
Example 11
Source File: Split.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@Override
public RegionSplitter.SplitAlgorithm createSplitter(int cardinality) {
    return new RegionSplitter.HexStringSplit();
}
 
Example 12
Source File: Split.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@Override
public RegionSplitter.SplitAlgorithm createSplitter(int cardinality) {
    return new RegionSplitter.HexStringSplit();
}
 
Example 13
Source File: Split.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@Override
public RegionSplitter.SplitAlgorithm createSplitter(int cardinality) {
    return new RegionSplitter.UniformSplit();
}
 
Example 14
Source File: Split.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@Override
public RegionSplitter.SplitAlgorithm createSplitter(int cardinality) {
    return new DecimalStringSplit(cardinality);
}
 
Example 15
Source File: Split.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
public List<byte[]> split(int numRegions, int cardinality) {
    List<byte[]> splitPointList = new ArrayList<>();
    RegionSplitter.SplitAlgorithm splitter = createSplitter(cardinality);
    Collections.addAll(splitPointList, splitter.split(numRegions));
    return splitPointList;
}
 
Example 16
Source File: Split.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@Override
public RegionSplitter.SplitAlgorithm createSplitter(int cardinality) {
    return new RegionSplitter.UniformSplit();
}
 
Example 17
Source File: Split.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@Override
public RegionSplitter.SplitAlgorithm createSplitter(int cardinality) {
    return new RegionSplitter.HexStringSplit();
}
 
Example 18
Source File: TableMapReduceUtil.java    From hbase with Apache License 2.0 3 votes vote down vote up
/**
 * Sets up the job for reading from a table snapshot. It bypasses hbase servers
 * and read directly from snapshot files.
 *
 * @param snapshotName The name of the snapshot (of a table) to read from.
 * @param scan  The scan instance with the columns, time range etc.
 * @param mapper  The mapper class to use.
 * @param outputKeyClass  The class of the output key.
 * @param outputValueClass  The class of the output value.
 * @param job  The current job to adjust.  Make sure the passed job is
 * carrying all necessary HBase configuration.
 * @param addDependencyJars upload HBase jars and jars for any of the configured
 *           job classes via the distributed cache (tmpjars).
 *
 * @param tmpRestoreDir a temporary directory to copy the snapshot files into. Current user should
 * have write permissions to this directory, and this should not be a subdirectory of rootdir.
 * After the job is finished, restore directory can be deleted.
 * @param splitAlgo algorithm to split
 * @param numSplitsPerRegion how many input splits to generate per one region
 * @throws IOException When setting up the details fails.
 * @see TableSnapshotInputFormat
 */
public static void initTableSnapshotMapperJob(String snapshotName, Scan scan,
                                              Class<? extends TableMapper> mapper,
                                              Class<?> outputKeyClass,
                                              Class<?> outputValueClass, Job job,
                                              boolean addDependencyJars, Path tmpRestoreDir,
                                              RegionSplitter.SplitAlgorithm splitAlgo,
                                              int numSplitsPerRegion)
        throws IOException {
  TableSnapshotInputFormat.setInput(job, snapshotName, tmpRestoreDir, splitAlgo,
          numSplitsPerRegion);
  initTableMapperJob(snapshotName, scan, mapper, outputKeyClass,
          outputValueClass, job, addDependencyJars, false, TableSnapshotInputFormat.class);
  resetCacheConfig(job.getConfiguration());
}
 
Example 19
Source File: TableSnapshotInputFormat.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
 * Configures the job to use TableSnapshotInputFormat to read from a snapshot.
 * @param job the job to configure
 * @param snapshotName the name of the snapshot to read from
 * @param restoreDir a temporary directory to restore the snapshot into. Current user should
 * have write permissions to this directory, and this should not be a subdirectory of rootdir.
 * After the job is finished, restoreDir can be deleted.
 * @param splitAlgo split algorithm to generate splits from region
 * @param numSplitsPerRegion how many input splits to generate per one region
 * @throws IOException if an error occurs
 */
public static void setInput(JobConf job, String snapshotName, Path restoreDir,
                            RegionSplitter.SplitAlgorithm splitAlgo, int numSplitsPerRegion) throws IOException {
  TableSnapshotInputFormatImpl.setInput(job, snapshotName, restoreDir, splitAlgo, numSplitsPerRegion);
}
 
Example 20
Source File: TableSnapshotInputFormat.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
* Configures the job to use TableSnapshotInputFormat to read from a snapshot.
* @param job the job to configure
* @param snapshotName the name of the snapshot to read from
* @param restoreDir a temporary directory to restore the snapshot into. Current user should
* have write permissions to this directory, and this should not be a subdirectory of rootdir.
* After the job is finished, restoreDir can be deleted.
* @param splitAlgo split algorithm to generate splits from region
* @param numSplitsPerRegion how many input splits to generate per one region
* @throws IOException if an error occurs
*/
public static void setInput(Job job, String snapshotName, Path restoreDir,
                            RegionSplitter.SplitAlgorithm splitAlgo, int numSplitsPerRegion) throws IOException {
  TableSnapshotInputFormatImpl.setInput(job.getConfiguration(), snapshotName, restoreDir,
          splitAlgo, numSplitsPerRegion);
}