use of org.apache.hadoop.hbase.filter.Filter in project phoenix by apache.
the class WhereOptimizerTest method testNullAtEndOfRVC.
@Test
public void testNullAtEndOfRVC() throws SQLException {
String tenantId = "000000000000001";
String parentId = "000000000000002";
Date createdDate = null;
String query = "select * from entity_history where (organization_id, parent_id, created_date) >= (?,?,?)";
List<Object> binds = Arrays.<Object>asList(tenantId, parentId, createdDate);
StatementContext context = compileStatement(query, binds);
Scan scan = context.getScan();
Filter filter = scan.getFilter();
assertNull(filter);
byte[] expectedStartRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(parentId));
assertArrayEquals(expectedStartRow, scan.getStartRow());
assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
}
use of org.apache.hadoop.hbase.filter.Filter in project phoenix by apache.
the class WhereOptimizerTest method testNullAtStartOfRVC.
@Test
public void testNullAtStartOfRVC() throws SQLException {
String tenantId = null;
String parentId = "000000000000002";
Date createdDate = new Date(System.currentTimeMillis());
String query = "select * from entity_history where (organization_id, parent_id, created_date) >= (?,?,?)";
List<Object> binds = Arrays.<Object>asList(tenantId, parentId, createdDate);
StatementContext context = compileStatement(query, binds);
Scan scan = context.getScan();
Filter filter = scan.getFilter();
assertNull(filter);
byte[] expectedStartRow = ByteUtil.concat(new byte[15], ByteUtil.previousKey(PChar.INSTANCE.toBytes(parentId)), PDate.INSTANCE.toBytes(createdDate));
assertArrayEquals(expectedStartRow, scan.getStartRow());
assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
}
use of org.apache.hadoop.hbase.filter.Filter in project phoenix by apache.
the class WhereOptimizerTest method testRVCWithCompareOpsForRowKeyColumnValuesSmallerThanSchema.
@Test
public void testRVCWithCompareOpsForRowKeyColumnValuesSmallerThanSchema() throws SQLException {
String orgId = "0000005";
String entityId = "011";
String orgId2 = "000005";
String entityId2 = "11";
// CASE 1: >=
String query = "select * from atable where (organization_id, entity_id) >= (?,?)";
List<Object> binds = Arrays.<Object>asList(orgId, entityId);
StatementContext context = compileStatement(query, binds);
Scan scan = context.getScan();
Filter filter = scan.getFilter();
assertNull(filter);
assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(PChar.INSTANCE.toBytes(entityId), 15)), scan.getStartRow());
assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
// CASE 2: >
query = "select * from atable where (organization_id, entity_id) > (?,?)";
binds = Arrays.<Object>asList(orgId, entityId);
context = compileStatement(query, binds);
scan = context.getScan();
filter = scan.getFilter();
assertNull(filter);
assertArrayEquals(ByteUtil.nextKey(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(PChar.INSTANCE.toBytes(entityId), 15))), scan.getStartRow());
assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
// CASE 3: <=
query = "select * from atable where (organization_id, entity_id) <= (?,?)";
binds = Arrays.<Object>asList(orgId, entityId);
context = compileStatement(query, binds);
scan = context.getScan();
filter = scan.getFilter();
assertNull(filter);
assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStartRow());
assertArrayEquals(ByteUtil.nextKey(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(PChar.INSTANCE.toBytes(entityId), 15))), scan.getStopRow());
// CASE 4: <
query = "select * from atable where (organization_id, entity_id) < (?,?)";
binds = Arrays.<Object>asList(orgId, entityId);
context = compileStatement(query, binds);
scan = context.getScan();
filter = scan.getFilter();
assertNull(filter);
assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStartRow());
assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(PChar.INSTANCE.toBytes(entityId), 15)), scan.getStopRow());
// CASE 5: =
// For RVC, this will only occur if there's more than one key in the IN
query = "select * from atable where (organization_id, entity_id) IN ((?,?),(?,?))";
binds = Arrays.<Object>asList(orgId, entityId, orgId2, entityId2);
context = compileStatement(query, binds);
scan = context.getScan();
filter = scan.getFilter();
assertTrue(filter instanceof SkipScanFilter);
ScanRanges scanRanges = context.getScanRanges();
assertEquals(2, scanRanges.getPointLookupCount());
Iterator<KeyRange> iterator = scanRanges.getPointLookupKeyIterator();
KeyRange k1 = iterator.next();
assertTrue(k1.isSingleKey());
assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(PChar.INSTANCE.toBytes(entityId), 15)), k1.getLowerRange());
KeyRange k2 = iterator.next();
assertTrue(k2.isSingleKey());
assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId2), 15), StringUtil.padChar(PChar.INSTANCE.toBytes(entityId2), 15)), k2.getLowerRange());
}
use of org.apache.hadoop.hbase.filter.Filter in project phoenix by apache.
the class WhereOptimizerTest method testCombiningRVCUsingOr2.
@Test
public void testCombiningRVCUsingOr2() throws SQLException {
String firstTenantId = "000000000000001";
String secondTenantId = "000000000000005";
String firstParentId = "000000000000011";
String secondParentId = "000000000000015";
String query = "select * from entity_history where (organization_id, parent_id) >= (?,?) OR (organization_id, parent_id) >= (?, ?)";
List<Object> binds = Arrays.<Object>asList(firstTenantId, firstParentId, secondTenantId, secondParentId);
StatementContext context = compileStatement(query, binds);
Scan scan = context.getScan();
Filter filter = scan.getFilter();
assertNull(filter);
assertArrayEquals(ByteUtil.concat(PVarchar.INSTANCE.toBytes(firstTenantId), PVarchar.INSTANCE.toBytes(firstParentId)), scan.getStartRow());
assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
}
use of org.apache.hadoop.hbase.filter.Filter in project phoenix by apache.
the class WhereOptimizerTest method testLikeExtractKeyExpression2.
@Test
public void testLikeExtractKeyExpression2() throws SQLException {
String tenantId = "000000000000001";
String keyPrefix = "002";
String likeArg = keyPrefix + "_";
String query = "select * from atable where organization_id = ? and entity_id LIKE '" + likeArg + "'";
List<Object> binds = Arrays.<Object>asList(tenantId);
StatementContext context = compileStatement(query, binds);
Scan scan = context.getScan();
Filter filter = scan.getFilter();
assertNotNull(filter);
assertEquals(rowKeyFilter(like(ENTITY_ID, likeArg, context)), filter);
byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix), 15));
assertArrayEquals(startRow, scan.getStartRow());
byte[] stopRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)), 15));
assertArrayEquals(stopRow, scan.getStopRow());
}
Aggregations