use of org.apache.phoenix.filter.SkipScanFilter in project phoenix by apache.
the class ScanUtil method setRowKeyOffset.
private static void setRowKeyOffset(Filter filter, int offset) {
if (filter instanceof BooleanExpressionFilter) {
BooleanExpressionFilter boolFilter = (BooleanExpressionFilter) filter;
IndexUtil.setRowKeyExpressionOffset(boolFilter.getExpression(), offset);
} else if (filter instanceof SkipScanFilter) {
SkipScanFilter skipScanFilter = (SkipScanFilter) filter;
skipScanFilter.setOffset(offset);
} else if (filter instanceof DistinctPrefixFilter) {
DistinctPrefixFilter prefixFilter = (DistinctPrefixFilter) filter;
prefixFilter.setOffset(offset);
}
}
use of org.apache.phoenix.filter.SkipScanFilter in project phoenix by apache.
the class WhereOptimizerTest method testDescDecimalRange.
@Test
public void testDescDecimalRange() throws SQLException {
String ddl = "create table t (k1 bigint not null, k2 decimal, constraint pk primary key (k1,k2 desc))";
Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
conn.createStatement().execute(ddl);
String query = "select * from t where k1 in (1,2) and k2>1.0";
Scan scan = compileStatement(query).getScan();
byte[] startRow = ByteUtil.concat(PLong.INSTANCE.toBytes(1), ByteUtil.nextKey(QueryConstants.SEPARATOR_BYTE_ARRAY), QueryConstants.DESC_SEPARATOR_BYTE_ARRAY);
byte[] upperValue = PDecimal.INSTANCE.toBytes(BigDecimal.valueOf(1.0));
byte[] stopRow = ByteUtil.concat(PLong.INSTANCE.toBytes(2), SortOrder.invert(upperValue, 0, upperValue.length), QueryConstants.DESC_SEPARATOR_BYTE_ARRAY);
assertTrue(scan.getFilter() instanceof SkipScanFilter);
assertArrayEquals(startRow, scan.getStartRow());
assertArrayEquals(stopRow, scan.getStopRow());
}
use of org.apache.phoenix.filter.SkipScanFilter in project phoenix by apache.
the class WhereCompilerTest method testOrPKWithAndPKAndNotPK.
@Test
public void testOrPKWithAndPKAndNotPK() throws SQLException {
String query = "select * from bugTable where ID = 'i1' or (ID = 'i2' and company = 'c3')";
PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
pconn.createStatement().execute("create table bugTable(ID varchar primary key,company varchar)");
PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
QueryPlan plan = pstmt.optimizeQuery();
Scan scan = plan.getContext().getScan();
Filter filter = scan.getFilter();
Expression idExpression = new ColumnRef(plan.getTableRef(), plan.getTableRef().getTable().getColumnForColumnName("ID").getPosition()).newColumnExpression();
Expression id = new RowKeyColumnExpression(idExpression, new RowKeyValueAccessor(plan.getTableRef().getTable().getPKColumns(), 0));
Expression company = new KeyValueColumnExpression(plan.getTableRef().getTable().getColumnForColumnName("COMPANY"));
// FilterList has no equals implementation
assertTrue(filter instanceof FilterList);
FilterList filterList = (FilterList) filter;
assertEquals(FilterList.Operator.MUST_PASS_ALL, filterList.getOperator());
assertEquals(Arrays.asList(new SkipScanFilter(ImmutableList.of(Arrays.asList(pointRange("i1"), pointRange("i2"))), SchemaUtil.VAR_BINARY_SCHEMA), singleKVFilter(or(constantComparison(CompareOp.EQUAL, id, "i1"), and(constantComparison(CompareOp.EQUAL, id, "i2"), constantComparison(CompareOp.EQUAL, company, "c3"))))), filterList.getFilters());
}
use of org.apache.phoenix.filter.SkipScanFilter in project phoenix by apache.
the class WhereCompilerTest method testMultiFixedFullPkSalted.
@Test
public void testMultiFixedFullPkSalted() throws SQLException {
PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
pconn.createStatement().execute("CREATE TABLE t (k bigint not null primary key, v varchar) SALT_BUCKETS=20");
String query = "select * from t where k in (1,3)";
PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
QueryPlan plan = pstmt.optimizeQuery();
Scan scan = plan.getContext().getScan();
Filter filter = scan.getFilter();
byte[] key = new byte[PLong.INSTANCE.getByteSize() + 1];
PLong.INSTANCE.toBytes(1L, key, 1);
key[0] = SaltingUtil.getSaltingByte(key, 1, PLong.INSTANCE.getByteSize(), 20);
byte[] startKey1 = key;
key = new byte[PLong.INSTANCE.getByteSize() + 1];
PLong.INSTANCE.toBytes(3L, key, 1);
key[0] = SaltingUtil.getSaltingByte(key, 1, PLong.INSTANCE.getByteSize(), 20);
byte[] startKey2 = key;
byte[] startKey = scan.getStartRow();
byte[] stopKey = scan.getStopRow();
// Due to salting byte, the 1 key may be after the 3 key
byte[] expectedStartKey;
byte[] expectedEndKey;
List<List<KeyRange>> expectedRanges = Collections.singletonList(Arrays.asList(KeyRange.getKeyRange(startKey1), KeyRange.getKeyRange(startKey2)));
if (Bytes.compareTo(startKey1, startKey2) > 0) {
expectedStartKey = startKey2;
expectedEndKey = startKey1;
Collections.reverse(expectedRanges.get(0));
} else {
expectedStartKey = startKey1;
expectedEndKey = startKey2;
}
assertEquals(0, startKey.length);
assertEquals(0, stopKey.length);
assertNotNull(filter);
assertTrue(filter instanceof SkipScanFilter);
SkipScanFilter skipScanFilter = (SkipScanFilter) filter;
assertEquals(1, skipScanFilter.getSlots().size());
assertEquals(2, skipScanFilter.getSlots().get(0).size());
assertArrayEquals(expectedStartKey, skipScanFilter.getSlots().get(0).get(0).getLowerRange());
assertArrayEquals(expectedEndKey, skipScanFilter.getSlots().get(0).get(1).getLowerRange());
StatementContext context = plan.getContext();
ScanRanges scanRanges = context.getScanRanges();
List<List<KeyRange>> ranges = scanRanges.getRanges();
assertEquals(expectedRanges, ranges);
}
use of org.apache.phoenix.filter.SkipScanFilter in project phoenix by apache.
the class WhereCompilerTest method testInListFilter.
@Test
public void testInListFilter() throws SQLException {
String tenantId1 = "000000000000001";
String tenantId2 = "000000000000002";
String tenantId3 = "000000000000003";
String query = String.format("select * from %s where organization_id IN ('%s','%s','%s')", ATABLE_NAME, tenantId1, tenantId3, tenantId2);
PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
QueryPlan plan = pstmt.optimizeQuery();
Scan scan = plan.getContext().getScan();
byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId1);
assertArrayEquals(startRow, scan.getStartRow());
byte[] stopRow = PVarchar.INSTANCE.toBytes(tenantId3);
assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
Filter filter = scan.getFilter();
assertEquals(new SkipScanFilter(ImmutableList.of(Arrays.asList(pointRange(tenantId1), pointRange(tenantId2), pointRange(tenantId3))), plan.getTableRef().getTable().getRowKeySchema()), filter);
}
Aggregations