Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
  • Loading branch information
2010YOUY01 committed Aug 7, 2024
1 parent 9c590b3 commit 0e5be03
Show file tree
Hide file tree
Showing 7 changed files with 667 additions and 657 deletions.
66 changes: 33 additions & 33 deletions src/sqlancer/datafusion/DataFusionSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static DataFusionDataType getRandomWithoutNull() {
}

public boolean isNumeric() {
return (this == BIGINT) || (this == DOUBLE);
return this == BIGINT || this == DOUBLE;
}

// How to parse type in DataFusion's catalog to `DataFusionDataType`
Expand All @@ -112,16 +112,16 @@ public boolean isNumeric() {
// select table_name, column_name, data_type from information_schema.columns;
public static DataFusionDataType parseFromDataFusionCatalog(String typeString) {
switch (typeString) {
case "Int64":
return DataFusionDataType.BIGINT;
case "Float64":
return DataFusionDataType.DOUBLE;
case "Boolean":
return DataFusionDataType.BOOLEAN;
case "Utf8":
return DataFusionDataType.STRING;
default:
dfAssert(false, "Unreachable. All branches should be eovered");
case "Int64":
return DataFusionDataType.BIGINT;
case "Float64":
return DataFusionDataType.DOUBLE;
case "Boolean":
return DataFusionDataType.BOOLEAN;
case "Utf8":
return DataFusionDataType.STRING;
default:
dfAssert(false, "Unreachable. All branches should be eovered");
}

dfAssert(false, "Unreachable. All branches should be eovered");
Expand All @@ -134,31 +134,31 @@ public Node<DataFusionExpression> getRandomConstant(DataFusionGlobalState state)
return DataFusionConstant.createNullConstant();
}
switch (this) {
case BIGINT:
long randInt = Randomly.getBoolean() ? state.getRandomly().getInteger()
: state.getRandomly().getInteger(-5, 5);
return DataFusionConstant.createIntConstant(randInt);
case BOOLEAN:
return new DataFusionConstant.DataFusionBooleanConstant(Randomly.getBoolean());
case DOUBLE:
if (Randomly.getBoolean()) {
case BIGINT:
long randInt = Randomly.getBoolean() ? state.getRandomly().getInteger()
: state.getRandomly().getInteger(-5, 5);
return DataFusionConstant.createIntConstant(randInt);
case BOOLEAN:
return new DataFusionConstant.DataFusionBooleanConstant(Randomly.getBoolean());
case DOUBLE:
if (Randomly.getBoolean()) {
Double randomDouble = state.getRandomly().getDouble(); // [0.0, 1.0);
Double scaledDouble = (randomDouble - 0.5) * 2 * Double.MAX_VALUE;
return new DataFusionConstant.DataFusionDoubleConstant(scaledDouble);
if (Randomly.getBoolean()) {
Double randomDouble = state.getRandomly().getDouble(); // [0.0, 1.0);
Double scaledDouble = (randomDouble - 0.5) * 2 * Double.MAX_VALUE;
return new DataFusionConstant.DataFusionDoubleConstant(scaledDouble);
}
String doubleStr = Randomly.fromOptions("'NaN'::Double", "'+Inf'::Double", "'-Inf'::Double", "-0.0",
"+0.0");
return new DataFusionConstant.DataFusionDoubleConstant(doubleStr);
}
String doubleStr = Randomly.fromOptions("'NaN'::Double", "'+Inf'::Double", "'-Inf'::Double", "-0.0",
"+0.0");
return new DataFusionConstant.DataFusionDoubleConstant(doubleStr);
}

return new DataFusionConstant.DataFusionDoubleConstant(state.getRandomly().getDouble());
case NULL:
return DataFusionConstant.createNullConstant();
case STRING:
return new DataFusionConstant.DataFusionStringConstant(state.getRandomly().getString());
default:
dfAssert(false, "Unreachable. All branches should be eovered");
return new DataFusionConstant.DataFusionDoubleConstant(state.getRandomly().getDouble());
case NULL:
return DataFusionConstant.createNullConstant();
case STRING:
return new DataFusionConstant.DataFusionStringConstant(state.getRandomly().getString());
default:
dfAssert(false, "Unreachable. All branches should be eovered");
}

dfAssert(false, "Unreachable. All branches should be eovered");
Expand Down
42 changes: 21 additions & 21 deletions src/sqlancer/datafusion/DataFusionToStringVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,26 @@ private void visit(DataFusionFrom from) {
visit(from.tableList.get(0));
for (int i = 0; i < from.joinConditionList.size(); i++) {
switch (from.joinTypeList.get(i)) {
case INNER:
sb.append(Randomly.fromOptions(" JOIN ", " INNER JOIN "));
break;
case LEFT:
sb.append(Randomly.fromOptions(" LEFT JOIN ", " LEFT OUTER JOIN "));
break;
case RIGHT:
sb.append(Randomly.fromOptions(" RIGHT JOIN ", " RIGHT OUTER JOIN "));
break;
case FULL:
sb.append(Randomly.fromOptions(" FULL JOIN ", " FULL OUTER JOIN "));
break;
case CROSS:
sb.append(" CROSS JOIN ");
break;
case NATURAL:
sb.append(" NATURAL JOIN ");
break;
default:
dfAssert(false, "Unreachable");
case INNER:
sb.append(Randomly.fromOptions(" JOIN ", " INNER JOIN "));
break;
case LEFT:
sb.append(Randomly.fromOptions(" LEFT JOIN ", " LEFT OUTER JOIN "));
break;
case RIGHT:
sb.append(Randomly.fromOptions(" RIGHT JOIN ", " RIGHT OUTER JOIN "));
break;
case FULL:
sb.append(Randomly.fromOptions(" FULL JOIN ", " FULL OUTER JOIN "));
break;
case CROSS:
sb.append(" CROSS JOIN ");
break;
case NATURAL:
sb.append(" NATURAL JOIN ");
break;
default:
dfAssert(false, "Unreachable");
}

visit(from.tableList.get(i + 1)); // ti
Expand All @@ -95,7 +95,7 @@ private void visit(DataFusionConstant constant) {

private void visit(DataFusionSelect select) {
sb.append("SELECT ");
if (select.all && (!select.distinct)) {
if (select.all && !select.distinct) {
sb.append("ALL ");
}
if (select.distinct) {
Expand Down
4 changes: 2 additions & 2 deletions src/sqlancer/datafusion/ast/DataFusionConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public String toString() {
}

public static class DataFusionStringConstant extends DataFusionConstant {
private final String value;

public static String cleanString(String input) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
Expand All @@ -117,8 +119,6 @@ public static String cleanString(String input) {
return sb.toString();
}

private final String value;

public DataFusionStringConstant(String value) {
// cleanup invalid Utf8
this.value = cleanString(value.replace("'", "''"));
Expand Down
4 changes: 2 additions & 2 deletions src/sqlancer/datafusion/ast/DataFusionSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import sqlancer.datafusion.gen.DataFusionExpressionGenerator;

public class DataFusionSelect extends SelectBase<Node<DataFusionExpression>> implements Node<DataFusionExpression> {
public boolean all = false; // SELECT ALL
public boolean distinct = false; // SELECT DISTINCT
public boolean all; // SELECT ALL
public boolean distinct; // SELECT DISTINCT
public Optional<String> fetchColumnsString = Optional.empty(); // When available, override `fetchColumns` in base
// class's `Node` representation (for display)

Expand Down
Loading

0 comments on commit 0e5be03

Please sign in to comment.