Skip to content

Commit d96e49f

Browse files
authored
Merge pull request #1000 from malwaregarry/tlp-citus
[Citus] Use common TLP Where oracle
2 parents de77ce2 + c234b11 commit d96e49f

3 files changed

Lines changed: 32 additions & 46 deletions

File tree

src/sqlancer/citus/gen/CitusCommon.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public static List<String> getCitusErrors() {
5454
errors.add("unlogged columnar tables are not supported");
5555
errors.add("UPDATE and CTID scans not supported for ColumnarScan");
5656
errors.add("indexes not supported for columnar tables");
57+
errors.add("invalid byte sequence for encoding \"UTF8\": 0x00");
58+
errors.add("columnar_tuple_insert_speculative not implemented");
59+
errors.add("row field count is 1, expected 2");
60+
errors.add("incorrect binary data format");
61+
errors.add("invalid sign in external \"numeric\" value");
62+
errors.add("Foreign keys and AFTER ROW triggers are not supported for columnar tables");
5763

5864
// current errors in Citus (to be removed once fixed)
5965
if (CitusBugs.bug3957) {
@@ -78,7 +84,6 @@ public static List<String> getCitusErrors() {
7884
if (CitusBugs.bug4079) {
7985
errors.add("aggregate function calls cannot be nested");
8086
}
81-
8287
return errors;
8388
}
8489

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,42 @@
11
package sqlancer.citus.oracle.tlp;
22

33
import java.sql.SQLException;
4-
import java.util.ArrayList;
5-
import java.util.Arrays;
6-
import java.util.Collections;
7-
import java.util.List;
84

9-
import sqlancer.ComparatorHelper;
10-
import sqlancer.Randomly;
115
import sqlancer.citus.CitusGlobalState;
126
import sqlancer.citus.gen.CitusCommon;
7+
import sqlancer.common.oracle.TLPWhereOracle;
8+
import sqlancer.common.oracle.TestOracle;
9+
import sqlancer.common.query.ExpectedErrors;
1310
import sqlancer.postgres.PostgresGlobalState;
14-
import sqlancer.postgres.PostgresVisitor;
15-
import sqlancer.postgres.oracle.tlp.PostgresTLPBase;
11+
import sqlancer.postgres.PostgresSchema;
12+
import sqlancer.postgres.PostgresSchema.PostgresColumn;
13+
import sqlancer.postgres.PostgresSchema.PostgresTable;
14+
import sqlancer.postgres.ast.PostgresExpression;
15+
import sqlancer.postgres.ast.PostgresJoin;
16+
import sqlancer.postgres.ast.PostgresSelect;
17+
import sqlancer.postgres.gen.PostgresCommon;
18+
import sqlancer.postgres.gen.PostgresExpressionGenerator;
1619

17-
public class CitusTLPWhereOracle extends PostgresTLPBase {
20+
public class CitusTLPWhereOracle implements TestOracle<PostgresGlobalState> {
1821

19-
private final CitusTLPBase citusTLPBase;
22+
private final TLPWhereOracle<PostgresSelect, PostgresJoin, PostgresExpression, PostgresSchema, PostgresTable, PostgresColumn, PostgresGlobalState> oracle;
2023

2124
public CitusTLPWhereOracle(CitusGlobalState state) {
22-
super(state);
23-
CitusCommon.addCitusErrors(errors);
24-
citusTLPBase = new CitusTLPBase(state);
25+
PostgresExpressionGenerator gen = new PostgresExpressionGenerator(state);
26+
ExpectedErrors expectedErrors = ExpectedErrors.newErrors().with(PostgresCommon.getCommonExpressionErrors())
27+
.with(PostgresCommon.getCommonFetchErrors()).withRegex(PostgresCommon.getCommonExpressionRegexErrors())
28+
.with(CitusCommon.getCitusErrors()).build();
29+
30+
this.oracle = new TLPWhereOracle<>(state, gen, expectedErrors);
2531
}
2632

2733
@Override
2834
public void check() throws SQLException {
29-
state.setAllowedFunctionTypes(Arrays.asList(PostgresGlobalState.IMMUTABLE));
30-
citusTLPBase.check();
31-
s = citusTLPBase.getSchema();
32-
targetTables = citusTLPBase.getTargetTables();
33-
gen = citusTLPBase.getGenerator();
34-
select = citusTLPBase.getSelect();
35-
predicate = citusTLPBase.getPredicate();
36-
negatedPredicate = citusTLPBase.getNegatedPredicate();
37-
isNullPredicate = citusTLPBase.getIsNullPredicate();
38-
whereCheck();
39-
state.setDefaultAllowedFunctionTypes();
35+
oracle.check();
4036
}
4137

42-
void whereCheck() throws SQLException {
43-
if (Randomly.getBooleanWithRatherLowProbability()) {
44-
select.setOrderByClauses(gen.generateOrderBys());
45-
}
46-
String originalQueryString = PostgresVisitor.asString(select);
47-
List<String> resultSet = ComparatorHelper.getResultSetFirstColumnAsString(originalQueryString, errors, state);
48-
49-
select.setOrderByClauses(Collections.emptyList());
50-
select.setWhereClause(predicate);
51-
String firstQueryString = PostgresVisitor.asString(select);
52-
select.setWhereClause(negatedPredicate);
53-
String secondQueryString = PostgresVisitor.asString(select);
54-
select.setWhereClause(isNullPredicate);
55-
String thirdQueryString = PostgresVisitor.asString(select);
56-
List<String> combinedString = new ArrayList<>();
57-
List<String> secondResultSet = ComparatorHelper.getCombinedResultSet(firstQueryString, secondQueryString,
58-
thirdQueryString, combinedString, Randomly.getBoolean(), state, errors);
59-
ComparatorHelper.assumeResultSetsAreEqual(resultSet, secondResultSet, originalQueryString, combinedString,
60-
state);
38+
@Override
39+
public String getLastQueryString() {
40+
return oracle.getLastQueryString();
6141
}
6242
}

src/sqlancer/postgres/gen/PostgresTruncateGenerator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ public static SQLQueryAdapter create(PostgresGlobalState globalState) {
3333
sb.append(" ");
3434
sb.append(Randomly.fromOptions("CASCADE", "RESTRICT"));
3535
}
36-
return new SQLQueryAdapter(sb.toString(), ExpectedErrors
37-
.from("cannot truncate a table referenced in a foreign key constraint", "is not a table"));
36+
return new SQLQueryAdapter(sb.toString(),
37+
ExpectedErrors.from("cannot truncate a table referenced in a foreign key constraint", "is not a table",
38+
"is not distributed"));
3839
}
3940

4041
}

0 commit comments

Comments
 (0)