forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDorisLikeOperation.java
More file actions
84 lines (70 loc) · 2.78 KB
/
DorisLikeOperation.java
File metadata and controls
84 lines (70 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package sqlancer.doris.ast;
import sqlancer.LikeImplementationHelper;
import sqlancer.Randomly;
import sqlancer.common.ast.BinaryOperatorNode;
import sqlancer.common.ast.newast.NewBinaryOperatorNode;
import sqlancer.doris.DorisSchema.DorisDataType;
public class DorisLikeOperation extends NewBinaryOperatorNode<DorisExpression> implements DorisExpression {
public DorisLikeOperation(DorisExpression left, DorisExpression right, DorisLikeOperator op) {
super(left, right, op);
}
@Override
public DorisDataType getExpectedType() {
return DorisDataType.BOOLEAN;
}
public DorisExpression getLeftExpr() {
return super.getLeft();
}
public DorisExpression getRightExpr() {
return super.getRight();
}
public DorisLikeOperator getOp() {
return (DorisLikeOperator) op;
}
@Override
public DorisConstant getExpectedValue() {
DorisConstant leftVal = getLeftExpr().getExpectedValue();
DorisConstant rightVal = getRightExpr().getExpectedValue();
if (leftVal == null || rightVal == null) {
return null;
}
return getOp().apply(leftVal, rightVal);
}
public enum DorisLikeOperator implements BinaryOperatorNode.Operator {
LIKE_OPERATOR("LIKE", "like") {
@Override
public DorisConstant apply(DorisConstant left, DorisConstant right) {
if (left == null || right == null) {
return null;
}
if (left.isNull() || right.isNull()) {
return DorisConstant.createNullConstant();
}
boolean result = LikeImplementationHelper.match(left.asString(), right.asString(), 0, 0, true);
return DorisConstant.createBooleanConstant(result);
}
},
NOT_LIKE("NOT LIKE", "not like") {
@Override
public DorisConstant apply(DorisConstant left, DorisConstant right) {
if (left == null || right == null) {
return null;
}
if (left.isNull() || right.isNull()) {
return DorisConstant.createNullConstant();
}
boolean result = LikeImplementationHelper.match(left.asString(), right.asString(), 0, 0, true);
return DorisConstant.createBooleanConstant(!result);
}
};
private final String[] textRepresentations;
DorisLikeOperator(String... text) {
textRepresentations = text.clone();
}
public abstract DorisConstant apply(DorisConstant left, DorisConstant right);
@Override
public String getTextRepresentation() {
return " " + Randomly.fromOptions(textRepresentations) + " ";
}
}
}