-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathTiDBFunctionCall.java
More file actions
170 lines (144 loc) · 4.14 KB
/
TiDBFunctionCall.java
File metadata and controls
170 lines (144 loc) · 4.14 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
package sqlancer.tidb.ast;
import java.util.List;
import sqlancer.Randomly;
public class TiDBFunctionCall implements TiDBExpression {
private TiDBFunction function;
private List<TiDBExpression> args;
// https://pingcap.github.io/docs/stable/reference/sql/functions-and-operators/numeric-functions-and-operators/
public enum TiDBFunction {
POW(2), //
POWER(2), //
EXP(1), //
SQRT(1), //
LN(1), //
LOG(1), //
LOG2(1), //
LOG10(1), //
PI(0), //
TAN(1), //
COT(1), //
SIN(1), //
COS(1), //
ATAN(1), //
ATAN2(2), //
ACOS(1), //
RADIANS(1), //
DEGREES(1), //
MOD(2), //
ABS(1), //
CEIL(1), //
CEILING(1), //
FLOOR(1), //
ROUND(1),
// RAND(1),
SIGN(1), //
// CONV()
// TRUNCATE(),
CRC32(1), //
// https://pingcap.github.io/docs/stable/reference/sql/functions-and-operators/bit-functions-and-operators/
BIT_COUNT(1),
// https://pingcap.github.io/docs/stable/reference/sql/functions-and-operators/information-functions/
CONNECTION_ID(0), //
CURRENT_USER(0), //
DATABASE(0), //
// FOUND_ROWS(0), <-- non-deterministic
// LAST_INSERT_ID(0), <-- non-deterministic
// ROW_COUNT(0), <-- non-deterministic
SCHEMA(0), //
SESSION_USER(0), //
SYSTEM_USER(0), //
USER(0), //
VERSION(0),
TIDB_VERSION(0), //
IF(3), //
IFNULL(2), //
NULLIF(2),
// string functions
ASCII(1), //
BIN(1), //
BIT_LENGTH(1), //
CHAR(1), //
CHAR_LENGTH(1), //
CHARACTER_LENGTH(1), //
CONCAT(1, true), //
CONCAT_WS(2, true), //
ELT(2, true), //
EXPORT_SET(0) {
@Override
public int getNrArgs() {
return Randomly.fromOptions(3, 4, 5);
}
},
// [...]
FIELD(2, true), //
FIND_IN_SET(2), //
FORMAT(2), //
FROM_BASE64(1), //
HEX(1), //
INSERT(4), //
INSTR(2), //
// [...]
REPLACE(3), //
REVERSE(1), //
RIGHT(2), //
// RPAD TODO
RTRIM(1), //
SPACE(1), // https://github.com/tidb-challenge-program/bug-hunting-issue/issues/6
STRCMP(2), //
SUBSTRING(2), // TODO: support other versions
SUBSTRING_INDEX(3), //
TO_BASE64(1), //
TRIM(1), //
UCASE(1), //
UNHEX(1), //
UPPER(1), //
COALESCE(1, true), //
// https://pingcap.github.io/docs/stable/reference/sql/functions-and-operators/miscellaneous-functions/
INET_ATON(1), //
INET_NTOA(1), //
INET6_ATON(1), //
INET6_NTOA(1), //
IS_IPV4(1), //
IS_IPV4_COMPAT(1), //
IS_IPV4_MAPPED(1), //
IS_IPV6(1),
// NAME_CONST(2),
DATE_FORMAT(2), //
// ANY_VALUE(1),
DEFAULT(-1);
private int nrArgs;
private boolean isVariadic;
TiDBFunction(int nrArgs) {
this.nrArgs = nrArgs;
}
TiDBFunction(int nrArgs, boolean isVariadic) {
this.nrArgs = nrArgs;
this.isVariadic = true;
}
public static TiDBFunction getRandom() {
while (true) {
TiDBFunction func = Randomly.fromOptions(values());
if (func.getNrArgs() != -1) {
// special functions that need to be created manually (e.g., DEFAULT)
return func;
}
}
}
public int getNrArgs() {
return nrArgs + (isVariadic() ? Randomly.smallNumber() : 0);
}
public boolean isVariadic() {
return isVariadic;
}
}
public TiDBFunctionCall(TiDBFunction function, List<TiDBExpression> args) {
this.function = function;
this.args = args;
}
public List<TiDBExpression> getArgs() {
return args;
}
public TiDBFunction getFunction() {
return function;
}
}