|
1 | 1 | package sqlancer.citus.oracle.tlp; |
2 | 2 |
|
3 | 3 | import java.sql.SQLException; |
4 | | -import java.util.ArrayList; |
5 | | -import java.util.Arrays; |
6 | | -import java.util.Collections; |
7 | | -import java.util.List; |
8 | 4 |
|
9 | | -import sqlancer.ComparatorHelper; |
10 | | -import sqlancer.Randomly; |
11 | 5 | import sqlancer.citus.CitusGlobalState; |
12 | 6 | import sqlancer.citus.gen.CitusCommon; |
| 7 | +import sqlancer.common.oracle.TLPWhereOracle; |
| 8 | +import sqlancer.common.oracle.TestOracle; |
| 9 | +import sqlancer.common.query.ExpectedErrors; |
13 | 10 | 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; |
16 | 19 |
|
17 | | -public class CitusTLPWhereOracle extends PostgresTLPBase { |
| 20 | +public class CitusTLPWhereOracle implements TestOracle<PostgresGlobalState> { |
18 | 21 |
|
19 | | - private final CitusTLPBase citusTLPBase; |
| 22 | + private final TLPWhereOracle<PostgresSelect, PostgresJoin, PostgresExpression, PostgresSchema, PostgresTable, PostgresColumn, PostgresGlobalState> oracle; |
20 | 23 |
|
21 | 24 | 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); |
25 | 31 | } |
26 | 32 |
|
27 | 33 | @Override |
28 | 34 | 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(); |
40 | 36 | } |
41 | 37 |
|
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(); |
61 | 41 | } |
62 | 42 | } |
0 commit comments