HBaseUtils { public static Scan mergeRangeScans(List<Scan> rangeScans) { List<RowRange> ranges = Lists.newArrayList(); for (Scan rangeScan : rangeScans) { byte[] startRow = rangeScan.getStartRow(); byte[] stopRow = rangeScan.getStopRow(); ranges.add(new RowRange(startRow, true, stopRow, false)); } Scan mergedScan = new Scan(); try { mergedScan.setFilter(new MultiRowRangeFilter(ranges)); } catch (IOException e) { throw new RuntimeException(e); } return mergedScan; }  synchronized static Connection getConnection(Config config); static Configuration getHBaseConfiguration(Config config); static int batchSizeFor(Config config); static TableName tableInfoFor(Config config); static HBaseSerde getSerde(Config config); static byte[] rowKeySeparatorFor(Config config); static List<String> rowKeyFor(Config config); static Map<String, HBaseSerde.ColumnDef> columnsFor(Config config); static StructType buildSchema(Map<String, HBaseSerde.ColumnDef> columnDefinitions); static Scan mergeRangeScans(List<Scan> rangeScans); static byte[] exclusiveStopRow(byte[] startRow); static Validations getValidations(); static final String ZK_QUORUM_PROPERTY; static final String TABLE_NAME_PROPERTY; static final String ROWKEY_PROPERTY; static final String KEY_SEPARATOR; static final String COLUMNS_PROPERTY; static final String SERDE_PROPERTY; static final String HBASE_PASSTHRU_PREFIX; static final String HBASE_BATCH_SIZE; static final int DEFAULT_HBASE_BATCH_SIZE; static final String DEFAULT_SERDE_PROPERTY; static final String DEFAULT_KEY_SEPARATOR; }
@Test public void testMergePrefixScans() throws IOException { List<Scan> scans = Lists.newArrayList(); byte[] startRow1 = Bytes.toBytes("hello"); byte[] stopRow1 = Bytes.toBytes("hellp"); Scan scan1 = new Scan(startRow1, stopRow1); scans.add(scan1); byte[] startRow2 = Bytes.toBytes("world"); byte[] stopRow2 = Bytes.toBytes("worle"); Scan scan2 = new Scan(startRow2, stopRow2); scans.add(scan2); Scan merged = HBaseUtils.mergeRangeScans(scans); assertEquals(MultiRowRangeFilter.class, merged.getFilter().getClass()); MultiRowRangeFilter mergedFilter = (MultiRowRangeFilter)merged.getFilter(); List<RowRange> ranges = mergedFilter.getRowRanges(); assertEquals(2, ranges.size()); assertTrue(ranges.get(0).getStartRow().equals(startRow1)); assertTrue(ranges.get(0).getStopRow().equals(stopRow1)); assertTrue(ranges.get(1).getStartRow().equals(startRow2)); assertTrue(ranges.get(1).getStopRow().equals(stopRow2)); }