Search in sources :

Example 6 with TiExpressionException

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

the class PredicateUtils method expressionToPoints.

/**
 * Turn access conditions into list of points Each condition is bound to single key We pick up
 * single condition for each index key and disregard if multiple EQ conditions in DNF
 *
 * @param pointPredicates expressions that convertible to access points
 * @return access points for each index
 */
private static List<Key> expressionToPoints(List<Expression> pointPredicates, TiTableInfo table, TiIndexInfo index) {
    requireNonNull(pointPredicates, "pointPredicates cannot be null");
    List<Key> resultKeys = new ArrayList<>();
    IndexRangeSetBuilder indexRangeBuilder = new IndexRangeSetBuilder(table, index);
    for (int i = 0; i < pointPredicates.size(); i++) {
        Expression predicate = pointPredicates.get(i);
        try {
            // each expr will be expand to one or more points
            Set<Range<TypedKey>> ranges = indexRangeBuilder.buildRange(predicate).asRanges();
            List<Key> points = rangesToPoint(ranges);
            resultKeys = joinKeys(resultKeys, points);
        } catch (Exception e) {
            throw new TiExpressionException(String.format("Error converting access points %s", predicate), e);
        }
    }
    return resultKeys;
}
Also used : Expression(com.pingcap.tikv.expression.Expression) IndexRangeSetBuilder(com.pingcap.tikv.expression.visitor.IndexRangeSetBuilder) ArrayList(java.util.ArrayList) TiExpressionException(com.pingcap.tikv.exception.TiExpressionException) Range(com.google.common.collect.Range) CompoundKey(com.pingcap.tikv.key.CompoundKey) Key(com.pingcap.tikv.key.Key) TypedKey(com.pingcap.tikv.key.TypedKey) TiExpressionException(com.pingcap.tikv.exception.TiExpressionException)

Example 7 with TiExpressionException

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

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

the class ColumnRef method create.

public static ColumnRef create(String name, TiTableInfo table) {
    name = name.replaceAll("`", "");
    TiColumnInfo col = table.getColumn(name);
    if (col != null) {
        return new ColumnRef(name, col.getType());
    }
    throw new TiExpressionException(String.format("Column name %s not found in table %s", name, table));
}
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