Search in sources :

Example 1 with ArithmeticBinaryExpression

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

the class ProtoConverter method visit.

@Override
protected Expr visit(ArithmeticBinaryExpression node, Object context) {
    // assume after type coerce, children should be compatible
    Expression child = node.getLeft();
    String typeSignature = getTypeSignature(child);
    ScalarFuncSig protoSig;
    switch(node.getCompType()) {
        // TODO: Add test for bitwise push down
        case BIT_AND:
            protoSig = ScalarFuncSig.BitAndSig;
            break;
        case BIT_OR:
            protoSig = ScalarFuncSig.BitOrSig;
            break;
        case BIT_XOR:
            protoSig = ScalarFuncSig.BitXorSig;
            break;
        case DIVIDE:
            protoSig = ScalarFuncSig.valueOf("Divide" + typeSignature);
            break;
        case MINUS:
            protoSig = ScalarFuncSig.valueOf("Minus" + typeSignature);
            break;
        case MULTIPLY:
            protoSig = ScalarFuncSig.valueOf("Multiply" + typeSignature);
            break;
        case PLUS:
            protoSig = ScalarFuncSig.valueOf("Plus" + typeSignature);
            break;
        default:
            throw new TiExpressionException(String.format("Unknown comparison type %s", node.getCompType()));
    }
    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) TiExpressionException(com.pingcap.tikv.exception.TiExpressionException) ScalarFuncSig(com.pingcap.tidb.tipb.ScalarFuncSig)

Aggregations

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 ComparisonBinaryExpression (com.pingcap.tikv.expression.ComparisonBinaryExpression)1 Expression (com.pingcap.tikv.expression.Expression)1 FuncCallExpr (com.pingcap.tikv.expression.FuncCallExpr)1 LogicalBinaryExpression (com.pingcap.tikv.expression.LogicalBinaryExpression)1 StringRegExpression (com.pingcap.tikv.expression.StringRegExpression)1