boolean useSkipScan = false; boolean hasRange = false; List<List<KeyRange>> rangesList = dataScanRanges.getRanges(); int rangesListSize = rangesList.size(); while (offset < nColumnsInCommon && offset < rangesListSize) {
boolean isLocalIndex = ScanUtil.isLocalIndex(context.getScan()); boolean forceSkipScan = this.hint.hasHint(Hint.SKIP_SCAN); int nRanges = forceSkipScan ? scanRanges.getRanges().size() : scanRanges.getBoundSlotCount(); for (int i = 0, minPos = 0; minPos < nRanges || minMaxIterator.hasNext(); i++) { List<KeyRange> ranges = minPos >= nRanges ? EVERYTHING : scanRanges.getRanges().get(minPos++); KeyRange range = bound == Bound.LOWER ? ranges.get(0) : ranges.get(ranges.size()-1); byte[] b = range.getRange(bound);
private boolean explainSkipScan(StringBuilder buf) { ScanRanges scanRanges = context.getScanRanges(); if (scanRanges.isPointLookup()) { int keyCount = scanRanges.getPointLookupCount(); buf.append("POINT LOOKUP ON " + keyCount + " KEY" + (keyCount > 1 ? "S " : " ")); } else if (scanRanges.useSkipScanFilter()) { buf.append("SKIP SCAN "); int count = 1; boolean hasRanges = false; int nSlots = scanRanges.getBoundSlotCount(); for (int i = 0; i < nSlots; i++) { List<KeyRange> ranges = scanRanges.getRanges().get(i); count *= ranges.size(); for (KeyRange range : ranges) { hasRanges |= !range.isSingleKey(); } } buf.append("ON "); buf.append(count); buf.append(hasRanges ? " RANGE" : " KEY"); buf.append(count > 1 ? "S " : " "); } else { buf.append("RANGE SCAN "); } return scanRanges.useSkipScanFilter(); }
private static Collection<?> foreach(ScanRanges scanRanges, int[] widths, KeyRange[] expectedSplits) { SkipScanFilter filter = new SkipScanFilter(scanRanges.getRanges(), buildSchema(widths)); Scan scan = new Scan().setFilter(filter).setStartRow(KeyRange.UNBOUND).setStopRow(KeyRange.UNBOUND); List<Object> ret = Lists.newArrayList(); ret.add(new Object[] {scan, scanRanges, Arrays.<KeyRange>asList(expectedSplits)}); return ret; }
assertEquals(3,scanRanges.getRanges().size()); assertEquals(1,scanRanges.getRanges().get(1).size()); assertEquals(KeyRange.EVERYTHING_RANGE,scanRanges.getRanges().get(1).get(0)); assertEquals(1,scanRanges.getRanges().get(2).size()); assertTrue(scanRanges.getRanges().get(2).get(0).isSingleKey()); assertEquals(Long.valueOf(5399179882L), PUnsignedLong.INSTANCE.toObject(scanRanges.getRanges().get(2).get(0).getLowerRange()));
@Test public void testOrPKRanges() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); ensureTableCreated(getUrl(), TestUtil.BTABLE_NAME); Statement stmt = conn.createStatement(); // BTABLE has 5 PK columns String query = "select * from " + BTABLE_NAME + " where (a_string > '1' and a_string < '5') or (a_string > '6' and a_string < '9')"; StatementContext context = compileStatement(query); Filter filter = context.getScan().getFilter(); assertNotNull(filter); assertTrue(filter instanceof SkipScanFilter); ScanRanges scanRanges = context.getScanRanges(); assertNotNull(scanRanges); List<List<KeyRange>> ranges = scanRanges.getRanges(); assertEquals(1, ranges.size()); List<List<KeyRange>> expectedRanges = Collections.singletonList(Arrays.asList( KeyRange.getKeyRange(Bytes.toBytes("1"), false, Bytes.toBytes("5"), false), KeyRange.getKeyRange(Bytes.toBytes("6"), false, Bytes.toBytes("9"), false))); assertEquals(expectedRanges, ranges); stmt.close(); conn.close(); }
StatementContext context = plan.getContext(); ScanRanges scanRanges = context.getScanRanges(); List<List<KeyRange>> ranges = scanRanges.getRanges(); assertEquals(expectedRanges, ranges);
@Test public void testOrSameColRangeExpression() throws SQLException { String query = "select * from atable where substr(organization_id,1,3) = ? or organization_id LIKE 'foo%'"; List<Object> binds = Arrays.<Object>asList("00D"); StatementContext context = compileStatement(query, binds); Scan scan = context.getScan(); Filter filter = scan.getFilter(); assertNotNull(filter); assertTrue(filter instanceof SkipScanFilter); ScanRanges scanRanges = context.getScanRanges(); assertNotNull(scanRanges); List<List<KeyRange>> ranges = scanRanges.getRanges(); assertEquals(1,ranges.size()); List<List<KeyRange>> expectedRanges = Collections.singletonList(Arrays.asList( PChar.INSTANCE.getKeyRange( StringUtil.padChar(PChar.INSTANCE.toBytes("00D"),15), true, StringUtil.padChar(ByteUtil.nextKey(PChar.INSTANCE.toBytes("00D")),15), false), PChar.INSTANCE.getKeyRange( StringUtil.padChar(PChar.INSTANCE.toBytes("foo"),15), true, StringUtil.padChar(ByteUtil.nextKey(PChar.INSTANCE.toBytes("foo")),15), false))); assertEquals(expectedRanges, ranges); }
@Test public void testOrSameColExpression() throws SQLException { String tenantId1 = "000000000000001"; String tenantId2 = "000000000000003"; String query = "select * from atable where organization_id = ? or organization_id = ?"; List<Object> binds = Arrays.<Object>asList(tenantId1,tenantId2); StatementContext context = compileStatement(query, binds); Scan scan = context.getScan(); Filter filter = scan.getFilter(); assertNotNull(filter); assertTrue(filter instanceof SkipScanFilter); ScanRanges scanRanges = context.getScanRanges(); assertNotNull(scanRanges); List<List<KeyRange>> ranges = scanRanges.getRanges(); assertEquals(1,ranges.size()); List<List<KeyRange>> expectedRanges = Collections.singletonList(Arrays.asList( PChar.INSTANCE.getKeyRange(PChar.INSTANCE.toBytes(tenantId1), true, PChar.INSTANCE.toBytes(tenantId1), true), PChar.INSTANCE.getKeyRange(PChar.INSTANCE.toBytes(tenantId2), true, PChar.INSTANCE.toBytes(tenantId2), true))); assertEquals(expectedRanges, ranges); byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId1); assertArrayEquals(startRow, scan.getStartRow()); assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId2)), scan.getStopRow()); }
@Test public void testUsingRVCFullyQualifiedInClause() throws Exception { String firstOrgId = "000000000000001"; String secondOrgId = "000000000000009"; String firstParentId = "000000000000011"; String secondParentId = "000000000000021"; String query = "select * from atable where (organization_id, entity_id) IN ((?, ?), (?, ?))"; List<Object> binds = Arrays.<Object>asList(firstOrgId, firstParentId, secondOrgId, secondParentId); StatementContext context = compileStatement(query, binds); Scan scan = context.getScan(); Filter filter = scan.getFilter(); assertTrue(filter instanceof SkipScanFilter); List<List<KeyRange>> skipScanRanges = Collections.singletonList(Arrays.asList( KeyRange.getKeyRange(ByteUtil.concat(PChar.INSTANCE.toBytes(firstOrgId), PChar.INSTANCE.toBytes(firstParentId))), KeyRange.getKeyRange(ByteUtil.concat(PChar.INSTANCE.toBytes(secondOrgId), PChar.INSTANCE.toBytes(secondParentId))))); assertEquals(skipScanRanges, context.getScanRanges().getRanges()); assertArrayEquals(ByteUtil.concat(PChar.INSTANCE.toBytes(firstOrgId), PChar.INSTANCE.toBytes(firstParentId)), scan.getStartRow()); assertArrayEquals(ByteUtil.concat(PChar.INSTANCE.toBytes(secondOrgId), PChar.INSTANCE.toBytes(secondParentId), QueryConstants.SEPARATOR_BYTE_ARRAY), scan.getStopRow()); }
private boolean explainSkipScan(StringBuilder buf) { ScanRanges scanRanges = context.getScanRanges(); if (scanRanges.isPointLookup()) { int keyCount = scanRanges.getPointLookupCount(); buf.append("POINT LOOKUP ON " + keyCount + " KEY" + (keyCount > 1 ? "S " : " ")); } else if (scanRanges.useSkipScanFilter()) { buf.append("SKIP SCAN "); int count = 1; boolean hasRanges = false; int nSlots = scanRanges.getBoundSlotCount(); for (int i = 0; i < nSlots; i++) { List<KeyRange> ranges = scanRanges.getRanges().get(i); count *= ranges.size(); for (KeyRange range : ranges) { hasRanges |= !range.isSingleKey(); } } buf.append("ON "); buf.append(count); buf.append(hasRanges ? " RANGE" : " KEY"); buf.append(count > 1 ? "S " : " "); } else { buf.append("RANGE SCAN "); } return scanRanges.useSkipScanFilter(); }
boolean isLocalIndex = ScanUtil.isLocalIndex(context.getScan()); boolean forceSkipScan = this.hint.hasHint(Hint.SKIP_SCAN); int nRanges = forceSkipScan ? scanRanges.getRanges().size() : scanRanges.getBoundSlotCount(); for (int i = 0, minPos = 0; minPos < nRanges || minMaxIterator.hasNext(); i++) { List<KeyRange> ranges = minPos >= nRanges ? EVERYTHING : scanRanges.getRanges().get(minPos++); KeyRange range = bound == Bound.LOWER ? ranges.get(0) : ranges.get(ranges.size()-1); byte[] b = range.getRange(bound);
boolean useSkipScan = false; boolean hasRange = false; List<List<KeyRange>> rangesList = dataScanRanges.getRanges(); int rangesListSize = rangesList.size(); while (offset < nColumnsInCommon && offset < rangesListSize) {
private boolean explainSkipScan(StringBuilder buf) { ScanRanges scanRanges = context.getScanRanges(); if (scanRanges.isPointLookup()) { int keyCount = scanRanges.getPointLookupCount(); buf.append("POINT LOOKUP ON " + keyCount + " KEY" + (keyCount > 1 ? "S " : " ")); } else if (scanRanges.useSkipScanFilter()) { buf.append("SKIP SCAN "); int count = 1; boolean hasRanges = false; int nSlots = scanRanges.getBoundSlotCount(); for (int i = 0; i < nSlots; i++) { List<KeyRange> ranges = scanRanges.getRanges().get(i); count *= ranges.size(); for (KeyRange range : ranges) { hasRanges |= !range.isSingleKey(); } } buf.append("ON "); buf.append(count); buf.append(hasRanges ? " RANGE" : " KEY"); buf.append(count > 1 ? "S " : " "); } else { buf.append("RANGE SCAN "); } return scanRanges.useSkipScanFilter(); }
public GettingResultIterator(StatementContext context, Expression where) { this.context = context; this.where = where; this.gets = Lists.newArrayListWithExpectedSize(context.getScanRanges().getPointLookupCount()); Scan scan = context.getScan(); List<List<KeyRange>> ranges = context.getScanRanges().getRanges(); for (KeyRange range : ranges.get(0)) { Get get = new Get(range.getLowerRange()); for (Map.Entry<byte[], NavigableSet<byte[]>> entry : scan.getFamilyMap().entrySet()) { byte[] family = entry.getKey(); if (entry.getValue() != null) { for (byte[] q : entry.getValue()) { get.addColumn(family, q); } } else { get.addFamily(family); } } for (Map.Entry<String, byte[]> attr : scan.getAttributesMap().entrySet()) { get.setAttribute(attr.getKey(), attr.getValue()); } setGetAttribute(get); gets.add(get); } }
boolean useSkipScan = false; boolean hasRange = false; List<List<KeyRange>> rangesList = dataScanRanges.getRanges(); int rangesListSize = rangesList.size(); while (offset < nColumnsInCommon && offset < rangesListSize) {
int nRanges = forceSkipScan ? scanRanges.getRanges().size() : scanRanges.getBoundSlotCount(); for (int i = 0, minPos = 0; minPos < nRanges || minMaxIterator.hasNext(); i++) { List<KeyRange> ranges = minPos >= nRanges ? EVERYTHING : scanRanges.getRanges().get(minPos++); KeyRange range = bound == Bound.LOWER ? ranges.get(0) : ranges.get(ranges.size()-1); byte[] b = range.getRange(bound);