Search in sources :

Example 6 with ScanPlan

use of org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan in project hive by apache.

the class TestHBaseFilterPlanUtil method testMultiScanPlanOr.

/**
   * Test MultiScanPlan OR
   */
@Test
public void testMultiScanPlanOr() {
    MultiScanPlan l = createMultiScanPlan(new ScanPlan());
    MultiScanPlan r = createMultiScanPlan(new ScanPlan());
    // verify OR of two multi plans with one plan each
    Assert.assertEquals(2, l.or(r).getPlans().size());
    // verify OR of multi plan with a single scanplan
    Assert.assertEquals(2, l.or(new ScanPlan()).getPlans().size());
    Assert.assertEquals(2, (new ScanPlan()).or(l).getPlans().size());
    // verify or of two multiplans with more than one scan plan
    r = createMultiScanPlan(new ScanPlan(), new ScanPlan());
    Assert.assertEquals(3, l.or(r).getPlans().size());
    Assert.assertEquals(3, r.or(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 7 with ScanPlan

use of org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan in project hive by apache.

the class TestHBaseFilterPlanUtil method verifyPlan.

private void verifyPlan(TreeNode l, List<FieldSchema> parts, String keyName, ScanMarker startMarker, ScanMarker endMarker, boolean hasUnsupportedCondition) throws MetaException {
    ExpressionTree e = null;
    if (l != null) {
        e = new ExpressionTree();
        e.setRootForTest(l);
    }
    PlanResult planRes = HBaseFilterPlanUtil.getFilterPlan(e, parts);
    FilterPlan plan = planRes.plan;
    Assert.assertEquals("Has unsupported condition", hasUnsupportedCondition, planRes.hasUnsupportedCondition);
    Assert.assertEquals(1, plan.getPlans().size());
    ScanPlan splan = plan.getPlans().get(0);
    if (startMarker != null) {
        Assert.assertEquals(startMarker, splan.markers.get(keyName).startMarker);
    } else {
        Assert.assertTrue(splan.markers.get(keyName) == null || splan.markers.get(keyName).startMarker == null);
    }
    if (endMarker != null) {
        Assert.assertEquals(endMarker, splan.markers.get(keyName).endMarker);
    } else {
        Assert.assertTrue(splan.markers.get(keyName) == null || splan.markers.get(keyName).endMarker == null);
    }
}
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) ExpressionTree(org.apache.hadoop.hive.metastore.parser.ExpressionTree) FilterPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.FilterPlan)

Example 8 with ScanPlan

use of org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan in project hive by apache.

the class HBaseStore method getPartitionsByExprInternal.

private boolean getPartitionsByExprInternal(String dbName, String tblName, ExpressionTree exprTree, short maxParts, List<Partition> result) throws MetaException, NoSuchObjectException {
    dbName = HiveStringUtils.normalizeIdentifier(dbName);
    tblName = HiveStringUtils.normalizeIdentifier(tblName);
    Table table = getTable(dbName, tblName);
    if (table == null) {
        throw new NoSuchObjectException("Unable to find table " + dbName + "." + tblName);
    }
    // general hbase filter plan from expression tree
    PlanResult planRes = HBaseFilterPlanUtil.getFilterPlan(exprTree, table.getPartitionKeys());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Hbase Filter Plan generated : " + planRes.plan);
    }
    // results from scans need to be merged as there can be overlapping results between
    // the scans. Use a map of list of partition values to partition for this.
    Map<List<String>, Partition> mergedParts = new HashMap<List<String>, Partition>();
    for (ScanPlan splan : planRes.plan.getPlans()) {
        try {
            List<Partition> parts = getHBase().scanPartitions(dbName, tblName, splan.getStartRowSuffix(dbName, tblName, table.getPartitionKeys()), splan.getEndRowSuffix(dbName, tblName, table.getPartitionKeys()), splan.getFilter(table.getPartitionKeys()), -1);
            boolean reachedMax = false;
            for (Partition part : parts) {
                mergedParts.put(part.getValues(), part);
                if (mergedParts.size() == maxParts) {
                    reachedMax = true;
                    break;
                }
            }
            if (reachedMax) {
                break;
            }
        } catch (IOException e) {
            LOG.error("Unable to get partitions", e);
            throw new MetaException("Error scanning partitions" + tableNameForErrorMsg(dbName, tblName) + ": " + e);
        }
    }
    for (Entry<List<String>, Partition> mp : mergedParts.entrySet()) {
        result.add(mp.getValue());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Matched partitions " + result);
    }
    // being returned
    return !planRes.hasUnsupportedCondition;
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) PlanResult(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.PlanResult) ScanPlan(org.apache.hadoop.hive.metastore.hbase.HBaseFilterPlanUtil.ScanPlan) Table(org.apache.hadoop.hive.metastore.api.Table) HashMap(java.util.HashMap) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

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