Search in sources :

Example 1 with ExpressionTree

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());
    }
}
Also used : MessageType(org.apache.parquet.schema.MessageType) Type(org.apache.parquet.schema.Type) PredicateLeaf(org.apache.hadoop.hive.ql.io.sarg.PredicateLeaf) ExpressionTree(org.apache.hadoop.hive.ql.io.sarg.ExpressionTree) FilterPredicate(org.apache.parquet.filter2.predicate.FilterPredicate) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)

Aggregations

ExpressionTree (org.apache.hadoop.hive.ql.io.sarg.ExpressionTree)1 PredicateLeaf (org.apache.hadoop.hive.ql.io.sarg.PredicateLeaf)1 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)1 FilterPredicate (org.apache.parquet.filter2.predicate.FilterPredicate)1 MessageType (org.apache.parquet.schema.MessageType)1 Type (org.apache.parquet.schema.Type)1