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());
}
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);
}
}
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;
}
Aggregations