Search in sources :

Example 1 with BetweenExpression

use of org.apache.pig.Expression.BetweenExpression in project parquet-mr by apache.

the class ParquetLoader method buildFilter.

private FilterPredicate buildFilter(Expression e) {
    OpType op = e.getOpType();
    if (e instanceof BinaryExpression) {
        Expression lhs = ((BinaryExpression) e).getLhs();
        Expression rhs = ((BinaryExpression) e).getRhs();
        switch(op) {
            case OP_AND:
                return and(buildFilter(lhs), buildFilter(rhs));
            case OP_OR:
                return or(buildFilter(lhs), buildFilter(rhs));
            case OP_BETWEEN:
                BetweenExpression between = (BetweenExpression) rhs;
                return and(buildFilter(OpType.OP_GE, (Column) lhs, (Const) between.getLower()), buildFilter(OpType.OP_LE, (Column) lhs, (Const) between.getUpper()));
            case OP_IN:
                FilterPredicate current = null;
                for (Object value : ((InExpression) rhs).getValues()) {
                    FilterPredicate next = buildFilter(OpType.OP_EQ, (Column) lhs, (Const) value);
                    if (current != null) {
                        current = or(current, next);
                    } else {
                        current = next;
                    }
                }
                return current;
        }
        if (lhs instanceof Column && rhs instanceof Const) {
            return buildFilter(op, (Column) lhs, (Const) rhs);
        } else if (lhs instanceof Const && rhs instanceof Column) {
            return buildFilter(op, (Column) rhs, (Const) lhs);
        }
    } else if (e instanceof UnaryExpression && op == OpType.OP_NOT) {
        return LogicalInverseRewriter.rewrite(not(buildFilter(((UnaryExpression) e).getExpression())));
    }
    throw new RuntimeException("Could not build filter for expression: " + e);
}
Also used : BinaryExpression(org.apache.pig.Expression.BinaryExpression) InExpression(org.apache.pig.Expression.InExpression) UnaryExpression(org.apache.pig.Expression.UnaryExpression) BinaryExpression(org.apache.pig.Expression.BinaryExpression) Expression(org.apache.pig.Expression) BetweenExpression(org.apache.pig.Expression.BetweenExpression) Column(org.apache.pig.Expression.Column) BetweenExpression(org.apache.pig.Expression.BetweenExpression) Const(org.apache.pig.Expression.Const) InExpression(org.apache.pig.Expression.InExpression) OpType(org.apache.pig.Expression.OpType) UnaryExpression(org.apache.pig.Expression.UnaryExpression) FilterPredicate(org.apache.parquet.filter2.predicate.FilterPredicate)

Aggregations

FilterPredicate (org.apache.parquet.filter2.predicate.FilterPredicate)1 Expression (org.apache.pig.Expression)1 BetweenExpression (org.apache.pig.Expression.BetweenExpression)1 BinaryExpression (org.apache.pig.Expression.BinaryExpression)1 Column (org.apache.pig.Expression.Column)1 Const (org.apache.pig.Expression.Const)1 InExpression (org.apache.pig.Expression.InExpression)1 OpType (org.apache.pig.Expression.OpType)1 UnaryExpression (org.apache.pig.Expression.UnaryExpression)1