Skip to content

Commit 64d9cbf

Browse files
chore: avoid Java version mismatch
When developing, the build (both on the command-line and in the IDE) frequently fails due to usage of unsupported Java language features for the target Java runtime. This is due to the the Java source version being set to a newer version than the target Java version. While this sometimes works, this combination is explicitly disallowed by the Java compiler. Source version must be equal to or less than the target version. This change uses the correct Java toolchain version for each sub-project. The exception being the core sub-project, since it targets Java 8 whereas ANTLR requires Java 11+ to run. Instead, the Java compiler release option is set to Java 8, ensuring that Java 8 bytecode is produced and that no APIs not present in Java 8 are used. While numerous code changes are required to adhere to the target Java language version, there are no functional changes. Signed-off-by: Mark S. Lewis <[email protected]>
1 parent b66913a commit 64d9cbf

File tree

69 files changed

+2200
-1758
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2200
-1758
lines changed

build.gradle.kts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,10 @@ allprojects {
4141
repositories { mavenCentral() }
4242

4343
tasks.configureEach<Test> {
44-
val javaToolchains = project.extensions.getByType<JavaToolchainService>()
4544
useJUnitPlatform()
46-
javaLauncher.set(javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(11)) })
4745
testLogging { exceptionFormat = TestExceptionFormat.FULL }
4846
}
49-
tasks.withType<JavaCompile> {
50-
sourceCompatibility = "17"
51-
if (project.name != "core") {
52-
options.release.set(11)
53-
} else {
54-
options.release.set(8)
55-
}
56-
dependsOn(submodulesUpdate)
57-
}
47+
tasks.withType<JavaCompile> { dependsOn(submodulesUpdate) }
5848

5949
group = "io.substrait"
6050
version = "${version}"

core/build.gradle.kts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ tasks {
233233
jar { manifest { from("build/generated/sources/manifest/META-INF/MANIFEST.MF") } }
234234
}
235235

236+
// Set the release instead of using a Java 8 toolchain since ANTLR requires Java 11+ to run
237+
tasks.withType<JavaCompile>().configureEach { options.release = 8 }
238+
236239
java {
237-
toolchain {
238-
languageVersion.set(JavaLanguageVersion.of(17))
239-
withJavadocJar()
240-
withSourcesJar()
241-
}
240+
withJavadocJar()
241+
withSourcesJar()
242242
}
243243

244244
configurations { runtimeClasspath { resolutionStrategy.activateDependencyLocking() } }

core/src/main/java/io/substrait/dsl/SubstraitBuilder.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ private Aggregate aggregate(
8787
Function<Rel, List<Aggregate.Measure>> measuresFn,
8888
Optional<Rel.Remap> remap,
8989
Rel input) {
90-
var groupings = groupingsFn.apply(input);
91-
var measures = measuresFn.apply(input);
90+
List<Aggregate.Grouping> groupings = groupingsFn.apply(input);
91+
List<Aggregate.Measure> measures = measuresFn.apply(input);
9292
return Aggregate.builder()
9393
.groupings(groupings)
9494
.measures(measures)
@@ -147,7 +147,7 @@ public Filter filter(Function<Rel, Expression> conditionFn, Rel.Remap remap, Rel
147147

148148
private Filter filter(
149149
Function<Rel, Expression> conditionFn, Optional<Rel.Remap> remap, Rel input) {
150-
var condition = conditionFn.apply(input);
150+
Expression condition = conditionFn.apply(input);
151151
return Filter.builder().input(input).condition(condition).remap(remap).build();
152152
}
153153

@@ -183,7 +183,7 @@ private Join join(
183183
Optional<Rel.Remap> remap,
184184
Rel left,
185185
Rel right) {
186-
var condition = conditionFn.apply(new JoinInput(left, right));
186+
Expression condition = conditionFn.apply(new JoinInput(left, right));
187187
return Join.builder()
188188
.left(left)
189189
.right(right)
@@ -263,7 +263,7 @@ private NestedLoopJoin nestedLoopJoin(
263263
Optional<Rel.Remap> remap,
264264
Rel left,
265265
Rel right) {
266-
var condition = conditionFn.apply(new JoinInput(left, right));
266+
Expression condition = conditionFn.apply(new JoinInput(left, right));
267267
return NestedLoopJoin.builder()
268268
.left(left)
269269
.right(right)
@@ -291,8 +291,8 @@ private NamedScan namedScan(
291291
Iterable<String> columnNames,
292292
Iterable<Type> types,
293293
Optional<Rel.Remap> remap) {
294-
var struct = Type.Struct.builder().addAllFields(types).nullable(false).build();
295-
var namedStruct = NamedStruct.of(columnNames, struct);
294+
Type.Struct struct = Type.Struct.builder().addAllFields(types).nullable(false).build();
295+
NamedStruct namedStruct = NamedStruct.of(columnNames, struct);
296296
return NamedScan.builder().names(tableName).initialSchema(namedStruct).remap(remap).build();
297297
}
298298

@@ -315,7 +315,7 @@ private Project project(
315315
Function<Rel, Iterable<? extends Expression>> expressionsFn,
316316
Optional<Rel.Remap> remap,
317317
Rel input) {
318-
var expressions = expressionsFn.apply(input);
318+
Iterable<? extends Expression> expressions = expressionsFn.apply(input);
319319
return Project.builder().input(input).expressions(expressions).remap(remap).build();
320320
}
321321

@@ -332,7 +332,7 @@ private Expand expand(
332332
Function<Rel, Iterable<? extends Expand.ExpandField>> fieldsFn,
333333
Optional<Rel.Remap> remap,
334334
Rel input) {
335-
var fields = fieldsFn.apply(input);
335+
Iterable<? extends Expand.ExpandField> fields = fieldsFn.apply(input);
336336
return Expand.builder().input(input).fields(fields).remap(remap).build();
337337
}
338338

@@ -363,7 +363,7 @@ private Sort sort(
363363
Function<Rel, Iterable<? extends Expression.SortField>> sortFieldFn,
364364
Optional<Rel.Remap> remap,
365365
Rel input) {
366-
var condition = sortFieldFn.apply(input);
366+
Iterable<? extends Expression.SortField> condition = sortFieldFn.apply(input);
367367
return Sort.builder().input(input).sortFields(condition).remap(remap).build();
368368
}
369369

@@ -465,7 +465,7 @@ public Switch switchExpression(
465465

466466
public AggregateFunctionInvocation aggregateFn(
467467
String namespace, String key, Type outputType, Expression... args) {
468-
var declaration =
468+
SimpleExtension.AggregateFunctionVariant declaration =
469469
extensions.getAggregateFunction(SimpleExtension.FunctionAnchor.of(namespace, key));
470470
return AggregateFunctionInvocation.builder()
471471
.arguments(Arrays.stream(args).collect(java.util.stream.Collectors.toList()))
@@ -477,7 +477,7 @@ public AggregateFunctionInvocation aggregateFn(
477477
}
478478

479479
public Aggregate.Grouping grouping(Rel input, int... indexes) {
480-
var columns = fieldReferences(input, indexes);
480+
List<FieldReference> columns = fieldReferences(input, indexes);
481481
return Aggregate.Grouping.builder().addAllExpressions(columns).build();
482482
}
483483

@@ -486,7 +486,7 @@ public Aggregate.Grouping grouping(Expression... expressions) {
486486
}
487487

488488
public Aggregate.Measure count(Rel input, int field) {
489-
var declaration =
489+
SimpleExtension.AggregateFunctionVariant declaration =
490490
extensions.getAggregateFunction(
491491
SimpleExtension.FunctionAnchor.of(
492492
DefaultExtensionCatalog.FUNCTIONS_AGGREGATE_GENERIC, "count:any"));
@@ -563,7 +563,7 @@ public Aggregate.Measure sum0(Expression expr) {
563563
private Aggregate.Measure singleArgumentArithmeticAggregate(
564564
Expression expr, String functionName, Type outputType) {
565565
String typeString = ToTypeString.apply(expr.getType());
566-
var declaration =
566+
SimpleExtension.AggregateFunctionVariant declaration =
567567
extensions.getAggregateFunction(
568568
SimpleExtension.FunctionAnchor.of(
569569
DefaultExtensionCatalog.FUNCTIONS_ARITHMETIC,
@@ -585,7 +585,7 @@ private Aggregate.Measure singleArgumentArithmeticAggregate(
585585

586586
public Expression.ScalarFunctionInvocation negate(Expression expr) {
587587
// output type of negate is the same as the input type
588-
var outputType = expr.getType();
588+
Type outputType = expr.getType();
589589
return scalarFn(
590590
DefaultExtensionCatalog.FUNCTIONS_ARITHMETIC,
591591
String.format("negate:%s", ToTypeString.apply(outputType)),
@@ -611,12 +611,12 @@ public Expression.ScalarFunctionInvocation divide(Expression left, Expression ri
611611

612612
private Expression.ScalarFunctionInvocation arithmeticFunction(
613613
String fname, Expression left, Expression right) {
614-
var leftTypeStr = ToTypeString.apply(left.getType());
615-
var rightTypeStr = ToTypeString.apply(right.getType());
616-
var key = String.format("%s:%s_%s", fname, leftTypeStr, rightTypeStr);
614+
String leftTypeStr = ToTypeString.apply(left.getType());
615+
String rightTypeStr = ToTypeString.apply(right.getType());
616+
String key = String.format("%s:%s_%s", fname, leftTypeStr, rightTypeStr);
617617

618-
var isOutputNullable = left.getType().nullable() || right.getType().nullable();
619-
var outputType = left.getType();
618+
boolean isOutputNullable = left.getType().nullable() || right.getType().nullable();
619+
Type outputType = left.getType();
620620
outputType =
621621
isOutputNullable
622622
? TypeCreator.asNullable(outputType)
@@ -633,14 +633,14 @@ public Expression.ScalarFunctionInvocation equal(Expression left, Expression rig
633633
public Expression.ScalarFunctionInvocation or(Expression... args) {
634634
// If any arg is nullable, the output of or is potentially nullable
635635
// For example: false or null = null
636-
var isOutputNullable = Arrays.stream(args).anyMatch(a -> a.getType().nullable());
637-
var outputType = isOutputNullable ? N.BOOLEAN : R.BOOLEAN;
636+
boolean isOutputNullable = Arrays.stream(args).anyMatch(a -> a.getType().nullable());
637+
Type outputType = isOutputNullable ? N.BOOLEAN : R.BOOLEAN;
638638
return scalarFn(DefaultExtensionCatalog.FUNCTIONS_BOOLEAN, "or:bool", outputType, args);
639639
}
640640

641641
public Expression.ScalarFunctionInvocation scalarFn(
642642
String namespace, String key, Type outputType, FunctionArg... args) {
643-
var declaration =
643+
SimpleExtension.ScalarFunctionVariant declaration =
644644
extensions.getScalarFunction(SimpleExtension.FunctionAnchor.of(namespace, key));
645645
return Expression.ScalarFunctionInvocation.builder()
646646
.declaration(declaration)
@@ -659,7 +659,7 @@ public Expression.WindowFunctionInvocation windowFn(
659659
WindowBound lowerBound,
660660
WindowBound upperBound,
661661
Expression... args) {
662-
var declaration =
662+
SimpleExtension.WindowFunctionVariant declaration =
663663
extensions.getWindowFunction(SimpleExtension.FunctionAnchor.of(namespace, key));
664664
return Expression.WindowFunctionInvocation.builder()
665665
.declaration(declaration)

core/src/main/java/io/substrait/expression/Expression.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ public io.substrait.proto.Expression.WindowFunction.BoundsType toProto() {
762762

763763
public static WindowBoundsType fromProto(
764764
io.substrait.proto.Expression.WindowFunction.BoundsType proto) {
765-
for (var v : values()) {
765+
for (WindowBoundsType v : values()) {
766766
if (v.proto == proto) {
767767
return v;
768768
}
@@ -903,7 +903,7 @@ public io.substrait.proto.Expression.Subquery.SetPredicate.PredicateOp toProto()
903903

904904
public static PredicateOp fromProto(
905905
io.substrait.proto.Expression.Subquery.SetPredicate.PredicateOp proto) {
906-
for (var v : values()) {
906+
for (PredicateOp v : values()) {
907907
if (v.proto == proto) {
908908
return v;
909909
}
@@ -929,7 +929,7 @@ public io.substrait.proto.AggregateFunction.AggregationInvocation toProto() {
929929
}
930930

931931
public static AggregationInvocation fromProto(AggregateFunction.AggregationInvocation proto) {
932-
for (var v : values()) {
932+
for (AggregationInvocation v : values()) {
933933
if (v.proto == proto) {
934934
return v;
935935
}
@@ -960,7 +960,7 @@ public io.substrait.proto.AggregationPhase toProto() {
960960
}
961961

962962
public static AggregationPhase fromProto(io.substrait.proto.AggregationPhase proto) {
963-
for (var v : values()) {
963+
for (AggregationPhase v : values()) {
964964
if (v.proto == proto) {
965965
return v;
966966
}
@@ -988,7 +988,7 @@ public io.substrait.proto.SortField.SortDirection toProto() {
988988
}
989989

990990
public static SortDirection fromProto(io.substrait.proto.SortField.SortDirection proto) {
991-
for (var v : values()) {
991+
for (SortDirection v : values()) {
992992
if (v.proto == proto) {
993993
return v;
994994
}
@@ -1016,7 +1016,7 @@ public io.substrait.proto.Expression.Cast.FailureBehavior toProto() {
10161016

10171017
public static FailureBehavior fromProto(
10181018
io.substrait.proto.Expression.Cast.FailureBehavior proto) {
1019-
for (var v : values()) {
1019+
for (FailureBehavior v : values()) {
10201020
if (v.proto == proto) {
10211021
return v;
10221022
}

core/src/main/java/io/substrait/expression/ExpressionCreator.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.substrait.type.Type;
88
import io.substrait.util.DecimalUtil;
99
import java.math.BigDecimal;
10+
import java.nio.ByteBuffer;
1011
import java.time.Instant;
1112
import java.time.LocalDateTime;
1213
import java.time.ZoneOffset;
@@ -89,7 +90,7 @@ public static Expression.TimestampLiteral timestamp(boolean nullable, long value
8990
*/
9091
@Deprecated
9192
public static Expression.TimestampLiteral timestamp(boolean nullable, LocalDateTime value) {
92-
var epochMicro =
93+
long epochMicro =
9394
TimeUnit.SECONDS.toMicros(value.toEpochSecond(ZoneOffset.UTC))
9495
+ TimeUnit.NANOSECONDS.toMicros(value.toLocalTime().getNano());
9596
return timestamp(nullable, epochMicro);
@@ -127,7 +128,7 @@ public static Expression.TimestampTZLiteral timestampTZ(boolean nullable, long v
127128
*/
128129
@Deprecated
129130
public static Expression.TimestampTZLiteral timestampTZ(boolean nullable, Instant value) {
130-
var epochMicro =
131+
long epochMicro =
131132
TimeUnit.SECONDS.toMicros(value.getEpochSecond())
132133
+ TimeUnit.NANOSECONDS.toMicros(value.getNano());
133134
return timestampTZ(nullable, epochMicro);
@@ -195,7 +196,7 @@ public static Expression.IntervalCompoundLiteral intervalCompound(
195196
}
196197

197198
public static Expression.UUIDLiteral uuid(boolean nullable, ByteString uuid) {
198-
var bb = uuid.asReadOnlyByteBuffer();
199+
ByteBuffer bb = uuid.asReadOnlyByteBuffer();
199200
return Expression.UUIDLiteral.builder()
200201
.nullable(nullable)
201202
.value(new UUID(bb.getLong(), bb.getLong()))
@@ -237,7 +238,7 @@ public static Expression.DecimalLiteral decimal(
237238

238239
public static Expression.DecimalLiteral decimal(
239240
boolean nullable, BigDecimal value, int precision, int scale) {
240-
var twosComplement = DecimalUtil.encodeDecimalIntoBytes(value, scale, 16);
241+
byte[] twosComplement = DecimalUtil.encodeDecimalIntoBytes(value, scale, 16);
241242

242243
return Expression.DecimalLiteral.builder()
243244
.nullable(nullable)

core/src/main/java/io/substrait/expression/FieldReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ private static FieldReference of(
222222
Collections.reverse(segments);
223223
for (int i = 0; i < segments.size(); i++) {
224224
if (i == 0) {
225-
var last = segments.get(0);
225+
ReferenceSegment last = segments.get(0);
226226
reference =
227227
struct == null ? last.constructOnExpression(expression) : last.constructOnRoot(struct);
228228
} else {

core/src/main/java/io/substrait/expression/FunctionArg.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ static FuncArgVisitor<FunctionArgument, RuntimeException> toProto(
3535
@Override
3636
public FunctionArgument visitExpr(SimpleExtension.Function fnDef, int argIdx, Expression e)
3737
throws RuntimeException {
38-
var pE = e.accept(expressionVisitor);
38+
io.substrait.proto.Expression pE = e.accept(expressionVisitor);
3939
return FunctionArgument.newBuilder().setValue(pE).build();
4040
}
4141

4242
@Override
4343
public FunctionArgument visitType(SimpleExtension.Function fnDef, int argIdx, Type t)
4444
throws RuntimeException {
45-
var pTyp = t.accept(typeVisitor);
45+
io.substrait.proto.Type pTyp = t.accept(typeVisitor);
4646
return FunctionArgument.newBuilder().setType(pTyp).build();
4747
}
4848

4949
@Override
5050
public FunctionArgument visitEnumArg(SimpleExtension.Function fnDef, int argIdx, EnumArg ea)
5151
throws RuntimeException {
52-
var enumBldr = FunctionArgument.newBuilder();
52+
FunctionArgument.Builder enumBldr = FunctionArgument.newBuilder();
5353

5454
if (ea.value().isPresent()) {
5555
enumBldr = enumBldr.setEnum(ea.value().get());
@@ -75,18 +75,22 @@ public ProtoFrom(
7575

7676
public FunctionArg convert(
7777
SimpleExtension.Function funcDef, int argIdx, FunctionArgument fArg) {
78-
return switch (fArg.getArgTypeCase()) {
79-
case TYPE -> protoTypeConverter.from(fArg.getType());
80-
case VALUE -> protoExprConverter.from(fArg.getValue());
81-
case ENUM -> {
82-
SimpleExtension.EnumArgument enumArgDef =
83-
(SimpleExtension.EnumArgument) funcDef.args().get(argIdx);
84-
var optionValue = fArg.getEnum();
85-
yield EnumArg.of(enumArgDef, optionValue);
86-
}
87-
default -> throw new UnsupportedOperationException(
88-
String.format("Unable to convert FunctionArgument %s.", fArg));
89-
};
78+
switch (fArg.getArgTypeCase()) {
79+
case TYPE:
80+
return protoTypeConverter.from(fArg.getType());
81+
case VALUE:
82+
return protoExprConverter.from(fArg.getValue());
83+
case ENUM:
84+
{
85+
SimpleExtension.EnumArgument enumArgDef =
86+
(SimpleExtension.EnumArgument) funcDef.args().get(argIdx);
87+
String optionValue = fArg.getEnum();
88+
return EnumArg.of(enumArgDef, optionValue);
89+
}
90+
default:
91+
throw new UnsupportedOperationException(
92+
String.format("Unable to convert FunctionArgument %s.", fArg));
93+
}
9094
}
9195
}
9296
}

0 commit comments

Comments
 (0)