Skip to content

style: avoid using star imports #438

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id("java")
id("idea")
id("com.github.vlsi.gradle-extensions") version "1.74"
id("com.diffplug.spotless") version "6.19.0"
id("com.diffplug.spotless") version "7.1.0"
id("org.jreleaser") version "1.18.0" apply false
}

Expand Down Expand Up @@ -67,6 +67,7 @@ allprojects {
googleJavaFormat()
removeUnusedImports()
trimTrailingWhitespace()
removeWildcardImports()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
id("idea")
id("antlr")
id("com.google.protobuf") version "0.9.4"
id("com.diffplug.spotless") version "6.19.0"
id("com.diffplug.spotless") version "7.1.0"
id("com.gradleup.shadow") version "8.3.6"
id("org.jreleaser")
}
Expand Down Expand Up @@ -263,7 +263,7 @@ project.configure<IdeaModel> {
generatedSourceDirs.addAll(
listOf(
file("build/generated/sources/antlr/main"),
file("build/generated/source/proto/main/java")
file("build/generated/source/proto/main/java"),
)
)
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/io/substrait/expression/FunctionArg.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public FunctionArg convert(
var optionValue = fArg.getEnum();
yield EnumArg.of(enumArgDef, optionValue);
}
default -> throw new UnsupportedOperationException(
String.format("Unable to convert FunctionArgument %s.", fArg));
default ->
throw new UnsupportedOperationException(
String.format("Unable to convert FunctionArgument %s.", fArg));
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,34 @@ public FieldReference from(io.substrait.proto.Expression.FieldReference referenc
segment = listElement.getChild();
yield FieldReference.ListElement.of(listElement.getOffset());
}
case REFERENCETYPE_NOT_SET -> throw new IllegalArgumentException(
"Unhandled type: " + segment.getReferenceTypeCase());
case REFERENCETYPE_NOT_SET ->
throw new IllegalArgumentException(
"Unhandled type: " + segment.getReferenceTypeCase());
});
}
Collections.reverse(segments);
var fieldReference =
switch (reference.getRootTypeCase()) {
case EXPRESSION -> FieldReference.ofExpression(
from(reference.getExpression()), segments);
case EXPRESSION ->
FieldReference.ofExpression(from(reference.getExpression()), segments);
case ROOT_REFERENCE -> FieldReference.ofRoot(rootType, segments);
case OUTER_REFERENCE -> FieldReference.newRootStructOuterReference(
reference.getDirectReference().getStructField().getField(),
rootType,
reference.getOuterReference().getStepsOut());
case ROOTTYPE_NOT_SET -> throw new IllegalArgumentException(
"Unhandled type: " + reference.getRootTypeCase());
case OUTER_REFERENCE ->
FieldReference.newRootStructOuterReference(
reference.getDirectReference().getStructField().getField(),
rootType,
reference.getOuterReference().getStepsOut());
case ROOTTYPE_NOT_SET ->
throw new IllegalArgumentException(
"Unhandled type: " + reference.getRootTypeCase());
};

return fieldReference;
}
case MASKED_REFERENCE -> throw new IllegalArgumentException(
"Unsupported type: " + reference.getReferenceTypeCase());
default -> throw new IllegalArgumentException(
"Unhandled type: " + reference.getReferenceTypeCase());
case MASKED_REFERENCE ->
throw new IllegalArgumentException(
"Unsupported type: " + reference.getReferenceTypeCase());
default ->
throw new IllegalArgumentException("Unhandled type: " + reference.getReferenceTypeCase());
}
}

Expand Down Expand Up @@ -177,10 +181,11 @@ public Expression from(io.substrait.proto.Expression expr) {
.collect(java.util.stream.Collectors.toList()))
.build();
}
case CAST -> ExpressionCreator.cast(
protoTypeConverter.from(expr.getCast().getType()),
from(expr.getCast().getInput()),
Expression.FailureBehavior.fromProto(expr.getCast().getFailureBehavior()));
case CAST ->
ExpressionCreator.cast(
protoTypeConverter.from(expr.getCast().getType()),
from(expr.getCast().getInput()),
Expression.FailureBehavior.fromProto(expr.getCast().getFailureBehavior()));
case SUBQUERY -> {
switch (expr.getSubquery().getSubqueryTypeCase()) {
case SET_PREDICATE -> {
Expand Down Expand Up @@ -232,9 +237,9 @@ public Type visit(Type.Struct type) throws RuntimeException {
}
}

// TODO enum.
case ENUM -> throw new UnsupportedOperationException(
"Unsupported type: " + expr.getRexTypeCase());
// TODO enum.
case ENUM ->
throw new UnsupportedOperationException("Unsupported type: " + expr.getRexTypeCase());
default -> throw new IllegalArgumentException("Unknown type: " + expr.getRexTypeCase());
};
}
Expand Down Expand Up @@ -320,9 +325,9 @@ private WindowBound toWindowBound(io.substrait.proto.Expression.WindowFunction.B
case CURRENT_ROW -> WindowBound.CURRENT_ROW;
case UNBOUNDED -> WindowBound.UNBOUNDED;
case KIND_NOT_SET ->
// per the spec, the lower and upper bounds default to the start or end of the partition
// respectively if not set
WindowBound.UNBOUNDED;
// per the spec, the lower and upper bounds default to the start or end of the partition
// respectively if not set
WindowBound.UNBOUNDED;
};
}

Expand All @@ -338,22 +343,25 @@ public Expression.Literal from(io.substrait.proto.Expression.Literal literal) {
case STRING -> ExpressionCreator.string(literal.getNullable(), literal.getString());
case BINARY -> ExpressionCreator.binary(literal.getNullable(), literal.getBinary());
case TIMESTAMP -> ExpressionCreator.timestamp(literal.getNullable(), literal.getTimestamp());
case TIMESTAMP_TZ -> ExpressionCreator.timestampTZ(
literal.getNullable(), literal.getTimestampTz());
case PRECISION_TIMESTAMP -> ExpressionCreator.precisionTimestamp(
literal.getNullable(),
literal.getPrecisionTimestamp().getValue(),
literal.getPrecisionTimestamp().getPrecision());
case PRECISION_TIMESTAMP_TZ -> ExpressionCreator.precisionTimestampTZ(
literal.getNullable(),
literal.getPrecisionTimestampTz().getValue(),
literal.getPrecisionTimestampTz().getPrecision());
case TIMESTAMP_TZ ->
ExpressionCreator.timestampTZ(literal.getNullable(), literal.getTimestampTz());
case PRECISION_TIMESTAMP ->
ExpressionCreator.precisionTimestamp(
literal.getNullable(),
literal.getPrecisionTimestamp().getValue(),
literal.getPrecisionTimestamp().getPrecision());
case PRECISION_TIMESTAMP_TZ ->
ExpressionCreator.precisionTimestampTZ(
literal.getNullable(),
literal.getPrecisionTimestampTz().getValue(),
literal.getPrecisionTimestampTz().getPrecision());
case DATE -> ExpressionCreator.date(literal.getNullable(), literal.getDate());
case TIME -> ExpressionCreator.time(literal.getNullable(), literal.getTime());
case INTERVAL_YEAR_TO_MONTH -> ExpressionCreator.intervalYear(
literal.getNullable(),
literal.getIntervalYearToMonth().getYears(),
literal.getIntervalYearToMonth().getMonths());
case INTERVAL_YEAR_TO_MONTH ->
ExpressionCreator.intervalYear(
literal.getNullable(),
literal.getIntervalYearToMonth().getYears(),
literal.getIntervalYearToMonth().getMonths());
case INTERVAL_DAY_TO_SECOND -> {
// Handle deprecated version that doesn't provide precision and that uses microseconds
// instead of subseconds, for backwards compatibility
Expand Down Expand Up @@ -387,24 +395,30 @@ public Expression.Literal from(io.substrait.proto.Expression.Literal literal) {
literal.getIntervalCompound().getIntervalDayToSecond().getPrecision());
}
case FIXED_CHAR -> ExpressionCreator.fixedChar(literal.getNullable(), literal.getFixedChar());
case VAR_CHAR -> ExpressionCreator.varChar(
literal.getNullable(), literal.getVarChar().getValue(), literal.getVarChar().getLength());
case FIXED_BINARY -> ExpressionCreator.fixedBinary(
literal.getNullable(), literal.getFixedBinary());
case DECIMAL -> ExpressionCreator.decimal(
literal.getNullable(),
literal.getDecimal().getValue(),
literal.getDecimal().getPrecision(),
literal.getDecimal().getScale());
case STRUCT -> ExpressionCreator.struct(
literal.getNullable(),
literal.getStruct().getFieldsList().stream()
.map(this::from)
.collect(java.util.stream.Collectors.toList()));
case MAP -> ExpressionCreator.map(
literal.getNullable(),
literal.getMap().getKeyValuesList().stream()
.collect(Collectors.toMap(kv -> from(kv.getKey()), kv -> from(kv.getValue()))));
case VAR_CHAR ->
ExpressionCreator.varChar(
literal.getNullable(),
literal.getVarChar().getValue(),
literal.getVarChar().getLength());
case FIXED_BINARY ->
ExpressionCreator.fixedBinary(literal.getNullable(), literal.getFixedBinary());
case DECIMAL ->
ExpressionCreator.decimal(
literal.getNullable(),
literal.getDecimal().getValue(),
literal.getDecimal().getPrecision(),
literal.getDecimal().getScale());
case STRUCT ->
ExpressionCreator.struct(
literal.getNullable(),
literal.getStruct().getFieldsList().stream()
.map(this::from)
.collect(java.util.stream.Collectors.toList()));
case MAP ->
ExpressionCreator.map(
literal.getNullable(),
literal.getMap().getKeyValuesList().stream()
.collect(Collectors.toMap(kv -> from(kv.getKey()), kv -> from(kv.getValue()))));
case EMPTY_MAP -> {
// literal.getNullable() is intentionally ignored in favor of the nullability
// specified in the literal.getEmptyMap() type.
Expand All @@ -413,11 +427,12 @@ public Expression.Literal from(io.substrait.proto.Expression.Literal literal) {
}
case UUID -> ExpressionCreator.uuid(literal.getNullable(), literal.getUuid());
case NULL -> ExpressionCreator.typedNull(protoTypeConverter.from(literal.getNull()));
case LIST -> ExpressionCreator.list(
literal.getNullable(),
literal.getList().getValuesList().stream()
.map(this::from)
.collect(java.util.stream.Collectors.toList()));
case LIST ->
ExpressionCreator.list(
literal.getNullable(),
literal.getList().getValuesList().stream()
.map(this::from)
.collect(java.util.stream.Collectors.toList()));
case EMPTY_LIST -> {
// literal.getNullable() is intentionally ignored in favor of the nullability
// specified in the literal.getEmptyList() type.
Expand All @@ -430,8 +445,8 @@ public Expression.Literal from(io.substrait.proto.Expression.Literal literal) {
yield ExpressionCreator.userDefinedLiteral(
literal.getNullable(), type.uri(), type.name(), userDefinedLiteral.getValue());
}
default -> throw new IllegalStateException(
"Unexpected value: " + literal.getLiteralTypeCase());
default ->
throw new IllegalStateException("Unexpected value: " + literal.getLiteralTypeCase());
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public ExtendedExpression toProto(
builder.addReferredExpr(expressionReferenceBuilder);
} else if (expressionReference
instanceof
io.substrait.extendedexpression.ExtendedExpression.AggregateFunctionReference
aft) {
io.substrait.extendedexpression.ExtendedExpression.AggregateFunctionReference aft) {
ExpressionReference.Builder expressionReferenceBuilder =
ExpressionReference.newBuilder()
.setMeasure(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import io.substrait.proto.Plan;
import io.substrait.proto.SimpleExtensionDeclaration;
import io.substrait.proto.SimpleExtensionURI;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
import io.substrait.util.Util;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down
32 changes: 16 additions & 16 deletions core/src/main/java/io/substrait/relation/Join.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,26 @@ public static JoinType fromProto(JoinRel.JoinType proto) {
protected Type.Struct deriveRecordType() {
Stream<Type> leftTypes =
switch (getJoinType()) {
case RIGHT, OUTER, RIGHT_SINGLE -> getLeft().getRecordType().fields().stream()
.map(TypeCreator::asNullable);
case RIGHT_SEMI, RIGHT_ANTI -> Stream
.of(); // these are right joins which ignore left side columns
case RIGHT_MARK -> Stream.of(
TypeCreator.REQUIRED
.BOOLEAN); // right mark join keeps all fields from right and adds a boolean mark
// field
case RIGHT, OUTER, RIGHT_SINGLE ->
getLeft().getRecordType().fields().stream().map(TypeCreator::asNullable);
case RIGHT_SEMI, RIGHT_ANTI ->
// these are right joins which ignore left side columns
Stream.of();
case RIGHT_MARK ->
// right mark join keeps all fields from right and adds a boolean mark field
Stream.of(TypeCreator.REQUIRED.BOOLEAN);
default -> getLeft().getRecordType().fields().stream();
};
Stream<Type> rightTypes =
switch (getJoinType()) {
case LEFT, OUTER, LEFT_SINGLE -> getRight().getRecordType().fields().stream()
.map(TypeCreator::asNullable);
case SEMI, ANTI, LEFT_SEMI, LEFT_ANTI -> Stream
.of(); // these are left joins which ignore right side columns
case LEFT_MARK -> Stream.of(
TypeCreator.REQUIRED
.BOOLEAN); // left mark join keeps all fields from left and adds a boolean mark
// field
case LEFT, OUTER, LEFT_SINGLE ->
getRight().getRecordType().fields().stream().map(TypeCreator::asNullable);
case SEMI, ANTI, LEFT_SEMI, LEFT_ANTI ->
// these are left joins which ignore right side columns
Stream.of();
case LEFT_MARK ->
// left mark join keeps all fields from left and adds a boolean mark field
Stream.of(TypeCreator.REQUIRED.BOOLEAN);
default -> getRight().getRecordType().fields().stream();
};
return TypeCreator.REQUIRED.struct(Stream.concat(leftTypes, rightTypes));
Expand Down
31 changes: 18 additions & 13 deletions core/src/main/java/io/substrait/relation/ProtoRelConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ protected Rel newUpdate(UpdateRel rel) {
case NAMED_TABLE -> {
return newNamedUpdate(rel);
}
default -> throw new UnsupportedOperationException(
"Unsupported UpdateTypeCase of " + relType);
default ->
throw new UnsupportedOperationException("Unsupported UpdateTypeCase of " + relType);
}
}

Expand Down Expand Up @@ -608,17 +608,22 @@ protected Expand newExpand(ExpandRel rel) {
.map(
expandField ->
switch (expandField.getFieldTypeCase()) {
case CONSISTENT_FIELD -> Expand.ConsistentField.builder()
.expression(converter.from(expandField.getConsistentField()))
.build();
case SWITCHING_FIELD -> Expand.SwitchingField.builder()
.duplicates(
expandField.getSwitchingField().getDuplicatesList().stream()
.map(converter::from)
.collect(java.util.stream.Collectors.toList()))
.build();
case FIELDTYPE_NOT_SET -> throw new UnsupportedOperationException(
"Expand fields not set");
case CONSISTENT_FIELD ->
Expand.ConsistentField.builder()
.expression(converter.from(expandField.getConsistentField()))
.build();
case SWITCHING_FIELD ->
Expand.SwitchingField.builder()
.duplicates(
expandField
.getSwitchingField()
.getDuplicatesList()
.stream()
.map(converter::from)
.collect(java.util.stream.Collectors.toList()))
.build();
case FIELDTYPE_NOT_SET ->
throw new UnsupportedOperationException("Expand fields not set");
})
.collect(java.util.stream.Collectors.toList()));

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/io/substrait/relation/Set.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ protected Type.Struct deriveRecordType() {
case UNKNOWN -> first; // alternative would be to throw an exception
case MINUS_PRIMARY, MINUS_PRIMARY_ALL, MINUS_MULTISET -> first;
case INTERSECTION_PRIMARY -> coalesceNullabilityIntersectionPrimary(first, rest);
case INTERSECTION_MULTISET, INTERSECTION_MULTISET_ALL -> coalesceNullabilityIntersection(
first, rest);
case INTERSECTION_MULTISET, INTERSECTION_MULTISET_ALL ->
coalesceNullabilityIntersection(first, rest);
case UNION_DISTINCT, UNION_ALL -> coalesceNullabilityUnion(first, rest);
};
}
Expand Down
Loading
Loading