Search in sources :

Example 6 with Expr

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

the class ProtoConverter method visit.

@Override
protected Expr visit(Constant node, Object context) {
    Expr.Builder builder = Expr.newBuilder();
    DataType type = node.getDataType();
    if (node.getValue() == null) {
        builder.setTp(ExprType.Null);
    } else {
        // can mark it cannot be pushed down to coprocessor.
        if (node.isOverflowed()) {
            throw new UnsupportedOperationException("overflowed value cannot be pushed down to coprocessor");
        }
        builder.setTp(type.getProtoExprType());
        CodecDataOutput cdo = new CodecDataOutput();
        type.encode(cdo, EncodeType.PROTO, node.getValue());
        builder.setVal(cdo.toByteString());
        builder.setFieldType(toPBFieldType(getType(node)));
    }
    return builder.build();
}
Also used : Expr(com.pingcap.tidb.tipb.Expr) CodecDataOutput(org.tikv.common.codec.CodecDataOutput)

Example 7 with Expr

use of com.pingcap.tidb.tipb.Expr 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)

Example 8 with Expr

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

the class ProtoConverter method scalarToPartialProto.

// Generate protobuf builder with partial data encoded.
// Scalar Signature is left alone
private Expr.Builder scalarToPartialProto(Expression node, Object context) {
    Expr.Builder builder = Expr.newBuilder();
    // Scalar function type
    builder.setTp(ExprType.ScalarFunc);
    // Return type
    builder.setFieldType(toPBFieldType(getType(node)));
    for (Expression child : node.getChildren()) {
        Expr exprProto = child.accept(this, context);
        builder.addChildren(exprProto);
    }
    return builder;
}
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)

Example 9 with Expr

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

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

Example 10 with Expr

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

the class ProtoConverter method visit.

@Override
protected Expr visit(StringRegExpression node, Object context) {
    // assume after type coerce, children should be compatible
    ScalarFuncSig protoSig;
    switch(node.getRegType()) {
        case STARTS_WITH:
        case CONTAINS:
        case ENDS_WITH:
        case LIKE:
            protoSig = ScalarFuncSig.LikeSig;
            break;
        default:
            throw new TiExpressionException(String.format("Unknown reg type %s", node.getRegType()));
    }
    Expr.Builder builder = scalarToPartialProto(node, context);
    builder.setSig(protoSig);
    return builder.build();
}
Also used : Expr(com.pingcap.tidb.tipb.Expr) FuncCallExpr(com.pingcap.tikv.expression.FuncCallExpr) TiExpressionException(com.pingcap.tikv.exception.TiExpressionException) ScalarFuncSig(com.pingcap.tidb.tipb.ScalarFuncSig)

Aggregations

Expr (com.pingcap.tidb.tipb.Expr)23 ScalarFuncSig (com.pingcap.tidb.tipb.ScalarFuncSig)14 FuncCallExpr (com.pingcap.tikv.expression.FuncCallExpr)11 Expression (com.pingcap.tikv.expression.Expression)5 TiExpressionException (com.pingcap.tikv.exception.TiExpressionException)4 ArithmeticBinaryExpression (com.pingcap.tikv.expression.ArithmeticBinaryExpression)4 ComparisonBinaryExpression (com.pingcap.tikv.expression.ComparisonBinaryExpression)4 LogicalBinaryExpression (com.pingcap.tikv.expression.LogicalBinaryExpression)4 StringRegExpression (com.pingcap.tikv.expression.StringRegExpression)4 TiExpressionException (org.tikv.common.exception.TiExpressionException)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 CodecDataOutput (com.pingcap.tikv.codec.CodecDataOutput)2 DataType (com.pingcap.tikv.types.DataType)2 Map (java.util.Map)2 CodecDataOutput (org.tikv.common.codec.CodecDataOutput)2 ByteString (com.google.protobuf.ByteString)1 FunctionType (com.pingcap.tikv.expression.AggregateFunction.FunctionType)1 ByItem (com.pingcap.tikv.expression.ByItem)1 ColumnRef (com.pingcap.tikv.expression.ColumnRef)1 NormalizedPredicate (com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate)1