forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabendLikeOperation.java
More file actions
62 lines (49 loc) · 1.9 KB
/
DatabendLikeOperation.java
File metadata and controls
62 lines (49 loc) · 1.9 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
package sqlancer.databend.ast;
import sqlancer.LikeImplementationHelper;
import sqlancer.Randomly;
import sqlancer.common.ast.BinaryOperatorNode;
import sqlancer.common.ast.newast.NewBinaryOperatorNode;
import sqlancer.databend.DatabendSchema.DatabendDataType;
public class DatabendLikeOperation extends NewBinaryOperatorNode<DatabendExpression> implements DatabendExpression {
public DatabendLikeOperation(DatabendExpression left, DatabendExpression right, DatabendLikeOperator op) {
super(left, right, op);
}
@Override
public DatabendDataType getExpectedType() {
return DatabendDataType.BOOLEAN;
}
public DatabendExpression getLeftExpr() {
return super.getLeft();
}
public DatabendExpression getRightExpr() {
return super.getRight();
}
public DatabendLikeOperator getOp() {
return (DatabendLikeOperator) op;
}
@Override
public DatabendConstant getExpectedValue() {
DatabendConstant leftVal = getLeftExpr().getExpectedValue();
DatabendConstant rightVal = getRightExpr().getExpectedValue();
if (leftVal == null || rightVal == null) {
return null;
}
if (leftVal.isNull() || rightVal.isNull()) {
return DatabendConstant.createNullConstant();
} else {
boolean result = LikeImplementationHelper.match(leftVal.asString(), rightVal.asString(), 0, 0, true);
return DatabendConstant.createBooleanConstant(result);
}
}
public enum DatabendLikeOperator implements BinaryOperatorNode.Operator {
LIKE_OPERATOR("LIKE", "like");
private final String[] textRepresentations;
DatabendLikeOperator(String... text) {
textRepresentations = text.clone();
}
@Override
public String getTextRepresentation() {
return Randomly.fromOptions(textRepresentations);
}
}
}