-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add TLPWhereGenerator interface * Add generic TLPWhere oracle * Implement TLPWhereGenerator interfaces for SQLite3 * Use generic TLPWhere oracle for SQLite3 * [Databend] Refactor tests * [Databend] Update to v1.2.542 * Remove duplicated logs in NoREC oracle (#953) * [ClickHouse] Added pattern for changed error message (#955) * [ClickHouse] Added pattern for changed error message https://fiddle.clickhouse.com/a3a95024-4da7-4275-baff-86f116014744 ``` Received exception from server (version 24.2.3): Code: 403. DB::Exception: Received from localhost:9000. DB::Exception: Cannot get JOIN keys from JOIN ON section: '476505718 = `_--right_2.c0`', found keys: [Left keys: [] Right keys [] Condition columns: '', 'equals(476505718, _--right_2.c0)']. (INVALID_JOIN_ON_EXPRESSION) (query: SELECT SUM(check <> 0) FROM ((SELECT right_0.c0 AS `check` FROM t0 AS left FULL OUTER JOIN t0 AS right_0 ON ((left.c0)=(right_0.c0)) LEFT OUTER JOIN t0 AS right_1 ON ((left.c0)=(right_1.c0)) LEFT ANTI JOIN t0 AS right_2 ON ((476505718)=(right_2.c0)))) as res;) ``` * formatter * Avoid storage parameters during CREATE TABLE for partitioned tables (#956) CREATE TABLE WITH() allows storage parameters, but partitioned tables emit an error (given below) if attempted. This is because partitioned non-leaf tables are virutal tables [1] and don't accept storage parameters. Sample Error: "ERROR: cannot specify storage parameters for a partitioned table" This patch skips storage parameter generation for partitioned tables. Ref: 1. https://www.postgresql.org/docs/current/ddl-partitioning.html * Review feedback * Ensure INHERITS() only uses tables (not views) In Postgres, CREATE TABLE INHERITS () throws an error when VIEWs are provided, sample given below. ERROR: inherited relation "pg_buffercache" is not a table or foreign table Ref: 1. https://www.postgresql.org/docs/current/ddl-inherit.html * Revert "Ensure INHERITS() only uses tables (not views)" This reverts commit 0316c1c. * Ensure INHERITS() only uses tables (not views) In Postgres, CREATE TABLE INHERITS () throws an error when VIEWs are provided, sample given below. ERROR: inherited relation "pg_buffercache" is not a table or foreign table Ref: 1. https://www.postgresql.org/docs/current/ddl-inherit.html * Another fix --------- Co-authored-by: malwaregarry <[email protected]> Co-authored-by: ming wei <[email protected]> Co-authored-by: Manuel Rigger <[email protected]> Co-authored-by: Ilya Yatsishin <[email protected]> Co-authored-by: Robins <[email protected]>
- Loading branch information
1 parent
6681b41
commit f14743d
Showing
18 changed files
with
299 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package sqlancer.common.gen; | ||
|
||
import sqlancer.common.ast.newast.Expression; | ||
import sqlancer.common.schema.AbstractTableColumn; | ||
|
||
public interface PartitionGenerator<E extends Expression<C>, C extends AbstractTableColumn<?, ?>> { | ||
|
||
/** | ||
* Negates a predicate (i.e., uses a NOT operator). | ||
* | ||
* @param predicate | ||
* the boolean predicate. | ||
* | ||
* @return the negated predicate. | ||
*/ | ||
E negatePredicate(E predicate); | ||
|
||
/** | ||
* Checks if an expression evaluates to NULL (i.e., implements the IS NULL operator). | ||
* | ||
* @param expr | ||
* the expression | ||
* | ||
* @return an expression that checks whether the expression evaluates to NULL. | ||
*/ | ||
E isNull(E expr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package sqlancer.common.gen; | ||
|
||
import java.util.List; | ||
|
||
import sqlancer.common.ast.newast.Expression; | ||
import sqlancer.common.ast.newast.Join; | ||
import sqlancer.common.ast.newast.Select; | ||
import sqlancer.common.schema.AbstractTable; | ||
import sqlancer.common.schema.AbstractTableColumn; | ||
import sqlancer.common.schema.AbstractTables; | ||
|
||
public interface TLPWhereGenerator<S extends Select<J, E, T, C>, J extends Join<E, T, C>, E extends Expression<C>, T extends AbstractTable<C, ?, ?>, C extends AbstractTableColumn<?, ?>> | ||
extends PartitionGenerator<E, C> { | ||
|
||
TLPWhereGenerator<S, J, E, T, C> setTablesAndColumns(AbstractTables<T, C> tables); | ||
|
||
E generateBooleanExpression(); | ||
|
||
S generateSelect(); | ||
|
||
List<J> getRandomJoinClauses(); | ||
|
||
List<E> getTableRefs(); | ||
|
||
List<E> generateFetchColumns(boolean shouldCreateDummy); | ||
|
||
List<E> generateOrderBys(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package sqlancer.common.oracle; | ||
|
||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import sqlancer.ComparatorHelper; | ||
import sqlancer.Randomly; | ||
import sqlancer.SQLGlobalState; | ||
import sqlancer.common.ast.newast.Expression; | ||
import sqlancer.common.ast.newast.Join; | ||
import sqlancer.common.ast.newast.Select; | ||
import sqlancer.common.gen.TLPWhereGenerator; | ||
import sqlancer.common.query.ExpectedErrors; | ||
import sqlancer.common.schema.AbstractSchema; | ||
import sqlancer.common.schema.AbstractTable; | ||
import sqlancer.common.schema.AbstractTableColumn; | ||
import sqlancer.common.schema.AbstractTables; | ||
|
||
public class TLPWhereOracle<Z extends Select<J, E, T, C>, J extends Join<E, T, C>, E extends Expression<C>, S extends AbstractSchema<?, T>, T extends AbstractTable<C, ?, ?>, C extends AbstractTableColumn<?, ?>, G extends SQLGlobalState<?, S>> | ||
implements TestOracle<G> { | ||
|
||
private final G state; | ||
|
||
private TLPWhereGenerator<Z, J, E, T, C> gen; | ||
private final ExpectedErrors errors; | ||
|
||
private String generatedQueryString; | ||
|
||
public TLPWhereOracle(G state, TLPWhereGenerator<Z, J, E, T, C> gen, ExpectedErrors expectedErrors) { | ||
if (state == null || gen == null || expectedErrors == null) { | ||
throw new IllegalArgumentException("Null variables used to initialize test oracle."); | ||
} | ||
this.state = state; | ||
this.gen = gen; | ||
this.errors = expectedErrors; | ||
} | ||
|
||
@Override | ||
public void check() throws SQLException { | ||
S s = state.getSchema(); | ||
AbstractTables<T, C> targetTables = TestOracleUtils.getRandomTableNonEmptyTables(s); | ||
gen = gen.setTablesAndColumns(targetTables); | ||
|
||
Select<J, E, T, C> select = gen.generateSelect(); | ||
|
||
boolean shouldCreateDummy = true; | ||
select.setFetchColumns(gen.generateFetchColumns(shouldCreateDummy)); | ||
select.setJoinClauses(gen.getRandomJoinClauses()); | ||
select.setFromList(gen.getTableRefs()); | ||
select.setWhereClause(null); | ||
|
||
String originalQueryString = select.asString(); | ||
generatedQueryString = originalQueryString; | ||
List<String> firstResultSet = ComparatorHelper.getResultSetFirstColumnAsString(originalQueryString, errors, | ||
state); | ||
|
||
boolean orderBy = Randomly.getBooleanWithSmallProbability(); | ||
if (orderBy) { | ||
select.setOrderByClauses(gen.generateOrderBys()); | ||
} | ||
|
||
TestOracleUtils.PredicateVariants<E, C> predicates = TestOracleUtils.initializeTernaryPredicateVariants(gen, | ||
gen.generateBooleanExpression()); | ||
select.setWhereClause(predicates.predicate); | ||
String firstQueryString = select.asString(); | ||
select.setWhereClause(predicates.negatedPredicate); | ||
String secondQueryString = select.asString(); | ||
select.setWhereClause(predicates.isNullPredicate); | ||
String thirdQueryString = select.asString(); | ||
|
||
List<String> combinedString = new ArrayList<>(); | ||
List<String> secondResultSet = ComparatorHelper.getCombinedResultSet(firstQueryString, secondQueryString, | ||
thirdQueryString, combinedString, !orderBy, state, errors); | ||
|
||
ComparatorHelper.assumeResultSetsAreEqual(firstResultSet, secondResultSet, originalQueryString, combinedString, | ||
state); | ||
} | ||
|
||
@Override | ||
public String getLastQueryString() { | ||
return generatedQueryString; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.