forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClickHouseExpression.java
More file actions
187 lines (148 loc) · 5.78 KB
/
ClickHouseExpression.java
File metadata and controls
187 lines (148 loc) · 5.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package sqlancer.clickhouse.ast;
import sqlancer.clickhouse.ClickHouseSchema.ClickHouseColumn;
import sqlancer.clickhouse.ClickHouseSchema.ClickHouseTable;
import sqlancer.common.ast.newast.Expression;
import sqlancer.common.ast.newast.Join;
import sqlancer.common.visitor.BinaryOperation;
import sqlancer.common.visitor.UnaryOperation;
public abstract class ClickHouseExpression implements Expression<ClickHouseColumn> {
public ClickHouseConstant getExpectedValue() {
return null;
}
public enum TypeAffinity {
NOTHING, UINT8, UINT16, UINT32, UINT64, UINT128, INT8, INT16, INT32, INT64, INT128, FLOAT32, FLOAT64, DATE,
DATETIME, DATETIME64, STRING, FIXEDSTRING, ENUM8, ENUM16, DECIMAL32, DECIMAL64, DECIMAL128, UUID, ARRAY, TUPLE,
SET, INTERVAL;
// NULLABLE, FUNCTION, AGGREGATEFUNCTION, LOWCARDINALITY;
public boolean isNumeric() {
return this == UINT8 || this == UINT16 || this == UINT32 || this == UINT64 || this == UINT128
|| this == INT8 || this == INT16 || this == INT32 || this == INT64 || this == INT128
|| this == FLOAT32 || this == FLOAT64;
}
}
public static class ClickHouseExist extends ClickHouseExpression {
private final ClickHouseExpression select;
public ClickHouseExist(ClickHouseExpression select) {
this.select = select;
}
public ClickHouseExpression getExpression() {
return select;
}
}
public static class ClickHouseJoinOnClause extends ClickHouseExpression
implements BinaryOperation<ClickHouseExpression> {
private final ClickHouseExpression left;
private final ClickHouseExpression right;
public ClickHouseJoinOnClause(ClickHouseExpression left, ClickHouseExpression right) {
this.left = left;
this.right = right;
}
@Override
public final ClickHouseExpression getLeft() {
return this.left;
}
@Override
public final ClickHouseExpression getRight() {
return this.right;
}
@Override
public String getOperatorRepresentation() {
return "=";
}
}
public static class ClickHouseJoin extends ClickHouseExpression
implements Join<ClickHouseExpression, ClickHouseTable, ClickHouseColumn> {
// TODO: support ANY, ALL, ASOF modifiers
// LEFT_SEMI, RIGHT_SEMI are not deterministic as ClickHouse allows to read columns from
// whitelist table as well
public enum JoinType {
INNER, CROSS, LEFT_OUTER, RIGHT_OUTER, FULL_OUTER, LEFT_ANTI, RIGHT_ANTI;
}
private final ClickHouseTableReference leftTable;
private final ClickHouseTableReference rightTable;
private ClickHouseExpression onClause;
private final ClickHouseJoin.JoinType type;
public ClickHouseJoin(ClickHouseTableReference leftTable, ClickHouseTableReference rightTable,
ClickHouseJoin.JoinType type, ClickHouseJoinOnClause onClause) {
this.leftTable = leftTable;
this.rightTable = rightTable;
this.onClause = onClause;
this.type = type;
}
public ClickHouseJoin(ClickHouseTableReference leftTable, ClickHouseTableReference rightTable,
ClickHouseJoin.JoinType type) {
this.leftTable = leftTable;
this.rightTable = rightTable;
if (type != ClickHouseJoin.JoinType.CROSS) {
throw new AssertionError();
}
this.onClause = null;
this.type = type;
}
public ClickHouseTableReference getLeftTable() {
return leftTable;
}
public ClickHouseTableReference getRightTable() {
return rightTable;
}
public ClickHouseExpression getOnClause() {
return onClause;
}
public ClickHouseJoin.JoinType getType() {
return type;
}
@Override
public void setOnClause(ClickHouseExpression onClause) {
this.onClause = onClause;
}
}
public static class ClickHouseSubquery extends ClickHouseExpression {
private final String query;
public ClickHouseSubquery(String query) {
this.query = query;
}
public static ClickHouseExpression create(String query) {
return new ClickHouseSubquery(query);
}
public String getQuery() {
return query;
}
}
public static class ClickHousePostfixText extends ClickHouseExpression
implements UnaryOperation<ClickHouseExpression> {
private final ClickHouseExpression expr;
private final String text;
private ClickHouseConstant expectedValue;
public ClickHousePostfixText(ClickHouseExpression expr, String text, ClickHouseConstant expectedValue) {
this.expr = expr;
this.text = text;
this.expectedValue = expectedValue;
}
public ClickHousePostfixText(String text, ClickHouseConstant expectedValue) {
this(null, text, expectedValue);
}
public String getText() {
return text;
}
@Override
public ClickHouseConstant getExpectedValue() {
return expectedValue;
}
@Override
public ClickHouseExpression getExpression() {
return expr;
}
@Override
public String getOperatorRepresentation() {
return getText();
}
@Override
public OperatorKind getOperatorKind() {
return OperatorKind.POSTFIX;
}
@Override
public boolean omitBracketsWhenPrinting() {
return true;
}
}
}