org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange Java Examples
The following examples show how to use
org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange.
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: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testMergeAndSortWithOverlap() throws IOException { List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges.add(new RowRange(Bytes.toBytes(15), true, Bytes.toBytes(40), false)); ranges.add(new RowRange(Bytes.toBytes(20), true, Bytes.toBytes(30), false)); ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(50), false)); ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(70), false)); ranges.add(new RowRange(Bytes.toBytes(90), true, Bytes.toBytes(100), false)); ranges.add(new RowRange(Bytes.toBytes(95), true, Bytes.toBytes(100), false)); List<RowRange> actualRanges = MultiRowRangeFilter.sortAndMerge(ranges); List<RowRange> expectedRanges = new ArrayList<>(); expectedRanges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(70), false)); expectedRanges.add(new RowRange(Bytes.toBytes(90), true, Bytes.toBytes(100), false)); assertRangesEqual(expectedRanges, actualRanges); }
Example #2
Source File: HBaseReader.java From geowave with Apache License 2.0 | 6 votes |
protected Scan getMultiScanner(final FilterList filterList) { // Single scan w/ multiple ranges final Scan multiScanner = scanProvider.get(); final List<ByteArrayRange> ranges = readerParams.getQueryRanges().getCompositeQueryRanges(); final MultiRowRangeFilter filter = operations.getMultiRowRangeFilter(ranges); if (filter != null) { filterList.addFilter(filter); final List<RowRange> rowRanges = filter.getRowRanges(); multiScanner.setStartRow(rowRanges.get(0).getStartRow()); final RowRange stopRowRange = rowRanges.get(rowRanges.size() - 1); byte[] stopRowExclusive; if (stopRowRange.isStopRowInclusive()) { // because the end is always exclusive, to make an inclusive // stop row into exlusive all we need to do is add a traling 0 stopRowExclusive = HBaseUtils.getInclusiveEndKey(stopRowRange.getStopRow()); } else { stopRowExclusive = stopRowRange.getStopRow(); } multiScanner.setStopRow(stopRowExclusive); } return multiScanner; }
Example #3
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testMultiRowRangeFilterWithEmptyStopRow() throws IOException { tableName = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(tableName, family, Integer.MAX_VALUE); generateRows(numRows, ht, family, qf, value); Scan scan = new Scan(); scan.readAllVersions(); List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(""), false)); ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false)); MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges); scan.setFilter(filter); int resultsSize = getResultsSize(ht, scan); List<Cell> results1 = getScanResult(Bytes.toBytes(10), Bytes.toBytes(""), ht); assertEquals(results1.size(), resultsSize); ht.close(); }
Example #4
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testMultiRowRangeFilterWithEmptyStartRow() throws IOException { tableName = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(tableName, family, Integer.MAX_VALUE); generateRows(numRows, ht, family, qf, value); Scan scan = new Scan(); scan.readAllVersions(); List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(""), true, Bytes.toBytes(10), false)); ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false)); MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges); scan.setFilter(filter); int resultsSize = getResultsSize(ht, scan); List<Cell> results1 = getScanResult(Bytes.toBytes(""), Bytes.toBytes(10), ht); List<Cell> results2 = getScanResult(Bytes.toBytes(30), Bytes.toBytes(40), ht); assertEquals(results1.size() + results2.size(), resultsSize); ht.close(); }
Example #5
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testMultiRowRangeFilterWithoutRangeOverlap() throws IOException { tableName = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(tableName, family, Integer.MAX_VALUE); generateRows(numRows, ht, family, qf, value); Scan scan = new Scan(); scan.readAllVersions(); List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false)); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(70), false)); MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges); scan.setFilter(filter); int resultsSize = getResultsSize(ht, scan); LOG.info("found " + resultsSize + " results"); List<Cell> results1 = getScanResult(Bytes.toBytes(10), Bytes.toBytes(20), ht); List<Cell> results2 = getScanResult(Bytes.toBytes(30), Bytes.toBytes(40), ht); List<Cell> results3 = getScanResult(Bytes.toBytes(60), Bytes.toBytes(70), ht); assertEquals(results1.size() + results2.size() + results3.size(), resultsSize); ht.close(); }
Example #6
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testOutOfOrderScannerNextException() throws Exception { MultiRowRangeFilter filter = new MultiRowRangeFilter(Arrays.asList( new MultiRowRangeFilter.RowRange(Bytes.toBytes("b"), true, Bytes.toBytes("c"), true), new MultiRowRangeFilter.RowRange(Bytes.toBytes("d"), true, Bytes.toBytes("e"), true) )); filter.filterRowKey(KeyValueUtil.createFirstOnRow(Bytes.toBytes("a"))); assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterCell(null)); filter.filterRowKey(KeyValueUtil.createFirstOnRow(Bytes.toBytes("b"))); assertEquals(Filter.ReturnCode.INCLUDE, filter.filterCell(null)); filter.filterRowKey(KeyValueUtil.createFirstOnRow(Bytes.toBytes("c"))); assertEquals(Filter.ReturnCode.INCLUDE, filter.filterCell(null)); filter.filterRowKey(KeyValueUtil.createFirstOnRow(Bytes.toBytes("d"))); assertEquals(Filter.ReturnCode.INCLUDE, filter.filterCell(null)); filter.filterRowKey(KeyValueUtil.createFirstOnRow(Bytes.toBytes("e"))); assertEquals(Filter.ReturnCode.INCLUDE, filter.filterCell(null)); }
Example #7
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testRanges() throws IOException { byte[] key1Start = new byte[] {-3}; byte[] key1End = new byte[] {-2}; byte[] key2Start = new byte[] {5}; byte[] key2End = new byte[] {6}; byte[] badKey = new byte[] {-10}; MultiRowRangeFilter filter = new MultiRowRangeFilter(Arrays.asList( new MultiRowRangeFilter.RowRange(key1Start, true, key1End, false), new MultiRowRangeFilter.RowRange(key2Start, true, key2End, false) )); filter.filterRowKey(KeyValueUtil.createFirstOnRow(badKey)); /* * FAILS -- includes BAD key! * Expected :SEEK_NEXT_USING_HINT * Actual :INCLUDE * */ assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterCell(null)); }
Example #8
Source File: TestHBaseUtils.java From envelope with Apache License 2.0 | 6 votes |
@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)); }
Example #9
Source File: ReadData.java From java-docs-samples with Apache License 2.0 | 6 votes |
/** * Get the ranges to scan for the given time index. */ private List<RowRange> getRangesForTimeIndex(@Element Integer timeOffsetIndex, long maxInput) { List<RowRange> ranges = new ArrayList<>(); int numRows = imageData.size(); int numCols = imageData.get(0).size(); int rowHeight = (int) (maxInput / numRows); int columnIndex = timeOffsetIndex % numCols; for (int i = 0; i < imageData.size(); i++) { // To generate shading, only scan each pixel with a probability based on it's weight. if (Math.random() <= imageData.get(i).get(columnIndex)) { // Get the indexes of the rowkeys for the interval. long startKeyI = maxInput - (i + 1) * rowHeight; long endKeyI = startKeyI + rowHeight; String startKey = keys[Math.toIntExact(startKeyI)]; String endKey = keys[Math.toIntExact(endKeyI) - 1]; ranges.add( new RowRange( Bytes.toBytes("" + startKey), true, Bytes.toBytes("" + endKey), true)); } } return ranges; }
Example #10
Source File: HBaseUtils.java From envelope with Apache License 2.0 | 6 votes |
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; }
Example #11
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMultiRowRangeWithFilterListOrOperator() throws IOException { tableName = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(tableName, family, Integer.MAX_VALUE); generateRows(numRows, ht, family, qf, value); Scan scan = new Scan(); scan.readAllVersions(); List<RowRange> ranges1 = new ArrayList<>(); ranges1.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false)); ranges1.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges1.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(70), false)); MultiRowRangeFilter filter1 = new MultiRowRangeFilter(ranges1); List<RowRange> ranges2 = new ArrayList<>(); ranges2.add(new RowRange(Bytes.toBytes(20), true, Bytes.toBytes(40), false)); ranges2.add(new RowRange(Bytes.toBytes(80), true, Bytes.toBytes(90), false)); MultiRowRangeFilter filter2 = new MultiRowRangeFilter(ranges2); FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE); filterList.addFilter(filter1); filterList.addFilter(filter2); scan.setFilter(filterList); int resultsSize = getResultsSize(ht, scan); LOG.info("found " + resultsSize + " results"); List<Cell> results1 = getScanResult(Bytes.toBytes(10), Bytes.toBytes(40), ht); List<Cell> results2 = getScanResult(Bytes.toBytes(60), Bytes.toBytes(70), ht); List<Cell> results3 = getScanResult(Bytes.toBytes(80), Bytes.toBytes(90), ht); assertEquals(results1.size() + results2.size() + results3.size(),resultsSize); ht.close(); }
Example #12
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
public void assertRangesEqual(List<RowRange> expected, List<RowRange> actual) { assertEquals(expected.size(), actual.size()); for(int i = 0; i < expected.size(); i++) { Assert.assertTrue(Bytes.equals(expected.get(i).getStartRow(), actual.get(i).getStartRow())); Assert.assertTrue(expected.get(i).isStartRowInclusive() == actual.get(i).isStartRowInclusive()); Assert.assertTrue(Bytes.equals(expected.get(i).getStopRow(), actual.get(i).getStopRow())); Assert.assertTrue(expected.get(i).isStopRowInclusive() == actual.get(i).isStopRowInclusive()); } }
Example #13
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMultiRowRangeFilterWithRangeOverlap() throws IOException { tableName = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(tableName, family, Integer.MAX_VALUE); generateRows(numRows, ht, family, qf, value); Scan scan = new Scan(); scan.readAllVersions(); List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges.add(new RowRange(Bytes.toBytes(15), true, Bytes.toBytes(40), false)); ranges.add(new RowRange(Bytes.toBytes(65), true, Bytes.toBytes(75), false)); ranges.add(new RowRange(Bytes.toBytes(60), true, null, false)); ranges.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(80), false)); MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges); scan.setFilter(filter); int resultsSize = getResultsSize(ht, scan); LOG.info("found " + resultsSize + " results"); List<Cell> results1 = getScanResult(Bytes.toBytes(10), Bytes.toBytes(40), ht); List<Cell> results2 = getScanResult(Bytes.toBytes(60), Bytes.toBytes(""), ht); assertEquals(results1.size() + results2.size(), resultsSize); ht.close(); }
Example #14
Source File: Reads.java From java-docs-samples with Apache License 2.0 | 5 votes |
public static void readRowRanges(String projectId, String instanceId, String tableId) { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. try (Connection connection = BigtableConfiguration.connect(projectId, instanceId)) { Table table = connection.getTable(TableName.valueOf(tableId)); List<RowRange> ranges = new ArrayList<>(); ranges.add( new RowRange( Bytes.toBytes("phone#4c410523#20190501"), true, Bytes.toBytes("phone#4c410523#20190601"), false)); ranges.add( new RowRange( Bytes.toBytes("phone#5c10102#20190501"), true, Bytes.toBytes("phone#5c10102#20190601"), false)); Filter filter = new MultiRowRangeFilter(ranges); Scan scan = new Scan().setFilter(filter); ResultScanner rows = table.getScanner(scan); for (Result row : rows) { printRow(row); } } catch (IOException e) { System.out.println( "Unable to initialize service client, as a network error occurred: \n" + e.toString()); } }
Example #15
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMultiRowRangeFilterWithInclusive() throws IOException { tableName = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(tableName, family, Integer.MAX_VALUE); generateRows(numRows, ht, family, qf, value); Scan scan = new Scan(); scan.readAllVersions(); List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges.add(new RowRange(Bytes.toBytes(20), true, Bytes.toBytes(40), false)); ranges.add(new RowRange(Bytes.toBytes(65), true, Bytes.toBytes(75), false)); ranges.add(new RowRange(Bytes.toBytes(60), true, null, false)); ranges.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(80), false)); MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges); scan.setFilter(filter); int resultsSize = getResultsSize(ht, scan); LOG.info("found " + resultsSize + " results"); List<Cell> results1 = getScanResult(Bytes.toBytes(10), Bytes.toBytes(40), ht); List<Cell> results2 = getScanResult(Bytes.toBytes(60), Bytes.toBytes(""), ht); assertEquals(results1.size() + results2.size(), resultsSize); ht.close(); }
Example #16
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMultiRowRangeFilterWithExclusive() throws IOException { tableName = TableName.valueOf(name.getMethodName()); TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, 6000000); TEST_UTIL.createTable(tableName, family, Integer.MAX_VALUE); try (Table ht = TEST_UTIL.getConnection().getTableBuilder(tableName, null) .setReadRpcTimeout(600000).setOperationTimeout(6000000).build()) { generateRows(numRows, ht, family, qf, value); Scan scan = new Scan(); scan.readAllVersions(); List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges.add(new RowRange(Bytes.toBytes(20), false, Bytes.toBytes(40), false)); ranges.add(new RowRange(Bytes.toBytes(65), true, Bytes.toBytes(75), false)); MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges); scan.setFilter(filter); int resultsSize = getResultsSize(ht, scan); LOG.info("found " + resultsSize + " results"); List<Cell> results1 = getScanResult(Bytes.toBytes(10), Bytes.toBytes(40), ht); List<Cell> results2 = getScanResult(Bytes.toBytes(65), Bytes.toBytes(75), ht); assertEquals((results1.size() - 1) + results2.size(), resultsSize); } }
Example #17
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMultiRowRangeWithFilterListAndOperator() throws IOException { tableName = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(tableName, family, Integer.MAX_VALUE); generateRows(numRows, ht, family, qf, value); Scan scan = new Scan(); scan.readAllVersions(); List<RowRange> ranges1 = new ArrayList<>(); ranges1.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges1.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false)); ranges1.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(70), false)); MultiRowRangeFilter filter1 = new MultiRowRangeFilter(ranges1); List<RowRange> ranges2 = new ArrayList<>(); ranges2.add(new RowRange(Bytes.toBytes(20), true, Bytes.toBytes(40), false)); ranges2.add(new RowRange(Bytes.toBytes(80), true, Bytes.toBytes(90), false)); MultiRowRangeFilter filter2 = new MultiRowRangeFilter(ranges2); FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); filterList.addFilter(filter1); filterList.addFilter(filter2); scan.setFilter(filterList); int resultsSize = getResultsSize(ht, scan); LOG.info("found " + resultsSize + " results"); List<Cell> results1 = getScanResult(Bytes.toBytes(30), Bytes.toBytes(40), ht); assertEquals(results1.size(), resultsSize); ht.close(); }
Example #18
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testRowKeyPrefixWithEmptyPrefix() throws IOException { byte[] prefix = {}; byte[][] rowKeyPrefixes = new byte[1][]; rowKeyPrefixes[0] = prefix; MultiRowRangeFilter filter = new MultiRowRangeFilter(rowKeyPrefixes); List<RowRange> actualRanges = filter.getRowRanges(); List<RowRange> expectedRanges = new ArrayList<>(); expectedRanges.add( new RowRange(HConstants.EMPTY_START_ROW, true, HConstants.EMPTY_END_ROW, false) ); assertRangesEqual(expectedRanges, actualRanges); }
Example #19
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testReverseMultiRowRangeFilterWithinTable() throws IOException { tableName = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(tableName, family); generateRows(numRows, ht, family, qf, value); Scan scan = new Scan(); scan.setReversed(true); List<RowRange> ranges = Arrays.asList( new RowRange(Bytes.toBytes(20), true, Bytes.toBytes(30), true), new RowRange(Bytes.toBytes(50), true, Bytes.toBytes(60), true) ); MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges); scan.setFilter(filter); List<Integer> expectedResults = new ArrayList<>(); for (int i = 60; i >= 50; i--) { expectedResults.add(i); } for (int i = 30; i >= 20; i--) { expectedResults.add(i); } List<Cell> results = getResults(ht, scan); List<Integer> actualResults = new ArrayList<>(); StringBuilder sb = new StringBuilder(); for (Cell result : results) { int observedValue = Bytes.toInt( result.getRowArray(), result.getRowOffset(), result.getRowLength()); actualResults.add(observedValue); if (sb.length() > 0) { sb.append(", "); } sb.append(observedValue); } assertEquals("Saw results: " + sb.toString(), 22, results.size()); }
Example #20
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testReverseMultiRowRangeFilterIncludingMaxRow() throws IOException { tableName = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(tableName, family); for (String rowkey : Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h")) { byte[] row = Bytes.toBytes(rowkey); Put p = new Put(row); p.addColumn(family, qf, value); ht.put(p); } TEST_UTIL.flush(); Scan scan = new Scan(); scan.setReversed(true); List<RowRange> ranges = Arrays.asList( new RowRange(Bytes.toBytes("b"), true, Bytes.toBytes("c"), true), new RowRange(Bytes.toBytes("f"), true, Bytes.toBytes("h"), true) ); MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges); scan.setFilter(filter); List<String> expected = Arrays.asList("h", "g", "f", "c", "b"); List<String> actual = new ArrayList<>(); for (Cell cell : getResults(ht, scan)) { actual.add(Bytes.toString(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())); } assertEquals(expected, actual); }
Example #21
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testReverseMultiRowRangeFilterIncludingMinRow() throws IOException { tableName = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(tableName, family); for (String rowkey : Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h")) { byte[] row = Bytes.toBytes(rowkey); Put p = new Put(row); p.addColumn(family, qf, value); ht.put(p); } TEST_UTIL.flush(); Scan scan = new Scan(); scan.setReversed(true); List<RowRange> ranges = Arrays.asList( new RowRange(Bytes.toBytes("a"), true, Bytes.toBytes("c"), true), new RowRange(Bytes.toBytes("f"), true, Bytes.toBytes("g"), true) ); MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges); scan.setFilter(filter); List<String> expected = Arrays.asList("g", "f", "c", "b", "a"); List<String> actual = new ArrayList<>(); for (Cell cell : getResults(ht, scan)) { actual.add(Bytes.toString(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())); } assertEquals(expected, actual); }
Example #22
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testReverseMultiRowRangeFilterIncludingMinAndMaxRow() throws IOException { tableName = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(tableName, family); for (String rowkey : Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h")) { byte[] row = Bytes.toBytes(rowkey); Put p = new Put(row); p.addColumn(family, qf, value); ht.put(p); } TEST_UTIL.flush(); Scan scan = new Scan(); scan.setReversed(true); List<RowRange> ranges = Arrays.asList( new RowRange(Bytes.toBytes("a"), true, Bytes.toBytes("c"), true), new RowRange(Bytes.toBytes("f"), true, Bytes.toBytes("h"), true) ); MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges); scan.setFilter(filter); List<String> expected = Arrays.asList("h", "g", "f", "c", "b", "a"); List<String> actual = new ArrayList<>(); for (Cell cell : getResults(ht, scan)) { actual.add(Bytes.toString(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())); } assertEquals(expected, actual); }
Example #23
Source File: TestFilterSerialization.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMultiRowRangeFilter() throws Exception { List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false)); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(70), false)); MultiRowRangeFilter multiRowRangeFilter = new MultiRowRangeFilter(ranges); assertTrue(multiRowRangeFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(multiRowRangeFilter)))); }
Example #24
Source File: HBaseOperations.java From geowave with Apache License 2.0 | 5 votes |
public MultiRowRangeFilter getMultiRowRangeFilter(final List<ByteArrayRange> ranges) { // create the multi-row filter final List<RowRange> rowRanges = new ArrayList<>(); if ((ranges == null) || ranges.isEmpty()) { rowRanges.add( new RowRange(HConstants.EMPTY_BYTE_ARRAY, true, HConstants.EMPTY_BYTE_ARRAY, false)); } else { for (final ByteArrayRange range : ranges) { if (range.getStart() != null) { final byte[] startRow = range.getStart(); byte[] stopRow; if (!range.isSingleValue()) { stopRow = range.getEndAsNextPrefix(); } else { stopRow = ByteArrayUtils.getNextPrefix(range.getStart()); } final RowRange rowRange = new RowRange(startRow, true, stopRow, false); rowRanges.add(rowRange); } } } // Create the multi-range filter try { return new MultiRowRangeFilter(rowRanges); } catch (final IOException e) { LOGGER.error("Error creating range filter.", e); } return null; }
Example #25
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMergeAndSortWithRowInclusive() throws IOException { List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), true)); ranges.add(new RowRange(Bytes.toBytes(20), false, Bytes.toBytes(""), false)); List<RowRange> actualRanges = MultiRowRangeFilter.sortAndMerge(ranges); List<RowRange> expectedRanges = new ArrayList<>(); expectedRanges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(""), false)); assertRangesEqual(expectedRanges, actualRanges); }
Example #26
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMergeAndSortWithRowExclusive() throws IOException { List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges.add(new RowRange(Bytes.toBytes(20), false, Bytes.toBytes(""), false)); List<RowRange> actualRanges = MultiRowRangeFilter.sortAndMerge(ranges); List<RowRange> expectedRanges = new ArrayList<>(); expectedRanges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); expectedRanges.add(new RowRange(Bytes.toBytes(20), false, Bytes.toBytes(""), false)); assertRangesEqual(expectedRanges, actualRanges); }
Example #27
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMergeAndSortWithStartRowInclusive() throws IOException { List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges.add(new RowRange(Bytes.toBytes(20), true, Bytes.toBytes(""), false)); List<RowRange> actualRanges = MultiRowRangeFilter.sortAndMerge(ranges); List<RowRange> expectedRanges = new ArrayList<>(); expectedRanges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(""), false)); assertRangesEqual(expectedRanges, actualRanges); }
Example #28
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMergeAndSortWithoutOverlap() throws IOException { List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false)); ranges.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(70), false)); List<RowRange> actualRanges = MultiRowRangeFilter.sortAndMerge(ranges); List<RowRange> expectedRanges = new ArrayList<>(); expectedRanges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); expectedRanges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false)); expectedRanges.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(70), false)); assertRangesEqual(expectedRanges, actualRanges); }
Example #29
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test(expected=IllegalArgumentException.class) public void testMultiRowRangeWithInvalidRange() throws IOException { List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); // the start row larger than the stop row ranges.add(new RowRange(Bytes.toBytes(80), true, Bytes.toBytes(20), false)); ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(70), false)); new MultiRowRangeFilter(ranges); }
Example #30
Source File: TestMultiRowRangeFilter.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMergeAndSortWithEmptyStartRowAndStopRow() throws IOException { List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges.add(new RowRange(Bytes.toBytes(""), true, Bytes.toBytes(""), false)); ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(70), false)); List<RowRange> actualRanges = MultiRowRangeFilter.sortAndMerge(ranges); List<RowRange> expectedRanges = new ArrayList<>(); expectedRanges.add(new RowRange(Bytes.toBytes(""), true, Bytes.toBytes(""), false)); assertRangesEqual(expectedRanges, actualRanges); }