Search in sources :

Example 11 with Expr

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

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

the class ProtoConverter method visit.

@Override
@SuppressWarnings("unchecked")
protected Expr visit(ColumnRef node, Object context) {
    long position = 0;
    if (validateColPosition) {
        requireNonNull(context, "Context of a ColumnRef should not be null");
        Map<String, Integer> colIdOffsetMap = (Map<String, Integer>) context;
        position = requireNonNull(colIdOffsetMap.get(node.getName()), "Required column position info " + node.getName() + " is not in a valid context.");
    }
    Expr.Builder builder = Expr.newBuilder();
    builder.setTp(ExprType.ColumnRef);
    CodecDataOutput cdo = new CodecDataOutput();
    // After switching to DAG request mode, expression value
    // should be the index of table columns we provided in
    // the first executor of a DAG request.
    IntegerCodec.writeLong(cdo, position);
    builder.setVal(cdo.toByteString());
    builder.setFieldType(toPBFieldType(getType(node)));
    return builder.build();
}
Also used : Expr(com.pingcap.tidb.tipb.Expr) FuncCallExpr(com.pingcap.tikv.expression.FuncCallExpr) CodecDataOutput(com.pingcap.tikv.codec.CodecDataOutput) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 13 with Expr

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

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

Example 14 with Expr

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

Example 15 with Expr

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

the class ProtoConverter method visit.

@Override
protected Expr visit(AggregateFunction node, Object context) {
    Expr.Builder builder = Expr.newBuilder();
    FunctionType type = node.getType();
    switch(type) {
        case Max:
            builder.setTp(ExprType.Max);
            break;
        case Sum:
            builder.setTp(ExprType.Sum);
            break;
        case Min:
            builder.setTp(ExprType.Min);
            break;
        case First:
            builder.setTp(ExprType.First);
            break;
        case Count:
            builder.setTp(ExprType.Count);
            break;
    }
    for (Expression arg : node.getChildren()) {
        Expr exprProto = arg.accept(this, context);
        builder.addChildren(exprProto);
    }
    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) FunctionType(com.pingcap.tikv.expression.AggregateFunction.FunctionType)

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