Search in sources :

Example 1 with ScalarFuncSig

use of com.pingcap.tidb.tipb.ScalarFuncSig in project client-java by tikv.

the class ProtoConverter method visit.

@Override
protected Expr visit(LogicalBinaryExpression node, Object context) {
    ScalarFuncSig protoSig;
    switch(node.getCompType()) {
        case AND:
            protoSig = ScalarFuncSig.LogicalAnd;
            break;
        case OR:
            protoSig = ScalarFuncSig.LogicalOr;
            break;
        case XOR:
            protoSig = ScalarFuncSig.LogicalXor;
            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) TiExpressionException(org.tikv.common.exception.TiExpressionException) ScalarFuncSig(com.pingcap.tidb.tipb.ScalarFuncSig)

Example 2 with ScalarFuncSig

use of com.pingcap.tidb.tipb.ScalarFuncSig in project client-java by tikv.

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) TiExpressionException(org.tikv.common.exception.TiExpressionException) ScalarFuncSig(com.pingcap.tidb.tipb.ScalarFuncSig)

Example 3 with ScalarFuncSig

use of com.pingcap.tidb.tipb.ScalarFuncSig in project client-java by tikv.

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) NormalizedPredicate(org.tikv.common.expression.ComparisonBinaryExpression.NormalizedPredicate) TiExpressionException(org.tikv.common.exception.TiExpressionException) ScalarFuncSig(com.pingcap.tidb.tipb.ScalarFuncSig)

Example 4 with ScalarFuncSig

use of com.pingcap.tidb.tipb.ScalarFuncSig in project client-java by tikv.

the class ProtoConverter method visit.

@Override
protected Expr visit(FuncCallExpr node, Object context) {
    ScalarFuncSig protoSig = ScalarFuncSig.Year;
    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) ScalarFuncSig(com.pingcap.tidb.tipb.ScalarFuncSig)

Example 5 with ScalarFuncSig

use of com.pingcap.tidb.tipb.ScalarFuncSig in project tispark by pingcap.

the class ProtoConverter method visit.

@Override
protected Expr visit(Not node, Object context) {
    ScalarFuncSig protoSig = null;
    DataType dataType = getType(node);
    switch(dataType.getType()) {
        case TypeDecimal:
            protoSig = ScalarFuncSig.UnaryNotDecimal;
            break;
        case TypeDouble:
        case TypeFloat:
            protoSig = ScalarFuncSig.UnaryNotReal;
            break;
        case TypeInt24:
        case TypeLong:
        case TypeShort:
        case TypeLonglong:
        case TypeTiny:
            protoSig = ScalarFuncSig.UnaryNotInt;
            break;
        default:
    }
    Objects.requireNonNull(protoSig, "unary not can not find proper proto signature.");
    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) DataType(com.pingcap.tikv.types.DataType) ScalarFuncSig(com.pingcap.tidb.tipb.ScalarFuncSig)

Aggregations

Expr (com.pingcap.tidb.tipb.Expr)14 ScalarFuncSig (com.pingcap.tidb.tipb.ScalarFuncSig)14 FuncCallExpr (com.pingcap.tikv.expression.FuncCallExpr)7 TiExpressionException (com.pingcap.tikv.exception.TiExpressionException)4 TiExpressionException (org.tikv.common.exception.TiExpressionException)4 ArithmeticBinaryExpression (com.pingcap.tikv.expression.ArithmeticBinaryExpression)2 ComparisonBinaryExpression (com.pingcap.tikv.expression.ComparisonBinaryExpression)2 Expression (com.pingcap.tikv.expression.Expression)2 LogicalBinaryExpression (com.pingcap.tikv.expression.LogicalBinaryExpression)2 StringRegExpression (com.pingcap.tikv.expression.StringRegExpression)2 NormalizedPredicate (com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate)1 DataType (com.pingcap.tikv.types.DataType)1 NormalizedPredicate (org.tikv.common.expression.ComparisonBinaryExpression.NormalizedPredicate)1