forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCnosDBCastOperation.java
More file actions
60 lines (48 loc) · 1.53 KB
/
CnosDBCastOperation.java
File metadata and controls
60 lines (48 loc) · 1.53 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
package sqlancer.cnosdb.ast;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import sqlancer.cnosdb.CnosDBCompoundDataType;
import sqlancer.cnosdb.CnosDBSchema.CnosDBDataType;
public class CnosDBCastOperation implements CnosDBExpression {
private final CnosDBExpression expression;
private final CnosDBCompoundDataType type;
public CnosDBCastOperation(CnosDBExpression expression, CnosDBCompoundDataType type) {
if (expression == null) {
throw new AssertionError();
}
this.expression = expression;
this.type = type;
}
public static List<CnosDBDataType> canCastTo(CnosDBDataType dataType) {
List<CnosDBDataType> options = new ArrayList<>(Arrays.asList(CnosDBDataType.values()));
switch (dataType) {
case UINT:
case BOOLEAN:
case DOUBLE:
options.remove(CnosDBDataType.TIMESTAMP);
break;
case TIMESTAMP:
options.remove(CnosDBDataType.BOOLEAN);
options.remove(CnosDBDataType.UINT);
options.remove(CnosDBDataType.DOUBLE);
break;
default:
break;
}
return options;
}
@Override
public CnosDBDataType getExpressionType() {
return type.getDataType();
}
public CnosDBExpression getExpression() {
return expression;
}
public CnosDBDataType getType() {
return type.getDataType();
}
public CnosDBCompoundDataType getCompoundType() {
return type;
}
}