Search in sources :

Example 6 with NormalizedPredicate

use of com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate in project tispark by pingcap.

the class PartAndFilterExprRewriter method visit.

@Override
public Expression visit(ComparisonBinaryExpression node, Void context) {
    NormalizedPredicate predicate = node.normalize();
    // predicate maybe null if node's left or right does not have a column ref or a constant.
    if (predicate != null) {
        if (!columnRefs.contains(predicate.getColumnRef())) {
            return node;
        }
        // we only support year for now.
        if (isYear()) {
            FuncCallExpr year = new FuncCallExpr(predicate.getValue(), Type.YEAR);
            Constant newLiteral = year.eval(predicate.getValue());
            return new ComparisonBinaryExpression(node.getComparisonType(), node.getLeft(), newLiteral);
        } else if (isColumnRef()) {
            return node;
        }
        unsupportedPartFnFound = true;
        return null;
    }
    // when we find a node in form like [year(y) < 1995], we need rewrite the left child.
    Expression left = node.getLeft().accept(this, null);
    Expression right = node.getRight().accept(this, null);
    return new ComparisonBinaryExpression(node.getComparisonType(), left, right);
}
Also used : ComparisonBinaryExpression(com.pingcap.tikv.expression.ComparisonBinaryExpression) LogicalBinaryExpression(com.pingcap.tikv.expression.LogicalBinaryExpression) Expression(com.pingcap.tikv.expression.Expression) Constant(com.pingcap.tikv.expression.Constant) NormalizedPredicate(com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate) ComparisonBinaryExpression(com.pingcap.tikv.expression.ComparisonBinaryExpression) FuncCallExpr(com.pingcap.tikv.expression.FuncCallExpr)

Example 7 with NormalizedPredicate

use of com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate in project tispark by pingcap.

the class PrunedPartitionBuilder method visit.

@Override
protected RangeSet<TypedKey> visit(ComparisonBinaryExpression node, Void context) {
    NormalizedPredicate predicate = node.normalize();
    // which indicates it cannot be pruned such as a > b + 1
    if (predicate == null)
        return TreeRangeSet.<TypedKey>create().complement();
    if (!partExprColRefs.contains(predicate.getColumnRef()))
        return TreeRangeSet.<TypedKey>create().complement();
    TypedKey literal;
    literal = predicate.getTypedLiteral(-1);
    return visitComparisonBinaryExpr(node, context, literal, false);
}
Also used : TypedKey(com.pingcap.tikv.key.TypedKey) NormalizedPredicate(com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate)

Aggregations

NormalizedPredicate (com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate)7 TypedKey (com.pingcap.tikv.key.TypedKey)3 ComparisonBinaryExpression (com.pingcap.tikv.expression.ComparisonBinaryExpression)2 Expression (com.pingcap.tikv.expression.Expression)2 FuncCallExpr (com.pingcap.tikv.expression.FuncCallExpr)2 LogicalBinaryExpression (com.pingcap.tikv.expression.LogicalBinaryExpression)2 Expr (com.pingcap.tidb.tipb.Expr)1 ScalarFuncSig (com.pingcap.tidb.tipb.ScalarFuncSig)1 TiExpressionException (com.pingcap.tikv.exception.TiExpressionException)1 ArithmeticBinaryExpression (com.pingcap.tikv.expression.ArithmeticBinaryExpression)1 Constant (com.pingcap.tikv.expression.Constant)1 StringRegExpression (com.pingcap.tikv.expression.StringRegExpression)1 PrunedPartitionBuilder (com.pingcap.tikv.expression.visitor.PrunedPartitionBuilder)1 HashSet (java.util.HashSet)1