Search in sources :

Example 16 with Expr

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

the class ProtoConverter method visit.

@Override
protected Expr visit(IsNull node, Object context) {
    String typeSignature = getTypeSignature(node.getExpression());
    ScalarFuncSig protoSig = ScalarFuncSig.valueOf(typeSignature + "IsNull");
    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 17 with Expr

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

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) FuncCallExpr(com.pingcap.tikv.expression.FuncCallExpr) DataType(com.pingcap.tikv.types.DataType) CodecDataOutput(com.pingcap.tikv.codec.CodecDataOutput)

Example 18 with Expr

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

the class TiDAGRequestTest method selectRequestEquals.

private static boolean selectRequestEquals(TiDAGRequest lhs, TiDAGRequest rhs) {
    assertEquals(lhs.getFields().size(), rhs.getFields().size());
    Map<String, Integer> lhsMap = new HashMap<>();
    Map<String, Integer> rhsMap = new HashMap<>();
    for (int i = 0; i < lhs.getFields().size(); i++) {
        ColumnRef lCol = lhs.getFields().get(i);
        ColumnRef rCol = rhs.getFields().get(i);
        lhsMap.put(lCol.getName(), i);
        rhsMap.put(rCol.getName(), i);
    }
    for (int i = 0; i < lhs.getFields().size(); i++) {
        Expression lhsExpr = lhs.getFields().get(i);
        Expression rhsExpr = rhs.getFields().get(i);
        Expr lhsExprProto = ProtoConverter.toProto(lhsExpr, lhsMap);
        Expr rhsExprProto = ProtoConverter.toProto(rhsExpr, rhsMap);
        if (!lhsExprProto.equals(rhsExprProto))
            return false;
    }
    assertEquals(lhs.getAggregates().size(), rhs.getAggregates().size());
    for (int i = 0; i < lhs.getAggregates().size(); i++) {
        Expression lhsExpr = lhs.getAggregates().get(i);
        Expression rhsExpr = rhs.getAggregates().get(i);
        Expr lhsExprProto = ProtoConverter.toProto(lhsExpr, lhsMap);
        Expr rhsExprProto = ProtoConverter.toProto(rhsExpr, rhsMap);
        if (!lhsExprProto.equals(rhsExprProto))
            return false;
    }
    assertEquals(lhs.getGroupByItems().size(), rhs.getGroupByItems().size());
    for (int i = 0; i < lhs.getGroupByItems().size(); i++) {
        ByItem lhsItem = lhs.getGroupByItems().get(i);
        ByItem rhsItem = rhs.getGroupByItems().get(i);
        if (!lhsItem.toProto(lhsMap).equals(rhsItem.toProto(rhsMap)))
            return false;
    }
    assertEquals(lhs.getOrderByItems().size(), rhs.getOrderByItems().size());
    for (int i = 0; i < lhs.getOrderByItems().size(); i++) {
        ByItem lhsItem = lhs.getOrderByItems().get(i);
        ByItem rhsItem = rhs.getOrderByItems().get(i);
        if (!lhsItem.toProto(lhsMap).equals(rhsItem.toProto(rhsMap)))
            return false;
    }
    assertEquals(lhs.getRangesMaps().size(), rhs.getRangesMaps().size());
    assertEquals(lhs.getRangesMaps(), rhs.getRangesMaps());
    assertEquals(lhs.getFilters().size(), rhs.getFilters().size());
    for (int i = 0; i < lhs.getFilters().size(); i++) {
        Expression lhsItem = lhs.getFilters().get(i);
        Expression rhsItem = rhs.getFilters().get(i);
        Expr lhsExprProto = ProtoConverter.toProto(lhsItem);
        Expr rhsExprProto = ProtoConverter.toProto(rhsItem);
        if (!lhsExprProto.equals(rhsExprProto))
            return false;
    }
    assertEquals(lhs.getTableInfo().toProto(), rhs.getTableInfo().toProto());
    assertEquals(lhs.getLimit(), rhs.getLimit());
    assertEquals(lhs.isDistinct(), rhs.isDistinct());
    assertEquals(lhs.getIndexInfo().toProto(lhs.getTableInfo()), rhs.getIndexInfo().toProto(rhs.getTableInfo()));
    assertEquals(lhs.getStartTs(), rhs.getStartTs());
    assertEquals(lhs.getTimeZoneOffset(), rhs.getTimeZoneOffset());
    assertEquals(lhs.getFlags(), rhs.getFlags());
    return true;
}
Also used : ByItem(com.pingcap.tikv.expression.ByItem) Expr(com.pingcap.tidb.tipb.Expr) HashMap(java.util.HashMap) Expression(com.pingcap.tikv.expression.Expression) ByteString(com.google.protobuf.ByteString) ColumnRef(com.pingcap.tikv.expression.ColumnRef)

Example 19 with Expr

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

the class ProtoConverter method visit.

@Override
protected Expr visit(IsNull node, Object context) {
    String typeSignature = getTypeSignature(node.getExpression());
    ScalarFuncSig protoSig = ScalarFuncSig.valueOf(typeSignature + "IsNull");
    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 20 with Expr

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

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) CodecDataOutput(org.tikv.common.codec.CodecDataOutput) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

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