use of org.apache.hadoop.hive.ql.io.sarg.ExpressionTree in project hive by apache.
the class ParquetFilterPredicateConverter method translate.
private static FilterPredicate translate(ExpressionTree root, List<PredicateLeaf> leaves, Map<String, TypeInfo> columns, MessageType schema) throws Exception {
FilterPredicate p = null;
switch(root.getOperator()) {
case OR:
for (ExpressionTree child : root.getChildren()) {
FilterPredicate childPredicate = translate(child, leaves, columns, schema);
if (childPredicate == null) {
return null;
}
if (p == null) {
p = childPredicate;
} else {
p = FilterApi.or(p, childPredicate);
}
}
return p;
case AND:
for (ExpressionTree child : root.getChildren()) {
if (p == null) {
p = translate(child, leaves, columns, schema);
} else {
FilterPredicate right = translate(child, leaves, columns, schema);
// constant means no filter, ignore it when it is null
if (right != null) {
p = FilterApi.and(p, right);
}
}
}
return p;
case NOT:
FilterPredicate op = translate(root.getChildren().get(0), leaves, columns, schema);
if (op != null) {
return FilterApi.not(op);
} else {
return null;
}
case LEAF:
PredicateLeaf leaf = leaves.get(root.getLeaf());
// If columns is null, then we need to create the leaf
if (columns.containsKey(leaf.getColumnName())) {
Type parquetType = schema.getType(leaf.getColumnName());
TypeInfo hiveType = columns.get(leaf.getColumnName());
return buildFilterPredicateFromPredicateLeaf(leaf, parquetType, hiveType);
} else {
// Do not create predicate if the leaf is not on the passed schema.
return null;
}
case CONSTANT:
// no filter will be executed for constant
return null;
default:
throw new IllegalStateException("Unknown operator: " + root.getOperator());
}
}
Aggregations