forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYSQLSelect.java
More file actions
145 lines (112 loc) · 3.56 KB
/
YSQLSelect.java
File metadata and controls
145 lines (112 loc) · 3.56 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
package sqlancer.yugabyte.ysql.ast;
import java.util.Collections;
import java.util.List;
import sqlancer.Randomly;
import sqlancer.common.ast.SelectBase;
import sqlancer.common.ast.newast.Select;
import sqlancer.yugabyte.ysql.YSQLSchema.YSQLColumn;
import sqlancer.yugabyte.ysql.YSQLSchema.YSQLDataType;
import sqlancer.yugabyte.ysql.YSQLSchema.YSQLTable;
import sqlancer.yugabyte.ysql.YSQLVisitor;
public class YSQLSelect extends SelectBase<YSQLExpression>
implements YSQLExpression, Select<YSQLJoin, YSQLExpression, YSQLTable, YSQLColumn> {
private SelectType selectOption = SelectType.ALL;
private List<YSQLJoin> joinClauses = Collections.emptyList();
private YSQLExpression distinctOnClause;
private ForClause forClause;
public void setSelectType(SelectType fromOptions) {
this.setSelectOption(fromOptions);
}
public SelectType getSelectOption() {
return selectOption;
}
public void setSelectOption(SelectType fromOptions) {
this.selectOption = fromOptions;
}
@Override
public YSQLDataType getExpressionType() {
return null;
}
@Override
public List<YSQLJoin> getJoinClauses() {
return joinClauses;
}
@Override
public void setJoinClauses(List<YSQLJoin> joinStatements) {
this.joinClauses = joinStatements;
}
public YSQLExpression getDistinctOnClause() {
return distinctOnClause;
}
public void setDistinctOnClause(YSQLExpression distinctOnClause) {
if (selectOption != SelectType.DISTINCT) {
throw new IllegalArgumentException();
}
this.distinctOnClause = distinctOnClause;
}
public ForClause getForClause() {
return forClause;
}
public void setForClause(ForClause forClause) {
this.forClause = forClause;
}
public enum ForClause {
UPDATE("UPDATE"), NO_KEY_UPDATE("NO KEY UPDATE"), SHARE("SHARE"), KEY_SHARE("KEY SHARE");
private final String textRepresentation;
ForClause(String textRepresentation) {
this.textRepresentation = textRepresentation;
}
public static ForClause getRandom() {
return Randomly.fromOptions(values());
}
public String getTextRepresentation() {
return textRepresentation;
}
}
public enum SelectType {
DISTINCT, ALL;
public static SelectType getRandom() {
return Randomly.fromOptions(values());
}
}
public static class YSQLFromTable implements YSQLExpression {
private final YSQLTable t;
private final boolean only;
public YSQLFromTable(YSQLTable t, boolean only) {
this.t = t;
this.only = only;
}
public YSQLTable getTable() {
return t;
}
public boolean isOnly() {
return only;
}
@Override
public YSQLDataType getExpressionType() {
return null;
}
}
public static class YSQLSubquery implements YSQLExpression {
private final YSQLSelect s;
private final String name;
public YSQLSubquery(YSQLSelect s, String name) {
this.s = s;
this.name = name;
}
public YSQLSelect getSelect() {
return s;
}
public String getName() {
return name;
}
@Override
public YSQLDataType getExpressionType() {
return null;
}
}
@Override
public String asString() {
return YSQLVisitor.asString(this);
}
}