Search in sources :

Example 1 with ScanPlan

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);
}
Also used : ScanMarker(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan.ScanMarker) MultiScanPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.MultiScanPlan) ScanPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan) Test(org.junit.Test)

Example 2 with ScanPlan

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");
}
Also used : PlanResult(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.PlanResult) MultiScanPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.MultiScanPlan) ScanPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) ArrayList(java.util.ArrayList) ExpressionTree(org.apache.hadoop.hive.metastore.parser.ExpressionTree) Test(org.junit.Test)

Example 3 with ScanPlan

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());
}
Also used : MultiScanPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.MultiScanPlan) ScanPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan) FilterPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.FilterPlan) Test(org.junit.Test)

Example 4 with ScanPlan

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());
}
Also used : MultiScanPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.MultiScanPlan) ScanPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan) MultiScanPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.MultiScanPlan) Test(org.junit.Test)

Example 5 with ScanPlan

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()));
}
Also used : PlanResult(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.PlanResult) MultiScanPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.MultiScanPlan) ScanPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) ArrayList(java.util.ArrayList) ExpressionTree(org.apache.hadoop.hive.metastore.parser.ExpressionTree) Test(org.junit.Test)

Aggregations

ScanPlan (org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan)8 MultiScanPlan (org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.MultiScanPlan)7 Test (org.junit.Test)6 PlanResult (org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.PlanResult)4 ArrayList (java.util.ArrayList)3 ExpressionTree (org.apache.hadoop.hive.metastore.parser.ExpressionTree)3 RowFilter (org.apache.hadoop.hbase.filter.RowFilter)2 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)2 FilterPlan (org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.FilterPlan)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 Partition (org.apache.hadoop.hive.metastore.api.Partition)1 Table (org.apache.hadoop.hive.metastore.api.Table)1 ScanMarker (org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan.ScanMarker)1