Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stonedb impl err 3 #4

Draft
wants to merge 99 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
46be53a
fix: add space when creating table
Jun 29, 2023
c57f997
fix: add expected errors and key length specification
Jun 29, 2023
c9f33dd
feat: generate comments randomly
Jun 29, 2023
f2a2d0b
fix: add expected errors and key restriction
Jun 29, 2023
7d11c15
feat: add support for more map actions
Jun 29, 2023
804ae21
fix: add space between INDEX and indexName
Jun 29, 2023
9d3588a
fix: add space and {}
Jun 29, 2023
07b57ac
fix: remove pre-added errors before testing
Jun 29, 2023
2d54fa5
refactor: rename delete useless as when deleting from table
Jun 29, 2023
8d74233
fix: add missing space
Jun 29, 2023
e1deede
fix: add missing (
Jun 29, 2023
12e5630
fix: add missing length for varbinary type
Jun 30, 2023
f651d21
fix: string generation strategy in comments
Jun 30, 2023
e748258
fix: add provider
Jun 30, 2023
9e7e347
fix: use global randomly
Jun 30, 2023
36f73a9
fix: insert one row
Jun 30, 2023
d8f3c0e
feat: add expected errors
Jun 30, 2023
e9ee2b5
feat: no length
Jun 30, 2023
a650ae8
feat: no length
Jun 30, 2023
37e4398
style: format
Jun 30, 2023
1348786
fix: Tianmu engine does not support fulltext index.
Jun 30, 2023
8e921ed
fix: fix alter table and getwithoutnull
Jun 30, 2023
0afbe78
fix: add expected errors
Jun 30, 2023
1345b6e
feat: support StringVisitor of StoneSelect
Jun 30, 2023
2f5cff4
fix: delete useless import
Jun 30, 2023
d08ffb3
fix: syntax error in index create
Jun 30, 2023
c07dc5d
style: run formate
Jun 30, 2023
0042955
fix: syntax errors
Jun 30, 2023
c169371
fix: delete AS in DELETE
Jul 1, 2023
464d3ba
feat: add expectedErrors for all generator
Jul 3, 2023
fef149e
refactor: change cast operation to lambda and fix dataType toString e…
Jul 3, 2023
f0235b8
feat: add expected errors
Jul 3, 2023
9c3398b
refactor: remove redundant identifier
Jul 3, 2023
805321b
refactor: remove unused expected errors
Jul 4, 2023
5db400d
refactor: use parent StringBuilder
Jul 4, 2023
21383f5
refactor: add more expected errors
Jul 4, 2023
68c7764
feat: add some options according to docs
Jul 6, 2023
dc0d2bc
refactor: change action perform times
Jul 6, 2023
482ebb6
refactor: rename and change action perform times
Jul 6, 2023
10c350a
Merge branch 'main' into fix_stonedb_impl_err
zhenglin-charlie-li Jul 6, 2023
5b1e61c
fix: delete unexcepted errors
Jul 6, 2023
12eafc2
Merge remote-tracking branch 'origin/fix_stonedb_impl_err' into fix_s…
Jul 6, 2023
400ac04
feat: add one expected error
Jul 7, 2023
d85e750
feat: add another option when assigning assignment list
Jul 7, 2023
da95116
refactor: refactor append type, reused function
Jul 7, 2023
6d84268
refactor: refactor append type argus
Jul 7, 2023
168954d
fix: fix null pointer exception
Jul 7, 2023
0e28e47
refactor: delete useless code
Jul 7, 2023
cde4299
Merge branch 'main' into fix_stonedb_impl_err
zhenglin-charlie-li Jul 7, 2023
f03e53e
fix: fix cast operation bug in StoneDB
Jul 7, 2023
cc90915
feat: add some options according to docs
Jul 6, 2023
f22ccfb
feat: add one expected error
Jul 7, 2023
7873ebd
feat: add another option when assigning assignment list
Jul 7, 2023
e6c0994
fix: fix null pointer exception
Jul 7, 2023
0390d89
fix: fix cast operation bug in StoneDB
Jul 7, 2023
91e695c
Merge remote-tracking branch 'origin/fix_stonedb_impl_err_2' into fix…
Jul 7, 2023
aa781a6
fix: fix cast operation bug in StoneDB
Jul 7, 2023
657b094
fix: Tianmu engine does not support fulltext index.
Jun 30, 2023
f32a885
feat: add expectedErrors for all generator
Jul 3, 2023
76e1c2d
refactor: remove unused expected errors
Jul 4, 2023
80cf31c
refactor: delete useless code
Jul 7, 2023
596f321
feat: add some options according to docs
Jul 6, 2023
ac0f9f8
feat: add one expected error
Jul 7, 2023
27d9de0
feat: add another option when assigning assignment list
Jul 7, 2023
687833e
fix: fix null pointer exception
Jul 7, 2023
a25a909
fix: fix cast operation bug in StoneDB
Jul 7, 2023
4529f6f
fix: fix cast operation bug in StoneDB
Jul 7, 2023
f973fa2
Merge remote-tracking branch 'origin/fix_stonedb_impl_err_2' into fix…
Jul 8, 2023
0abbfd4
fix: delete rename column
Jul 8, 2023
cde3809
feat: add expected errors
Jul 8, 2023
1ca1645
refactor: reuse code
Jul 7, 2023
1764612
refactor: refactor append type argus
Jul 7, 2023
4e56b3e
refactor: reuse code, rename, fix
Jul 7, 2023
66221e7
fix: syntax error
Jul 8, 2023
5780e7b
fix: change / alter column error
Jul 8, 2023
a5e2c10
fix: change / alter column error
Jul 8, 2023
5dc4236
fix: change / alter column error
Jul 8, 2023
6d8b394
fix: duplicate data type when add column in alter table
Jul 8, 2023
2b4e581
fix: duplicate data type when add column in alter table
Jul 8, 2023
024ee63
fix: no space error
Jul 8, 2023
5012247
fix: fix as count in NoREC Oracle
Jul 8, 2023
a9c0c94
Merge branch 'fix_stonedb_impl_err_2' into fix_stonedb_impl_err_3
Jul 8, 2023
dd16fda
fix: fix as count in NoREC Oracle
Jul 8, 2023
b4eeb19
fix: fix as count in NoREC Oracle
Jul 8, 2023
4d46cf4
fix: fix bitwise operation
Jul 10, 2023
25b1afd
fix: fix binary operation
Jul 10, 2023
9222bcb
fix: fix in operation
Jul 10, 2023
63826d1
feat: add expected errors
Jul 10, 2023
0e4cb8f
feat: add expected errors
Jul 10, 2023
391ac1e
feat: fix errors in fetch size
Jul 10, 2023
8151d80
feat: add expected errors
Jul 10, 2023
0066bab
fix: regex match string
Jul 10, 2023
313bb95
feat: add expected errors
Jul 10, 2023
50d01d3
Merge branch 'main' into fix_stonedb_impl_err_3
Jul 11, 2023
edf57fa
git: merge main
Jul 11, 2023
8c61276
feat: disable delete order by
Jul 12, 2023
63951b5
feat: disable delete order by
Jul 12, 2023
aeebd2c
feat: disable delete order by
Jul 12, 2023
09f52ba
feat: add expected errors
Jul 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions src/sqlancer/stonedb/StoneDBSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,87 @@ public static Node<StoneDBExpression> getRandomValue(StoneDBDataType dataType) {
}
return null;
}

public static String getTypeAndValue(StoneDBDataType dataType) {
StringBuilder sb = new StringBuilder();
switch (dataType) {
case TINYINT:
return "TINYINT";
case SMALLINT:
return "SMALLINT";
case MEDIUMINT:
return "MEDIUMINT";
case INT:
return "INT";
case BIGINT:
return "BIGINT";
case FLOAT:
sb.append("FLOAT");
optionallyAddPrecisionAndScale(sb);
return sb.toString();
case DOUBLE:
sb.append("DOUBLE");
optionallyAddPrecisionAndScale(sb);
return sb.toString();
case DECIMAL:
return "DECIMAL"; // The default value is P(10,0);
case YEAR:
return "YEAR";
case TIME:
return "TIME";
case DATE:
return "DATE";
case DATETIME:
return "DATETIME";
case TIMESTAMP:
return "TIMESTAMP";
case CHAR:
sb.append("CHAR").append(Randomly.fromOptions("", "(" + new Randomly().getInteger(0, 255) + ")"));
return sb.toString();
case VARCHAR:
sb.append("VARCHAR").append("(").append(new Randomly().getInteger(0, 65535)).append(")");
return sb.toString();
case TINYTEXT:
return "TINYTEXT";
case TEXT:
return "TEXT";
case MEDIUMTEXT:
return "MEDIUMTEXT";
case LONGTEXT:
return "LONGTEXT";
case BINARY:
return "BINARY";
case VARBINARY:
sb.append("VARBINARY").append("(").append(new Randomly().getInteger(0, 65535)).append(")");
return sb.toString();
case TINYBLOB:
return "TINYBLOB";
case BLOB:
return "BLOB";
case MEDIUMBLOB:
return "MEDIUMBLOB";
case LONGBLOB:
return "LONGBLOB";
default:
throw new AssertionError();
}
}

private static void optionallyAddPrecisionAndScale(StringBuilder sb) {
if (Randomly.getBoolean()) {
sb.append("(");
// The maximum number of digits (M) for DECIMAL is 65
long m = Randomly.getNotCachedInteger(1, 65);
sb.append(m);
sb.append(", ");
// The maximum number of supported decimals (D) is 30
long nCandidate = Randomly.getNotCachedInteger(1, 30);
// For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'c0').
long n = Math.min(nCandidate, m);
sb.append(n);
sb.append(")");
}
}
}

public static class StoneDBTable
Expand Down
12 changes: 12 additions & 0 deletions src/sqlancer/stonedb/StoneDBToStringVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import sqlancer.common.ast.newast.NewToStringVisitor;
import sqlancer.common.ast.newast.Node;
import sqlancer.stonedb.StoneDBSchema.StoneDBDataType;
import sqlancer.stonedb.ast.StoneDBConstant;
import sqlancer.stonedb.ast.StoneDBExpression;
import sqlancer.stonedb.ast.StoneDBJoin;
import sqlancer.stonedb.ast.StoneDBSelect;
import sqlancer.stonedb.gen.StoneDBExpressionGenerator.StoneDBCastOperation;

public class StoneDBToStringVisitor extends NewToStringVisitor<StoneDBExpression> {
@Override
Expand All @@ -16,6 +18,8 @@ public void visitSpecific(Node<StoneDBExpression> expr) {
visit((StoneDBSelect) expr);
} else if (expr instanceof StoneDBJoin) {
visit((StoneDBJoin) expr);
} else if (expr instanceof StoneDBCastOperation) {
visit((StoneDBCastOperation) expr);
} else {
throw new AssertionError(expr.getClass());
}
Expand Down Expand Up @@ -81,6 +85,14 @@ private void visit(StoneDBJoin join) {
}
}

private void visit(StoneDBCastOperation cast) {
sb.append("CAST(");
visit(cast.getExpr());
sb.append(" AS ");
sb.append(cast.getType() == StoneDBDataType.INT ? "UNSIGNED" : cast.getType().toString());
sb.append(") ");
}

public static String asString(Node<StoneDBExpression> expr) {
StoneDBToStringVisitor visitor = new StoneDBToStringVisitor();
visitor.visit(expr);
Expand Down
53 changes: 39 additions & 14 deletions src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import sqlancer.IgnoreMeException;
import sqlancer.Randomly;
import sqlancer.common.ast.BinaryOperatorNode.Operator;
import sqlancer.common.ast.newast.ColumnReferenceNode;
import sqlancer.common.ast.newast.NewBetweenOperatorNode;
import sqlancer.common.ast.newast.NewBinaryOperatorNode;
import sqlancer.common.ast.newast.NewCaseOperatorNode;
Expand All @@ -32,25 +35,35 @@ public StoneDBExpressionGenerator(StoneDBGlobalState globalState) {

private enum Expression {
UNARY_PREFIX, UNARY_POSTFIX, BINARY_COMPARISON, BINARY_LOGICAL, BINARY_ARITHMETIC, BINARY_BITWISE, BETWEEN, IN,
CASE
NOT_IN, CASE
}

public static class StoneDBCastOperation extends NewUnaryPostfixOperatorNode<StoneDBExpression> {
public static class StoneDBCastOperation implements Node<StoneDBExpression> {
Node<StoneDBExpression> expr;
StoneDBDataType type;

public StoneDBCastOperation(Node<StoneDBExpression> expr, StoneDBDataType type) {
super(expr, () -> "::" + type.toString());
this.expr = expr;
this.type = type;
}

public Node<StoneDBExpression> getExpr() {
return expr;
}

public StoneDBDataType getType() {
return type;
}
}

@Override
public Node<StoneDBExpression> negatePredicate(Node<StoneDBExpression> predicate) {
return null;
return new NewUnaryPrefixOperatorNode<>(predicate, StoneDBUnaryPrefixOperator.NOT);
}

@Override
public Node<StoneDBExpression> isNull(Node<StoneDBExpression> expr) {
return null;
return new NewUnaryPostfixOperatorNode<>(expr, StoneDBUnaryPostfixOperator.IS_NULL);
}

@Override
Expand Down Expand Up @@ -111,6 +124,12 @@ protected Node<StoneDBExpression> generateExpression(int depth) {
case BINARY_COMPARISON:
op = StoneDBBinaryComparisonOperator.getRandom();
return new NewBinaryOperatorNode<>(generateExpression(depth + 1), generateExpression(depth + 1), op);
case IN:
return new NewInOperatorNode<>(generateExpression(depth + 1),
generateExpressions(Randomly.smallNumber() + 1, depth + 1), false);
case NOT_IN:
return new NewInOperatorNode<>(generateExpression(depth + 1),
generateExpressions(Randomly.smallNumber() + 1, depth + 1), true);
case BINARY_LOGICAL:
op = StoneDBBinaryLogicalOperator.getRandom();
return new NewBinaryOperatorNode<>(generateExpression(depth + 1), generateExpression(depth + 1), op);
Expand All @@ -123,9 +142,6 @@ protected Node<StoneDBExpression> generateExpression(int depth) {
case BETWEEN:
return new NewBetweenOperatorNode<>(generateExpression(depth + 1), generateExpression(depth + 1),
generateExpression(depth + 1), Randomly.getBoolean());
case IN:
return new NewInOperatorNode<>(generateExpression(depth + 1),
generateExpressions(Randomly.smallNumber() + 1, depth + 1), Randomly.getBoolean());
case CASE:
int nr = Randomly.smallNumber() + 1;
return new NewCaseOperatorNode<>(generateExpression(depth + 1), generateExpressions(nr, depth + 1),
Expand All @@ -137,7 +153,17 @@ protected Node<StoneDBExpression> generateExpression(int depth) {

@Override
protected Node<StoneDBExpression> generateColumn() {
return null;
StoneDBColumn column = Randomly.fromList(columns);
return new ColumnReferenceNode<>(column);
}

protected List<Node<StoneDBExpression>> generateColumns() {
int size = globalState.getRandomly().getInteger(1, columns.size());
Set<Node<StoneDBExpression>> set = new HashSet<>();
while (set.size() < size) {
set.add(generateColumn());
}
return new ArrayList<>(set);
}

public enum StoneDBAggregateFunction {
Expand All @@ -160,7 +186,7 @@ public int getNrArgs() {

public enum StoneDBUnaryPrefixOperator implements Operator {

NOT("NOT"), PLUS("+"), MINUS("-");
NOT("NOT"), PLUS("+"), MINUS("-"), INVERSION("!");

private final String textRepr;

Expand Down Expand Up @@ -203,8 +229,7 @@ public static StoneDBUnaryPostfixOperator getRandom() {
*/
public enum StoneDBBinaryComparisonOperator implements Operator {
EQUAL("="), GREATER(">"), LESS("<"), GREATER_EQUAL(">="), LESS_EQUAL("<="),
NOT_EQUALS(Randomly.fromList(Arrays.asList("!=", "<>"))), NULL_SAFE_EQUAL("<=>"), IN("IN"), NOT_IN("NOT_IN"),
LIKE("LIKE"), IS_NULL("IS NULL"), IS_NOT_NULL("IS NOT NULL");
NOT_EQUALS(Randomly.fromList(Arrays.asList("!=", "<>"))), NULL_SAFE_EQUAL("<=>"), LIKE("LIKE");

private final String textRepr;

Expand All @@ -227,7 +252,7 @@ public String getTextRepresentation() {
*/
public enum StoneDBBinaryLogicalOperator implements Operator {

NOT("NOT"), AND("AND"), OR("OR"), XOR("XOR");
AND("AND"), OR("OR"), XOR("XOR");

private final String textRepr;

Expand Down Expand Up @@ -274,7 +299,7 @@ public String getTextRepresentation() {
* Bitwise operators supported by StoneDB: https://stonedb.io/docs/SQL-reference/operators/bitwise-operators
*/
public enum StoneDBBinaryBitwiseOperator implements Operator {
AND("&"), OR("|"), XOR("^"), INVERSION("!"), LEFTSHIFT("<<"), RIGHTSHIFT(">>");
AND("&"), OR("|"), XOR("^"), LEFTSHIFT("<<"), RIGHTSHIFT(">>");

private final String textRepr;

Expand Down
20 changes: 17 additions & 3 deletions src/sqlancer/stonedb/gen/StoneDBIndexCreateGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sqlancer.common.query.ExpectedErrors;
import sqlancer.common.query.SQLQueryAdapter;
import sqlancer.stonedb.StoneDBProvider.StoneDBGlobalState;
import sqlancer.stonedb.StoneDBSchema.StoneDBColumn;
import sqlancer.stonedb.StoneDBSchema.StoneDBTable;

public class StoneDBIndexCreateGenerator {
Expand All @@ -30,10 +31,12 @@ private SQLQueryAdapter getQuery() {
sb.append(Randomly.fromOptions("UNIQUE", "FULLTEXT", "SPATIAL"));
sb.append(" INDEX ");
sb.append(globalState.getSchema().getFreeIndexName());
appendIndexType();
if (Randomly.getBoolean()) {
appendIndexType();
}
sb.append(" ON ");
sb.append(table.getName());
appendKeyPart();
appendKeyParts();
appendIndexOption();
appendAlgoOrLockOption();
addExpectedErrors();
Expand Down Expand Up @@ -67,9 +70,20 @@ private void appendIndexType() {
sb.append(Randomly.fromOptions("BTREE", "HASH"));
}

private void appendKeyParts() {
int numberOfKeyParts = Randomly.fromOptions(1, 1, 1, 1, table.getColumns().size());
for (int i = 0; i < numberOfKeyParts; i++) {
appendKeyPart();
}
}

private void appendKeyPart() {
sb.append("(");
sb.append(table.getRandomColumn().getName());
StoneDBColumn randomColumn = table.getRandomColumn();
sb.append(randomColumn.getName());
if (Randomly.getBoolean()) {
sb.append(" (").append(Randomly.smallNumber()).append(")");
}
if (Randomly.getBoolean()) {
sb.append(Randomly.fromOptions(" ASC", " DESC"));
}
Expand Down
Loading