use of org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan in project hive by apache.
the class TestHBaseFilterPlanUtil method testScanPlanAnd.
/**
* Test ScanPlan AND operation
*/
@Test
public void testScanPlanAnd() {
ScanPlan l = new ScanPlan();
ScanPlan r = new ScanPlan();
l.setStartMarker("a", "int", "10", INCLUSIVE);
r.setStartMarker("a", "int", "10", INCLUSIVE);
ScanPlan res;
// both equal
res = l.and(r).getPlans().get(0);
Assert.assertEquals(new ScanMarker("10", INCLUSIVE, "int"), res.markers.get("a").startMarker);
// add equal end markers as well, and test AND again
l.setEndMarker("a", "int", "20", INCLUSIVE);
r.setEndMarker("a", "int", "20", INCLUSIVE);
res = l.and(r).getPlans().get(0);
Assert.assertEquals(new ScanMarker("10", INCLUSIVE, "int"), res.markers.get("a").startMarker);
Assert.assertEquals(new ScanMarker("20", INCLUSIVE, "int"), res.markers.get("a").endMarker);
l.setStartMarker("a", "int", "10", !INCLUSIVE);
l.setEndMarker("a", "int", "20", INCLUSIVE);
r.setStartMarker("a", "int", "10", INCLUSIVE);
r.setEndMarker("a", "int", "15", INCLUSIVE);
res = l.and(r).getPlans().get(0);
// start of l is greater, end of r is smaller
Assert.assertEquals(l.markers.get("a").startMarker, res.markers.get("a").startMarker);
Assert.assertEquals(r.markers.get("a").endMarker, res.markers.get("a").endMarker);
}
use of org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan in project hive by apache.
the class TestHBaseFilterPlanUtil method testPartitionKeyScannerMixedType.
@Test
public void testPartitionKeyScannerMixedType() throws Exception {
List<FieldSchema> parts = new ArrayList<FieldSchema>();
parts.add(new FieldSchema("year", "int", null));
parts.add(new FieldSchema("month", "int", null));
parts.add(new FieldSchema("state", "string", null));
// One prefix key and one minor key range
ExpressionTree exprTree = PartFilterExprUtil.getFilterParser("year = 2015 and state = 'CA'").tree;
PlanResult planRes = HBaseFilterPlanUtil.getFilterPlan(exprTree, parts);
Assert.assertEquals(planRes.plan.getPlans().size(), 1);
ScanPlan sp = planRes.plan.getPlans().get(0);
byte[] startRowSuffix = sp.getStartRowSuffix("testdb", "testtb", parts);
byte[] endRowSuffix = sp.getEndRowSuffix("testdb", "testtb", parts);
RowFilter filter = (RowFilter) sp.getFilter(parts);
// scan range contains the major key year, rowfilter contains minor key state
Assert.assertTrue(Bytes.contains(startRowSuffix, Shorts.toByteArray((short) 2015)));
Assert.assertTrue(Bytes.contains(endRowSuffix, Shorts.toByteArray((short) 2016)));
PartitionKeyComparator comparator = (PartitionKeyComparator) filter.getComparator();
Assert.assertEquals(comparator.ranges.size(), 1);
Assert.assertEquals(comparator.ranges.get(0).keyName, "state");
}
use of org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan in project hive by apache.
the class TestHBaseFilterPlanUtil method testScanPlanOr.
/**
* Test ScanPlan OR operation
*/
@Test
public void testScanPlanOr() {
ScanPlan l = new ScanPlan();
ScanPlan r = new ScanPlan();
l.setStartMarker("a", "int", "1", INCLUSIVE);
r.setStartMarker("a", "int", "11", INCLUSIVE);
FilterPlan res1 = l.or(r);
Assert.assertEquals(2, res1.getPlans().size());
res1.getPlans().get(0).markers.get("a").startMarker.equals(l.markers.get("a").startMarker);
res1.getPlans().get(1).markers.get("a").startMarker.equals(r.markers.get("a").startMarker);
FilterPlan res2 = res1.or(r);
Assert.assertEquals(3, res2.getPlans().size());
}
use of org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan in project hive by apache.
the class TestHBaseFilterPlanUtil method testMultiScanPlanAnd.
/**
* Test MultiScanPlan AND
*/
@Test
public void testMultiScanPlanAnd() {
MultiScanPlan l = createMultiScanPlan(new ScanPlan());
MultiScanPlan r = createMultiScanPlan(new ScanPlan());
// two MultiScanPlan with single scan plans should result in new FilterPlan
// with just one scan
Assert.assertEquals(1, l.and(r).getPlans().size());
// l has one ScanPlan, r has two. AND result should have two
r = createMultiScanPlan(new ScanPlan(), new ScanPlan());
Assert.assertEquals(2, l.and(r).getPlans().size());
Assert.assertEquals(2, r.and(l).getPlans().size());
// l has 2 ScanPlans, r has 3. AND result should have 6
l = createMultiScanPlan(new ScanPlan(), new ScanPlan());
r = createMultiScanPlan(new ScanPlan(), new ScanPlan(), new ScanPlan());
Assert.assertEquals(6, l.and(r).getPlans().size());
Assert.assertEquals(6, r.and(l).getPlans().size());
}
use of org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan in project hive by apache.
the class TestHBaseFilterPlanUtil method testPartitionKeyScannerAllString.
@Test
public void testPartitionKeyScannerAllString() throws Exception {
List<FieldSchema> parts = new ArrayList<FieldSchema>();
parts.add(new FieldSchema("year", "string", null));
parts.add(new FieldSchema("month", "string", null));
parts.add(new FieldSchema("state", "string", null));
// One prefix key and one minor key range
ExpressionTree exprTree = PartFilterExprUtil.getFilterParser("year = 2015 and state = 'CA'").tree;
PlanResult planRes = HBaseFilterPlanUtil.getFilterPlan(exprTree, parts);
Assert.assertEquals(planRes.plan.getPlans().size(), 1);
ScanPlan sp = planRes.plan.getPlans().get(0);
byte[] startRowSuffix = sp.getStartRowSuffix("testdb", "testtb", parts);
byte[] endRowSuffix = sp.getEndRowSuffix("testdb", "testtb", parts);
RowFilter filter = (RowFilter) sp.getFilter(parts);
// scan range contains the major key year, rowfilter contains minor key state
Assert.assertTrue(Bytes.contains(startRowSuffix, "2015".getBytes()));
Assert.assertTrue(Bytes.contains(endRowSuffix, "2015".getBytes()));
Assert.assertFalse(Bytes.contains(startRowSuffix, "CA".getBytes()));
Assert.assertFalse(Bytes.contains(endRowSuffix, "CA".getBytes()));
PartitionKeyComparator comparator = (PartitionKeyComparator) filter.getComparator();
Assert.assertEquals(comparator.ranges.size(), 1);
Assert.assertEquals(comparator.ranges.get(0).keyName, "state");
// Two prefix key and one LIKE operator
exprTree = PartFilterExprUtil.getFilterParser("year = 2015 and month > 10 " + "and month <= 11 and state like 'C%'").tree;
planRes = HBaseFilterPlanUtil.getFilterPlan(exprTree, parts);
Assert.assertEquals(planRes.plan.getPlans().size(), 1);
sp = planRes.plan.getPlans().get(0);
startRowSuffix = sp.getStartRowSuffix("testdb", "testtb", parts);
endRowSuffix = sp.getEndRowSuffix("testdb", "testtb", parts);
filter = (RowFilter) sp.getFilter(parts);
// scan range contains the major key value year/month, rowfilter contains LIKE operator
Assert.assertTrue(Bytes.contains(startRowSuffix, "2015".getBytes()));
Assert.assertTrue(Bytes.contains(endRowSuffix, "2015".getBytes()));
Assert.assertTrue(Bytes.contains(startRowSuffix, "10".getBytes()));
Assert.assertTrue(Bytes.contains(endRowSuffix, "11".getBytes()));
comparator = (PartitionKeyComparator) filter.getComparator();
Assert.assertEquals(comparator.ops.size(), 1);
Assert.assertEquals(comparator.ops.get(0).keyName, "state");
// One prefix key, one minor key range and one LIKE operator
exprTree = PartFilterExprUtil.getFilterParser("year >= 2014 and month > 10 " + "and month <= 11 and state like 'C%'").tree;
planRes = HBaseFilterPlanUtil.getFilterPlan(exprTree, parts);
Assert.assertEquals(planRes.plan.getPlans().size(), 1);
sp = planRes.plan.getPlans().get(0);
startRowSuffix = sp.getStartRowSuffix("testdb", "testtb", parts);
endRowSuffix = sp.getEndRowSuffix("testdb", "testtb", parts);
filter = (RowFilter) sp.getFilter(parts);
// scan range contains the major key value year (low bound), rowfilter contains minor key state
// and LIKE operator
Assert.assertTrue(Bytes.contains(startRowSuffix, "2014".getBytes()));
comparator = (PartitionKeyComparator) filter.getComparator();
Assert.assertEquals(comparator.ranges.size(), 1);
Assert.assertEquals(comparator.ranges.get(0).keyName, "month");
Assert.assertEquals(comparator.ops.size(), 1);
Assert.assertEquals(comparator.ops.get(0).keyName, "state");
// Condition contains or
exprTree = PartFilterExprUtil.getFilterParser("year = 2014 and (month > 10 " + "or month < 3)").tree;
planRes = HBaseFilterPlanUtil.getFilterPlan(exprTree, parts);
sp = planRes.plan.getPlans().get(0);
startRowSuffix = sp.getStartRowSuffix("testdb", "testtb", parts);
endRowSuffix = sp.getEndRowSuffix("testdb", "testtb", parts);
filter = (RowFilter) sp.getFilter(parts);
// The first ScanPlan contains year = 2014 and month > 10
Assert.assertTrue(Bytes.contains(startRowSuffix, "2014".getBytes()));
Assert.assertTrue(Bytes.contains(endRowSuffix, "2014".getBytes()));
Assert.assertTrue(Bytes.contains(startRowSuffix, "10".getBytes()));
sp = planRes.plan.getPlans().get(1);
startRowSuffix = sp.getStartRowSuffix("testdb", "testtb", parts);
endRowSuffix = sp.getEndRowSuffix("testdb", "testtb", parts);
filter = (RowFilter) sp.getFilter(parts);
// The first ScanPlan contains year = 2014 and month < 3
Assert.assertTrue(Bytes.contains(startRowSuffix, "2014".getBytes()));
Assert.assertTrue(Bytes.contains(endRowSuffix, "2014".getBytes()));
Assert.assertTrue(Bytes.contains(endRowSuffix, "3".getBytes()));
}
Aggregations