Skip to content

Commit 2f6c566

Browse files
committed
Move the join list into the abstract select base class
1 parent 8272168 commit 2f6c566

10 files changed

Lines changed: 22 additions & 49 deletions

src/sqlancer/ast/SelectBase.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class SelectBase<T> {
88
List<T> fetchColumns;
99
List<T> groupByExpressions = Collections.emptyList();
1010
List<T> orderByExpressions = Collections.emptyList();
11+
List<T> joinList = Collections.emptyList();
1112
List<T> fromList;
1213
T whereClause;
1314
T havingClause;
@@ -97,5 +98,13 @@ public void setOffsetClause(T offsetClause) {
9798
public T getOffsetClause() {
9899
return offsetClause;
99100
}
101+
102+
public List<T> getJoinList() {
103+
return joinList;
104+
}
105+
106+
public void setJoinList(List<T> joinList) {
107+
this.joinList = joinList;
108+
}
100109

101110
}
Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package sqlancer.cockroachdb.ast;
22

3-
import java.util.Collections;
4-
import java.util.List;
5-
63
import sqlancer.ast.SelectBase;
74

85
public class CockroachDBSelect extends SelectBase<CockroachDBExpression> implements CockroachDBExpression {
96

107
private boolean isDistinct;
11-
private List<CockroachDBJoin> joinList = Collections.emptyList();
12-
138

149
public boolean isDistinct() {
1510
return isDistinct;
@@ -19,12 +14,4 @@ public void setDistinct(boolean isDistinct) {
1914
this.isDistinct = isDistinct;
2015
}
2116

22-
public List<CockroachDBJoin> getJoinList() {
23-
return joinList;
24-
}
25-
26-
public void setJoinList(List<CockroachDBJoin> joinList) {
27-
this.joinList = joinList;
28-
}
29-
3017
}

src/sqlancer/cockroachdb/test/CockroachDBNoRECTester.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void check() throws SQLException {
5454
.collect(Collectors.toList());
5555
List<CockroachDBExpression> tableList = CockroachDBCommon.getTableReferences(tableL);
5656
gen = new CockroachDBExpressionGenerator(globalState).setColumns(tables.getColumns());
57-
List<CockroachDBJoin> joinExpressions = getJoins(tableList, globalState);
57+
List<CockroachDBExpression> joinExpressions = getJoins(tableList, globalState);
5858
CockroachDBExpression whereCondition = gen.generateExpression(CockroachDBDataType.BOOL.get());
5959
CockroachDBExpression havingCondition = null;
6060
if (Randomly.getBoolean()) {
@@ -76,9 +76,9 @@ public void check() throws SQLException {
7676
}
7777
}
7878

79-
public static List<CockroachDBJoin> getJoins(List<CockroachDBExpression> tableList,
79+
public static List<CockroachDBExpression> getJoins(List<CockroachDBExpression> tableList,
8080
CockroachDBGlobalState globalState) throws AssertionError {
81-
List<CockroachDBJoin> joinExpressions = new ArrayList<>();
81+
List<CockroachDBExpression> joinExpressions = new ArrayList<>();
8282
while (tableList.size() >= 2 && Randomly.getBoolean()) {
8383
CockroachDBTableReference leftTable = (CockroachDBTableReference) tableList.remove(0);
8484
CockroachDBTableReference rightTable = (CockroachDBTableReference) tableList.remove(0);
@@ -110,7 +110,7 @@ public static List<CockroachDBJoin> getJoins(List<CockroachDBExpression> tableLi
110110

111111
private int getOptimizableResult(Connection con, CockroachDBExpression whereCondition,
112112
CockroachDBExpression havingCondition, List<CockroachDBExpression> tableList, Set<String> errors,
113-
List<CockroachDBJoin> joinExpressions) throws SQLException {
113+
List<CockroachDBExpression> joinExpressions) throws SQLException {
114114
CockroachDBSelect select = new CockroachDBSelect();
115115
CockroachDBColumn c = new CockroachDBColumn("COUNT(*)", null, false, false);
116116
select.setFetchColumns(Arrays.asList(new CockroachDBColumnReference(c)));
@@ -131,7 +131,7 @@ private int getOptimizableResult(Connection con, CockroachDBExpression whereCond
131131

132132
private int getNonOptimizedResult(Connection con, CockroachDBExpression whereCondition,
133133
CockroachDBExpression havingCondition, List<CockroachDBExpression> tableList, Set<String> errors,
134-
List<CockroachDBJoin> joinList) throws SQLException {
134+
List<CockroachDBExpression> joinList) throws SQLException {
135135
String fromString = tableList.stream().map(t -> ((CockroachDBTableReference) t).getTable().getName()).collect(Collectors.joining(", "));
136136
if (!tableList.isEmpty() && !joinList.isEmpty()) {
137137
fromString += ", ";

src/sqlancer/cockroachdb/test/CockroachDBQueryPartitioningAggregateTester.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import sqlancer.cockroachdb.ast.CockroachDBAlias;
2929
import sqlancer.cockroachdb.ast.CockroachDBCast;
3030
import sqlancer.cockroachdb.ast.CockroachDBExpression;
31-
import sqlancer.cockroachdb.ast.CockroachDBJoin;
3231
import sqlancer.cockroachdb.ast.CockroachDBNotOperation;
3332
import sqlancer.cockroachdb.ast.CockroachDBSelect;
3433
import sqlancer.cockroachdb.ast.CockroachDBTableReference;
@@ -185,7 +184,7 @@ private String getOuterAggregateFunction(CockroachDBAggregate aggregate) {
185184
}
186185

187186
private CockroachDBSelect getSelect(List<CockroachDBExpression> aggregates, List<CockroachDBExpression> from,
188-
CockroachDBExpression whereClause, List<CockroachDBJoin> joinList) {
187+
CockroachDBExpression whereClause, List<CockroachDBExpression> joinList) {
189188
CockroachDBSelect leftSelect = new CockroachDBSelect();
190189
leftSelect.setFetchColumns(aggregates);
191190
leftSelect.setFromList(from);

src/sqlancer/mysql/MySQLExpectedValueVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import sqlancer.mysql.ast.MySQLUnaryPostfixOperation;
2222
import sqlancer.mysql.ast.MySQLUnaryPrefixOperation;
2323

24-
public class MySQLExpectedValueVisitor extends MySQLVisitor {
24+
public class MySQLExpectedValueVisitor implements MySQLVisitor {
2525

2626
private final StringBuilder sb = new StringBuilder();
2727
private int nrTabs = 0;
@@ -91,7 +91,7 @@ public String get() {
9191

9292
@Override
9393
public void visit(MySQLSelect select) {
94-
for (MySQLJoin j : select.getJoinClauses()) {
94+
for (MySQLJoin j : select.getJoinList()) {
9595
visit(j);
9696
}
9797
if (select.getWhereClause() != null) {

src/sqlancer/mysql/MySQLToStringVisitor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import sqlancer.mysql.ast.MySQLExists;
1717
import sqlancer.mysql.ast.MySQLExpression;
1818
import sqlancer.mysql.ast.MySQLInOperation;
19-
import sqlancer.mysql.ast.MySQLJoin;
2019
import sqlancer.mysql.ast.MySQLOrderByTerm;
2120
import sqlancer.mysql.ast.MySQLOrderByTerm.MySQLOrder;
2221
import sqlancer.mysql.ast.MySQLSelect;
@@ -75,7 +74,7 @@ public void visit(MySQLSelect s) {
7574
}
7675
visit(s.getFromList().get(i));
7776
}
78-
for (MySQLJoin j : s.getJoinClauses()) {
77+
for (MySQLExpression j : s.getJoinList()) {
7978
visit(j);
8079
}
8180

src/sqlancer/mysql/ast/MySQLSelect.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
public class MySQLSelect extends SelectBase<MySQLExpression> implements MySQLExpression {
99

1010
private SelectType fromOptions = SelectType.ALL;
11-
private List<MySQLJoin> joinStatements = Collections.emptyList();
1211
private List<String> modifiers = Collections.emptyList();
1312

1413
public enum SelectType {
@@ -27,14 +26,6 @@ public void setFromOptions(SelectType fromOptions) {
2726
this.fromOptions = fromOptions;
2827
}
2928

30-
public void setJoinClauses(List<MySQLJoin> joinStatements) {
31-
this.joinStatements = joinStatements;
32-
}
33-
34-
public List<MySQLJoin> getJoinClauses() {
35-
return joinStatements;
36-
}
37-
3829
public void setModifiers(List<String> modifiers) {
3930
this.modifiers = modifiers;
4031
}

src/sqlancer/tidb/ast/TiDBSelect.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
package sqlancer.tidb.ast;
22

3-
import java.util.Collections;
4-
import java.util.List;
5-
63
import sqlancer.ast.SelectBase;
74

85
public class TiDBSelect extends SelectBase<TiDBExpression> implements TiDBExpression {
96

10-
private List<TiDBExpression> joinExpressions = Collections.emptyList();
117
private TiDBExpression hint;
128

13-
public void setJoins(List<TiDBExpression> joinExpressions) {
14-
this.joinExpressions = joinExpressions;
15-
}
16-
17-
public List<TiDBExpression> getJoinExpressions() {
18-
return joinExpressions;
19-
}
20-
219
public void setHint(TiDBExpression hint) {
2210
this.hint = hint;
2311
}

src/sqlancer/tidb/test/TiDBQueryPartitioningBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void check() throws SQLException {
5959
List<TiDBExpression> tableList = tables.stream().map(t -> new TiDBTableReference(t))
6060
.collect(Collectors.toList());
6161
List<TiDBExpression> joins = TiDBJoin.getJoins(tableList, state);
62-
select.setJoins(joins);
62+
select.setJoinList(joins);
6363
select.setFromList(tableList);
6464
select.setWhereClause(null);
6565
predicate = generatePredicate();

src/sqlancer/tidb/visitor/TiDBToStringVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ public void visit(TiDBSelect select) {
5555
visit(select.getFetchColumns());
5656
sb.append(" FROM ");
5757
visit(select.getFromList());
58-
if (!select.getFromList().isEmpty() && !select.getJoinExpressions().isEmpty()) {
58+
if (!select.getFromList().isEmpty() && !select.getJoinList().isEmpty()) {
5959
sb.append(", ");
6060
}
61-
if (!select.getJoinExpressions().isEmpty()) {
62-
visit(select.getJoinExpressions());
61+
if (!select.getJoinList().isEmpty()) {
62+
visit(select.getJoinList());
6363
}
6464
if (select.getWhereClause() != null) {
6565
sb.append(" WHERE ");

0 commit comments

Comments
 (0)