Skip to content

Commit

Permalink
feat: add expected errors for stonedb (sqlancer#867)
Browse files Browse the repository at this point in the history
* feat: add expected errors

* feat: add expected errors
  • Loading branch information
zhenglin-charlie-li authored Aug 11, 2023
1 parent 2902882 commit b6cf5c0
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/sqlancer/stonedb/StoneDBErrors.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
package sqlancer.stonedb;

import sqlancer.common.query.ExpectedErrors;

public final class StoneDBErrors {
private StoneDBErrors() {
}

public static void addExpectedExpressionErrors(ExpectedErrors errors) {
// java.sql.SQLException: Incorrect DATE value: '292269055-12-02'
errors.add("Incorrect DATE value: ");
// java.sql.SQLException: Incorrect string value: '\xBC\xE7\xC9\x91\x05R...' for column 'c1' at row 1
errors.add("Incorrect string value: ");
// java.sql.SQLException: Incorrect integer value: 'ST' for column 'c1' at row 1
errors.add("Incorrect integer value: ");
// com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Truncated incorrect INTEGER value: '#Q'
errors.add("Data truncation: Truncated incorrect INTEGER value: ");
// com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: BIGINT value is out of range in
// '-((`database0`.`t0`.`c1` >> (not(`database0`.`t0`.`c1`))))'
errors.add("Data truncation: BIGINT value is out of range in ");
// com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: BIGINT UNSIGNED value is out of range in
// '(`database10`.`t0`.`c0` + (`database10`.`t0`.`c0` & (not(0.5))))'
errors.add("Data truncation: BIGINT UNSIGNED value is out of range in ");
// com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect time value: '0Sly6xqF0' for
// column 'c1' at row 1
errors.add("Data truncation: Incorrect time value: ");
// com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: DOUBLE value is out of range in
// '(`database0`.`t0`.`c0` * `database0`.`t0`.`c0`)'
errors.add("Data truncation: DOUBLE value is out of range in ");
// java.sql.SQLException: Numeric result of an expression is too large and cannot be handled by tianmu.
errors.add("Numeric result of an expression is too large and cannot be handled by tianmu.");
// java.sql.SQLSyntaxErrorException: Unknown column '1020726100' in 'order clause'
errors.add("Unknown column ");
}
}
15 changes: 15 additions & 0 deletions src/sqlancer/stonedb/gen/StoneDBTableAlterGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ private SQLQueryAdapter getQuery() {
private void addExpectedErrors() {
// com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Data too long for column 'c0' at row 2
errors.addRegex(Pattern.compile("Data truncation: Data too long for column 'c\\d{1,3}' at row \\d{1,3}"));
// com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect datetime value:
// '0.571272522740968' for column 'c1' at row 1
errors.add("Incorrect datetime value: ");
// java.sql.SQLSyntaxErrorException: Invalid default value for 'c0'
errors.add("Invalid default value for ");
// com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'c0' at row
// 2
errors.add("Data truncation: Out of range value for column ");
// java.sql.SQLSyntaxErrorException: Specified key was too long; max key length is 3072 bytes
errors.add("Specified key was too long; max key length is 3072 bytes");
// java.sql.SQLSyntaxErrorException: You can't delete all columns with ALTER TABLE; use DROP TABLE instead
Expand Down Expand Up @@ -98,12 +106,19 @@ private void appendAlterOption(Action action) {
String oldColumnName = table.getRandomColumn().getName();
String newColumnName = table.getFreeColumnName();
sb.append(oldColumnName).append(" ").append(newColumnName).append(" ");
errors.add("Incorrect integer value: ");
// java.sql.SQLException: Data truncated for column 'c1' at row 1
errors.add("Data truncated for column ");
sb.append(
StoneDBDataType.getTypeAndValue(StoneDBDataType.getRandomWithoutNull(), globalState.getRandomly()));
// java.sql.SQLSyntaxErrorException: Column length too big for column 'c1' (max = 16383); use BLOB or TEXT
// instead
errors.addRegex(Pattern
.compile("Column length too big for column 'c\\d{1,3}' (max = 16383); use BLOB or TEXT instead"));
// java.sql.SQLSyntaxErrorException: BLOB column 'c1' can't be used in key specification with the used table
// type
errors.addRegex(Pattern
.compile("BLOB column 'c\\d{1,3}' can't be used in key specification with the used table type"));
if (Randomly.getBoolean()) {
if (Randomly.getBoolean()) {
sb.append(" FIRST");
Expand Down
6 changes: 6 additions & 0 deletions src/sqlancer/stonedb/gen/StoneDBTableDeleteGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public SQLQueryAdapter getQuery() {
sb.append(" LIMIT ");
sb.append(r.getInteger(0, (int) randomTable.getNrRows(globalState)));
}
addExpectedErrors();
return new SQLQueryAdapter(sb.toString(), errors);
}

private void addExpectedErrors() {
// java.sql.SQLException: Incorrect string value: '\xBC\xE7\xC9\x91\x05R...' for column 'c1' at row 1
errors.add("Incorrect string value: ");
}
}
4 changes: 4 additions & 0 deletions src/sqlancer/stonedb/gen/StoneDBTableInsertGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ private SQLQueryAdapter getQuery() {
}

private void addExpectedErrors() {
// java.sql.SQLException: Incorrect DATE value: '292278994-08-17'
errors.add("Incorrect DATE value: '");
// java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '1970-01-14' for key 'PRIMARY'
errors.add("Duplicate entry ");
// com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'c0' at row
errors.add("Data truncation: Out of range value for column ");
// java.sql.SQLSyntaxErrorException: Unknown column 'c0' in 'field list'
Expand Down
2 changes: 2 additions & 0 deletions src/sqlancer/stonedb/oracle/StoneDBAggregateOracle.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sqlancer.common.ast.newast.Node;
import sqlancer.common.query.SQLQueryAdapter;
import sqlancer.common.query.SQLancerResultSet;
import sqlancer.stonedb.StoneDBErrors;
import sqlancer.stonedb.StoneDBProvider.StoneDBGlobalState;
import sqlancer.stonedb.StoneDBSchema.StoneDBCompositeDataType;
import sqlancer.stonedb.StoneDBSchema.StoneDBDataType;
Expand All @@ -30,6 +31,7 @@ public class StoneDBAggregateOracle extends StoneDBQueryPartitioningBase {

public StoneDBAggregateOracle(StoneDBGlobalState state) {
super(state);
StoneDBErrors.addExpectedExpressionErrors(errors);
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import sqlancer.common.oracle.TestOracle;
import sqlancer.common.query.SQLQueryAdapter;
import sqlancer.common.query.SQLancerResultSet;
import sqlancer.stonedb.StoneDBErrors;
import sqlancer.stonedb.StoneDBProvider.StoneDBGlobalState;
import sqlancer.stonedb.StoneDBSchema;
import sqlancer.stonedb.StoneDBSchema.StoneDBColumn;
Expand All @@ -42,6 +43,7 @@ public class StoneDBNoRECOracle extends NoRECBase<StoneDBGlobalState> implements
public StoneDBNoRECOracle(StoneDBGlobalState globalState) {
super(globalState);
this.schema = globalState.getSchema();
StoneDBErrors.addExpectedExpressionErrors(errors);
}

@Override
Expand Down

0 comments on commit b6cf5c0

Please sign in to comment.