Skip to content

Commit

Permalink
feat: add appendType StoneDBTableGenerator.java
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhengLin Li authored and zhenglin-charlie-li committed Jun 23, 2023
1 parent 5203913 commit 46f45e9
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 138 deletions.
21 changes: 14 additions & 7 deletions src/sqlancer/Randomly.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package sqlancer;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.math.BigInteger;
import java.util.*;
import java.util.function.Supplier;

public final class Randomly {
Expand Down Expand Up @@ -215,7 +212,6 @@ public String getString(Randomly r) {

},
ALPHANUMERIC {

@Override
public String getString(Randomly r) {
return getStringOfAlphabet(r, ALPHANUMERIC_ALPHABET);
Expand All @@ -224,7 +220,6 @@ public String getString(Randomly r) {

},
ALPHANUMERIC_SPECIALCHAR {

@Override
public String getString(Randomly r) {
return getStringOfAlphabet(r, ALPHANUMERIC_SPECIALCHAR_ALPHABET);
Expand Down Expand Up @@ -452,6 +447,18 @@ public long getLong(long left, long right) {
return getNextLong(left, right);
}

public BigInteger getBigInteger(BigInteger left, BigInteger right) {
if (left.equals(right)) {
return left;
}
while (true) {
BigInteger result = new BigInteger(63, new Random());
if (result.compareTo(left) >= 0 && result.compareTo(right) <= 0) {
return result;
}
}
}

public BigDecimal getRandomBigDecimal() {
return BigDecimal.valueOf(getThreadRandom().get().nextDouble());
}
Expand Down
17 changes: 9 additions & 8 deletions src/sqlancer/stonedb/StoneDBProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected StoneDBSchema readSchema() throws Exception {

enum Action implements AbstractAction<StoneDBGlobalState> {
SHOW_TABLES((g) -> new SQLQueryAdapter("SHOW TABLES"));

private final SQLQueryProvider<StoneDBGlobalState> sqlQueryProvider;

Action(SQLQueryProvider<StoneDBGlobalState> sqlQueryProvider) {
Expand All @@ -43,10 +44,10 @@ public Query<?> getQuery(StoneDBGlobalState globalState) throws Exception {
private static int mapActions(StoneDBGlobalState globalState, Action a) {
Randomly r = globalState.getRandomly();
switch (a) {
case SHOW_TABLES:
return 1;
default:
throw new AssertionError(a);
case SHOW_TABLES:
return 1;
default:
throw new AssertionError(a);
}
}

Expand All @@ -59,10 +60,10 @@ public void generateDatabase(StoneDBGlobalState globalState) throws Exception {
}
StatementExecutor<StoneDBGlobalState, Action> se = new StatementExecutor<>(globalState, Action.values(),
StoneDBProvider::mapActions, (q) -> {
if (globalState.getSchema().getDatabaseTables().isEmpty()) {
throw new IgnoreMeException();
}
});
if (globalState.getSchema().getDatabaseTables().isEmpty()) {
throw new IgnoreMeException();
}
});
se.executeStatements();
}

Expand Down
Loading

0 comments on commit 46f45e9

Please sign in to comment.