protected static Scan createSmallResultSizeScan() { return new Scan().setMaxResultSize(1); }
private Scan setDefaultScanConfig(Scan scan) { // always create a new scan object as we may reset the start row later. Scan newScan = ReflectionUtils.newInstance(scan.getClass(), scan); if (newScan.getCaching() <= 0) { newScan.setCaching(defaultScannerCaching); } if (newScan.getMaxResultSize() <= 0) { newScan.setMaxResultSize(defaultScannerMaxResultSize); } return newScan; }
@Override public Void call() throws Exception { // Configure the scan so that it can read the entire table in a single RPC. We want to test // the case where a scan stops on the server side due to a time limit Scan scan = new Scan(); scan.setMaxResultSize(Long.MAX_VALUE); scan.setCaching(Integer.MAX_VALUE); testEquivalenceOfScanWithHeartbeats(scan, DEFAULT_ROW_SLEEP_TIME, -1, false); return null; } });
/** * Ensure that the results returned from a scanner that retrieves all results in a single RPC call * matches the results that are returned from a scanner that must incrementally combine partial * results into complete results. A variety of scan configurations can be tested * @throws Exception */ @Test public void testEquivalenceOfScanResults() throws Exception { Scan oneShotScan = new Scan(); oneShotScan.setMaxResultSize(Long.MAX_VALUE); Scan partialScan = new Scan(oneShotScan); partialScan.setMaxResultSize(1); testEquivalenceOfScanResults(TABLE, oneShotScan, partialScan); }
protected static Scan createBatchSmallResultSizeScan() { return new Scan().setBatch(1).setMaxResultSize(1); }
@Override public Void call() throws Exception { // Configure the scan so that it can read the entire table in a single RPC. We want to test // the case where a scan stops on the server side due to a time limit Scan baseScan = new Scan(); baseScan.setMaxResultSize(Long.MAX_VALUE); baseScan.setCaching(Integer.MAX_VALUE); // Copy the scan before each test. When a scan object is used by a scanner, some of its // fields may be changed such as start row Scan scanCopy = new Scan(baseScan); testEquivalenceOfScanWithHeartbeats(scanCopy, -1, DEFAULT_CF_SLEEP_TIME, false); scanCopy = new Scan(baseScan); testEquivalenceOfScanWithHeartbeats(scanCopy, -1, DEFAULT_CF_SLEEP_TIME, true); return null; } });
private void tuneScanParameters(Scan scan) { scan.setCaching(kylinConfig.getHBaseScanCacheRows()); scan.setMaxResultSize(kylinConfig.getHBaseScanMaxResultSize()); scan.setCacheBlocks(true); }
private Scan createScan() { Scan scan = new Scan(); if (batch) { scan.setBatch(1); } if (smallResultSize) { scan.setMaxResultSize(1); } if (allowPartial) { scan.setAllowPartialResults(true); } return scan; }
protected Scan createScanWithSizeLimit() { return new Scan().setMaxResultSize(1).setCaching(Integer.MAX_VALUE).setNeedCursorResult(true); } }
public void testPartialResultsWithColumnFilter(Filter filter) throws Exception { assertTrue(!filter.hasFilterRow()); Scan partialScan = new Scan(); partialScan.setFilter(filter); Scan oneshotScan = new Scan(); oneshotScan.setFilter(filter); oneshotScan.setMaxResultSize(Long.MAX_VALUE); for (int i = 1; i <= NUM_COLS; i++) { partialScan.setMaxResultSize(getResultSizeForNumberOfCells(i)); testEquivalenceOfScanResults(TABLE, partialScan, oneshotScan); } }
/** * Tries to scan a row from passed region */ private void isSuccessfulScan(RegionInfo region) throws IOException { Scan scan = new Scan().withStartRow(region.getStartKey()).setRaw(true).setOneRowLimit() .setMaxResultSize(1L).setCaching(1).setFilter(new FirstKeyOnlyFilter()) .setCacheBlocks(false); try (Table table = conn.getTable(region.getTable()); ResultScanner scanner = table.getScanner(scan)) { scanner.next(); } catch (IOException e) { LOG.error("Could not scan region:" + region.getEncodedName(), e); throw e; } }
protected Scan createScanWithSparseFilter() { return new Scan().setMaxResultSize(Long.MAX_VALUE).setCaching(Integer.MAX_VALUE) .setNeedCursorResult(true).setAllowPartialResults(true).setFilter(new SparseFilter(false)); }
/** * Order of cells in partial results matches the ordering of cells from complete results * @throws Exception */ @Test public void testOrderingOfCellsInPartialResults() throws Exception { Scan scan = new Scan(); for (int col = 1; col <= NUM_COLS; col++) { scan.setMaxResultSize(getResultSizeForNumberOfCells(col)); testOrderingOfCellsInPartialResults(scan); // Test again with a reversed scanner scan.setReversed(true); testOrderingOfCellsInPartialResults(scan); } }
protected Scan createReversedScanWithSparseFilter() { return new Scan().setMaxResultSize(Long.MAX_VALUE).setCaching(Integer.MAX_VALUE) .setReversed(true).setNeedCursorResult(true).setAllowPartialResults(true) .setFilter(new SparseFilter(true)); }
@Test public void testCompleteResult() throws InterruptedException, ExecutionException { int limit = 5; Scan scan = new Scan().setFilter(new ColumnCountOnRowFilter(2)).setMaxResultSize(1).setLimit(limit); List<Result> results = TABLE.scanAll(scan).get(); assertEquals(limit, results.size()); IntStream.range(0, limit).forEach(i -> { Result result = results.get(i); assertEquals(i, Bytes.toInt(result.getRow())); assertEquals(2, result.size()); assertFalse(result.mayHaveMoreCellsInRow()); assertEquals(i, Bytes.toInt(result.getValue(FAMILY, CQS[0]))); assertEquals(2 * i, Bytes.toInt(result.getValue(FAMILY, CQS[1]))); }); }
@Test public void testAllowPartial() throws InterruptedException, ExecutionException { int limit = 5; Scan scan = new Scan().setFilter(new ColumnCountOnRowFilter(2)).setMaxResultSize(1) .setAllowPartialResults(true).setLimit(limit); List<Result> results = TABLE.scanAll(scan).get(); assertEquals(2 * limit, results.size()); IntStream.range(0, 2 * limit).forEach(i -> { int key = i / 2; Result result = results.get(i); assertEquals(key, Bytes.toInt(result.getRow())); assertEquals(1, result.size()); assertTrue(result.mayHaveMoreCellsInRow()); int cqIndex = i % 2; assertEquals(key * (cqIndex + 1), Bytes.toInt(result.getValue(FAMILY, CQS[cqIndex]))); }); }
@Test public void testBatchAllowPartial() throws InterruptedException, ExecutionException { int limit = 5; Scan scan = new Scan().setFilter(new ColumnCountOnRowFilter(3)).setBatch(2).setMaxResultSize(1) .setAllowPartialResults(true).setLimit(limit); List<Result> results = TABLE.scanAll(scan).get(); assertEquals(3 * limit, results.size()); IntStream.range(0, 3 * limit).forEach(i -> { int key = i / 3; Result result = results.get(i); assertEquals(key, Bytes.toInt(result.getRow())); assertEquals(1, result.size()); assertTrue(result.mayHaveMoreCellsInRow()); int cqIndex = i % 3; assertEquals(key * (cqIndex + 1), Bytes.toInt(result.getValue(FAMILY, CQS[cqIndex]))); }); }
@Test public void testBatch() throws InterruptedException, ExecutionException { int limit = 5; Scan scan = new Scan().setFilter(new ColumnCountOnRowFilter(2)).setBatch(2).setMaxResultSize(1) .setLimit(limit); List<Result> results = TABLE.scanAll(scan).get(); assertEquals(limit, results.size()); IntStream.range(0, limit).forEach(i -> { Result result = results.get(i); assertEquals(i, Bytes.toInt(result.getRow())); assertEquals(2, result.size()); assertTrue(result.mayHaveMoreCellsInRow()); assertEquals(i, Bytes.toInt(result.getValue(FAMILY, CQS[0]))); assertEquals(2 * i, Bytes.toInt(result.getValue(FAMILY, CQS[1]))); }); }
@Override public Void call() throws Exception { Scan scan = new Scan(); scan.setMaxResultSize(Long.MAX_VALUE); scan.setCaching(Integer.MAX_VALUE); scan.setFilter(new SparseRowFilter()); ResultScanner scanner = TABLE.getScanner(scan); int num = 0; while (scanner.next() != null) { num++; } assertEquals(1, num); scanner.close(); return null; } });
@Test public void testCompleteResult() throws IOException { int limit = 5; Scan scan = new Scan().setFilter(new ColumnCountOnRowFilter(2)).setMaxResultSize(1).setLimit(limit); try (Table table = UTIL.getConnection().getTable(TABLE_NAME); ResultScanner scanner = table.getScanner(scan)) { for (int i = 0; i < limit; i++) { Result result = scanner.next(); assertEquals(i, Bytes.toInt(result.getRow())); assertEquals(2, result.size()); assertFalse(result.mayHaveMoreCellsInRow()); assertEquals(i, Bytes.toInt(result.getValue(FAMILY, CQS[0]))); assertEquals(2 * i, Bytes.toInt(result.getValue(FAMILY, CQS[1]))); } assertNull(scanner.next()); } }