Search in sources :

Example 1 with TiExpressionException

use of com.pingcap.tikv.exception.TiExpressionException 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 2 with TiExpressionException

use of com.pingcap.tikv.exception.TiExpressionException in project tispark by pingcap.

the class ProtoConverter method getTypeSignature.

private String getTypeSignature(Expression expression) {
    DataType type = getType(expression);
    String typeSignature = SCALAR_SIG_MAP.get(type.getClass());
    if (typeSignature == null) {
        throw new TiExpressionException(String.format("Type %s signature unknown", type));
    }
    return typeSignature;
}
Also used : DataType(com.pingcap.tikv.types.DataType) TiExpressionException(com.pingcap.tikv.exception.TiExpressionException)

Example 3 with TiExpressionException

use of com.pingcap.tikv.exception.TiExpressionException 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)

Example 4 with TiExpressionException

use of com.pingcap.tikv.exception.TiExpressionException 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 5 with TiExpressionException

use of com.pingcap.tikv.exception.TiExpressionException in project tispark by pingcap.

the class ColumnRef method resolve.

public void resolve(TiTableInfo table) {
    TiColumnInfo columnInfo = null;
    for (TiColumnInfo col : table.getColumns()) {
        if (col.matchName(name)) {
            this.dataType = col.getType();
            columnInfo = col;
            break;
        }
    }
    if (columnInfo == null) {
        throw new TiExpressionException(String.format("No Matching column %s from table %s", name, table.getName()));
    }
    if (columnInfo.getId() == 0) {
        throw new TiExpressionException("Zero Id is not a referable column id");
    }
}
Also used : TiExpressionException(com.pingcap.tikv.exception.TiExpressionException) TiColumnInfo(com.pingcap.tikv.meta.TiColumnInfo)

Aggregations

TiExpressionException (com.pingcap.tikv.exception.TiExpressionException)8 Expr (com.pingcap.tidb.tipb.Expr)4 ScalarFuncSig (com.pingcap.tidb.tipb.ScalarFuncSig)4 FuncCallExpr (com.pingcap.tikv.expression.FuncCallExpr)4 Expression (com.pingcap.tikv.expression.Expression)3 ArithmeticBinaryExpression (com.pingcap.tikv.expression.ArithmeticBinaryExpression)2 ComparisonBinaryExpression (com.pingcap.tikv.expression.ComparisonBinaryExpression)2 LogicalBinaryExpression (com.pingcap.tikv.expression.LogicalBinaryExpression)2 StringRegExpression (com.pingcap.tikv.expression.StringRegExpression)2 TiColumnInfo (com.pingcap.tikv.meta.TiColumnInfo)2 Range (com.google.common.collect.Range)1 NormalizedPredicate (com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate)1 IndexRangeSetBuilder (com.pingcap.tikv.expression.visitor.IndexRangeSetBuilder)1 CompoundKey (com.pingcap.tikv.key.CompoundKey)1 Key (com.pingcap.tikv.key.Key)1 TypedKey (com.pingcap.tikv.key.TypedKey)1 DataType (com.pingcap.tikv.types.DataType)1 ArrayList (java.util.ArrayList)1