forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgresPrefixOperation.java
More file actions
108 lines (83 loc) · 3.11 KB
/
PostgresPrefixOperation.java
File metadata and controls
108 lines (83 loc) · 3.11 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package sqlancer.postgres.ast;
import sqlancer.IgnoreMeException;
import sqlancer.ast.BinaryOperatorNode.Operator;
import sqlancer.postgres.PostgresSchema.PostgresDataType;
public class PostgresPrefixOperation implements PostgresExpression {
public enum PrefixOperator implements Operator {
NOT("NOT", PostgresDataType.BOOLEAN) {
@Override
public PostgresDataType getExpressionType() {
return PostgresDataType.BOOLEAN;
}
@Override
protected PostgresConstant getExpectedValue(PostgresConstant expectedValue) {
if (expectedValue.isNull()) {
return PostgresConstant.createNullConstant();
} else {
return PostgresConstant
.createBooleanConstant(!expectedValue.cast(PostgresDataType.BOOLEAN).asBoolean());
}
}
},
UNARY_PLUS("+", PostgresDataType.INT) {
@Override
public PostgresDataType getExpressionType() {
return PostgresDataType.INT;
}
@Override
protected PostgresConstant getExpectedValue(PostgresConstant expectedValue) {
// TODO: actual converts to double precision
return expectedValue;
}
},
UNARY_MINUS("-", PostgresDataType.INT) {
@Override
public PostgresDataType getExpressionType() {
return PostgresDataType.INT;
}
@Override
protected PostgresConstant getExpectedValue(PostgresConstant expectedValue) {
if (expectedValue.isNull()) {
// TODO
throw new IgnoreMeException();
}
return PostgresConstant.createIntConstant(-expectedValue.asInt());
}
};
private String textRepresentation;
private PostgresDataType[] dataTypes;
PrefixOperator(String textRepresentation, PostgresDataType... dataTypes) {
this.textRepresentation = textRepresentation;
this.dataTypes = dataTypes;
}
public abstract PostgresDataType getExpressionType();
protected abstract PostgresConstant getExpectedValue(PostgresConstant expectedValue);
@Override
public String getTextRepresentation() {
return toString();
}
}
private final PostgresExpression expr;
private final PrefixOperator op;
public PostgresPrefixOperation(PostgresExpression expr, PrefixOperator op) {
this.expr = expr;
this.op = op;
}
@Override
public PostgresDataType getExpressionType() {
return op.getExpressionType();
}
@Override
public PostgresConstant getExpectedValue() {
return op.getExpectedValue(expr.getExpectedValue());
}
public PostgresDataType[] getInputDataTypes() {
return op.dataTypes;
}
public String getTextRepresentation() {
return op.textRepresentation;
}
public PostgresExpression getExpression() {
return expr;
}
}