use of com.pingcap.tikv.expression.ComparisonBinaryExpression 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();
}
use of com.pingcap.tikv.expression.ComparisonBinaryExpression in project tispark by pingcap.
the class PartAndFilterExprRewriter method visit.
@Override
public Expression visit(ComparisonBinaryExpression node, Void context) {
NormalizedPredicate predicate = node.normalize();
// predicate maybe null if node's left or right does not have a column ref or a constant.
if (predicate != null) {
if (!columnRefs.contains(predicate.getColumnRef())) {
return node;
}
// we only support year for now.
if (isYear()) {
FuncCallExpr year = new FuncCallExpr(predicate.getValue(), Type.YEAR);
Constant newLiteral = year.eval(predicate.getValue());
return new ComparisonBinaryExpression(node.getComparisonType(), node.getLeft(), newLiteral);
} else if (isColumnRef()) {
return node;
}
unsupportedPartFnFound = true;
return null;
}
// when we find a node in form like [year(y) < 1995], we need rewrite the left child.
Expression left = node.getLeft().accept(this, null);
Expression right = node.getRight().accept(this, null);
return new ComparisonBinaryExpression(node.getComparisonType(), left, right);
}
Aggregations