Search in sources :

Example 1 with ComparisonBinaryExpression

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

the class ProtoConverter method visit.

@Override
protected Expr visit(ComparisonBinaryExpression node, Object context) {
    NormalizedPredicate predicate = node.normalize();
    if (predicate.getValue().isOverflowed()) {
        throw new UnsupportedOperationException("overflowed ComparisonBinaryExpression cannot be pushed down");
    }
    Expression child = node.getLeft();
    String typeSignature = getTypeSignature(child);
    ScalarFuncSig protoSig;
    switch(node.getComparisonType()) {
        case EQUAL:
            protoSig = ScalarFuncSig.valueOf("EQ" + typeSignature);
            break;
        case GREATER_EQUAL:
            protoSig = ScalarFuncSig.valueOf("GE" + typeSignature);
            break;
        case GREATER_THAN:
            protoSig = ScalarFuncSig.valueOf("GT" + typeSignature);
            break;
        case LESS_EQUAL:
            protoSig = ScalarFuncSig.valueOf("LE" + typeSignature);
            break;
        case LESS_THAN:
            protoSig = ScalarFuncSig.valueOf("LT" + typeSignature);
            break;
        case NOT_EQUAL:
            protoSig = ScalarFuncSig.valueOf("NE" + typeSignature);
            break;
        default:
            throw new TiExpressionException(String.format("Unknown comparison type %s", node.getComparisonType()));
    }
    Expr.Builder builder = scalarToPartialProto(node, context);
    builder.setSig(protoSig);
    builder.setFieldType(toPBFieldType(getType(node)));
    return builder.build();
}
Also used : Expr(com.pingcap.tidb.tipb.Expr) FuncCallExpr(com.pingcap.tikv.expression.FuncCallExpr) Expression(com.pingcap.tikv.expression.Expression) ArithmeticBinaryExpression(com.pingcap.tikv.expression.ArithmeticBinaryExpression) StringRegExpression(com.pingcap.tikv.expression.StringRegExpression) ComparisonBinaryExpression(com.pingcap.tikv.expression.ComparisonBinaryExpression) LogicalBinaryExpression(com.pingcap.tikv.expression.LogicalBinaryExpression) NormalizedPredicate(com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate) TiExpressionException(com.pingcap.tikv.exception.TiExpressionException) ScalarFuncSig(com.pingcap.tidb.tipb.ScalarFuncSig)

Example 2 with ComparisonBinaryExpression

use of com.pingcap.tikv.expression.ComparisonBinaryExpression 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)

Aggregations

ComparisonBinaryExpression (com.pingcap.tikv.expression.ComparisonBinaryExpression)2 NormalizedPredicate (com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate)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