Skip to content

Commit 39ea6bb

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 8f2c6ea commit 39ea6bb

File tree

83 files changed

+2315
-1841
lines changed

Some content is hidden

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

83 files changed

+2315
-1841
lines changed

build.gradle.kts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ dependencies {
2626
implementation("org.slf4j:slf4j-api:${SLF4J_VERSION}")
2727
annotationProcessor("org.immutables:value:${IMMUTABLES_VERSION}")
2828
compileOnly("org.immutables:value-annotations:${IMMUTABLES_VERSION}")
29-
annotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2")
30-
compileOnly("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2")
3129
}
3230

3331
val submodulesUpdate by
@@ -41,20 +39,10 @@ allprojects {
4139
repositories { mavenCentral() }
4240

4341
tasks.configureEach<Test> {
44-
val javaToolchains = project.extensions.getByType<JavaToolchainService>()
4542
useJUnitPlatform()
46-
javaLauncher.set(javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(11)) })
4743
testLogging { exceptionFormat = TestExceptionFormat.FULL }
4844
}
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-
}
45+
tasks.withType<JavaCompile> { dependsOn(submodulesUpdate) }
5846

5947
group = "io.substrait"
6048
version = "${version}"

core/build.gradle.kts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ dependencies {
128128
implementation("org.slf4j:slf4j-api:${SLF4J_VERSION}")
129129
annotationProcessor("org.immutables:value:${IMMUTABLES_VERSION}")
130130
compileOnly("org.immutables:value-annotations:${IMMUTABLES_VERSION}")
131-
annotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2")
132-
compileOnly("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2")
133131
}
134132

135133
configurations[JavaPlugin.API_CONFIGURATION_NAME].let { apiConfiguration ->
@@ -233,12 +231,12 @@ tasks {
233231
jar { manifest { from("build/generated/sources/manifest/META-INF/MANIFEST.MF") } }
234232
}
235233

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

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

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

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.substrait.dsl;
22

3-
import com.github.bsideup.jabel.Desugar;
43
import io.substrait.expression.AggregateFunctionInvocation;
54
import io.substrait.expression.Expression;
65
import io.substrait.expression.Expression.Cast;
@@ -87,8 +86,8 @@ private Aggregate aggregate(
8786
Function<Rel, List<Aggregate.Measure>> measuresFn,
8887
Optional<Rel.Remap> remap,
8988
Rel input) {
90-
var groupings = groupingsFn.apply(input);
91-
var measures = measuresFn.apply(input);
89+
List<Aggregate.Grouping> groupings = groupingsFn.apply(input);
90+
List<Aggregate.Measure> measures = measuresFn.apply(input);
9291
return Aggregate.builder()
9392
.groupings(groupings)
9493
.measures(measures)
@@ -147,12 +146,27 @@ public Filter filter(Function<Rel, Expression> conditionFn, Rel.Remap remap, Rel
147146

148147
private Filter filter(
149148
Function<Rel, Expression> conditionFn, Optional<Rel.Remap> remap, Rel input) {
150-
var condition = conditionFn.apply(input);
149+
Expression condition = conditionFn.apply(input);
151150
return Filter.builder().input(input).condition(condition).remap(remap).build();
152151
}
153152

154-
@Desugar
155-
public record JoinInput(Rel left, Rel right) {}
153+
public static final class JoinInput {
154+
private final Rel left;
155+
private final Rel right;
156+
157+
JoinInput(Rel left, Rel right) {
158+
this.left = left;
159+
this.right = right;
160+
}
161+
162+
public Rel left() {
163+
return left;
164+
}
165+
166+
public Rel right() {
167+
return right;
168+
}
169+
}
156170

157171
public Join innerJoin(Function<JoinInput, Expression> conditionFn, Rel left, Rel right) {
158172
return join(conditionFn, Join.JoinType.INNER, left, right);
@@ -183,7 +197,7 @@ private Join join(
183197
Optional<Rel.Remap> remap,
184198
Rel left,
185199
Rel right) {
186-
var condition = conditionFn.apply(new JoinInput(left, right));
200+
Expression condition = conditionFn.apply(new JoinInput(left, right));
187201
return Join.builder()
188202
.left(left)
189203
.right(right)
@@ -263,7 +277,7 @@ private NestedLoopJoin nestedLoopJoin(
263277
Optional<Rel.Remap> remap,
264278
Rel left,
265279
Rel right) {
266-
var condition = conditionFn.apply(new JoinInput(left, right));
280+
Expression condition = conditionFn.apply(new JoinInput(left, right));
267281
return NestedLoopJoin.builder()
268282
.left(left)
269283
.right(right)
@@ -291,8 +305,8 @@ private NamedScan namedScan(
291305
Iterable<String> columnNames,
292306
Iterable<Type> types,
293307
Optional<Rel.Remap> remap) {
294-
var struct = Type.Struct.builder().addAllFields(types).nullable(false).build();
295-
var namedStruct = NamedStruct.of(columnNames, struct);
308+
Type.Struct struct = Type.Struct.builder().addAllFields(types).nullable(false).build();
309+
NamedStruct namedStruct = NamedStruct.of(columnNames, struct);
296310
return NamedScan.builder().names(tableName).initialSchema(namedStruct).remap(remap).build();
297311
}
298312

@@ -315,7 +329,7 @@ private Project project(
315329
Function<Rel, Iterable<? extends Expression>> expressionsFn,
316330
Optional<Rel.Remap> remap,
317331
Rel input) {
318-
var expressions = expressionsFn.apply(input);
332+
Iterable<? extends Expression> expressions = expressionsFn.apply(input);
319333
return Project.builder().input(input).expressions(expressions).remap(remap).build();
320334
}
321335

@@ -332,7 +346,7 @@ private Expand expand(
332346
Function<Rel, Iterable<? extends Expand.ExpandField>> fieldsFn,
333347
Optional<Rel.Remap> remap,
334348
Rel input) {
335-
var fields = fieldsFn.apply(input);
349+
Iterable<? extends Expand.ExpandField> fields = fieldsFn.apply(input);
336350
return Expand.builder().input(input).fields(fields).remap(remap).build();
337351
}
338352

@@ -363,7 +377,7 @@ private Sort sort(
363377
Function<Rel, Iterable<? extends Expression.SortField>> sortFieldFn,
364378
Optional<Rel.Remap> remap,
365379
Rel input) {
366-
var condition = sortFieldFn.apply(input);
380+
Iterable<? extends Expression.SortField> condition = sortFieldFn.apply(input);
367381
return Sort.builder().input(input).sortFields(condition).remap(remap).build();
368382
}
369383

@@ -465,7 +479,7 @@ public Switch switchExpression(
465479

466480
public AggregateFunctionInvocation aggregateFn(
467481
String namespace, String key, Type outputType, Expression... args) {
468-
var declaration =
482+
SimpleExtension.AggregateFunctionVariant declaration =
469483
extensions.getAggregateFunction(SimpleExtension.FunctionAnchor.of(namespace, key));
470484
return AggregateFunctionInvocation.builder()
471485
.arguments(Arrays.stream(args).collect(java.util.stream.Collectors.toList()))
@@ -477,7 +491,7 @@ public AggregateFunctionInvocation aggregateFn(
477491
}
478492

479493
public Aggregate.Grouping grouping(Rel input, int... indexes) {
480-
var columns = fieldReferences(input, indexes);
494+
List<FieldReference> columns = fieldReferences(input, indexes);
481495
return Aggregate.Grouping.builder().addAllExpressions(columns).build();
482496
}
483497

@@ -486,7 +500,7 @@ public Aggregate.Grouping grouping(Expression... expressions) {
486500
}
487501

488502
public Aggregate.Measure count(Rel input, int field) {
489-
var declaration =
503+
SimpleExtension.AggregateFunctionVariant declaration =
490504
extensions.getAggregateFunction(
491505
SimpleExtension.FunctionAnchor.of(
492506
DefaultExtensionCatalog.FUNCTIONS_AGGREGATE_GENERIC, "count:any"));
@@ -563,7 +577,7 @@ public Aggregate.Measure sum0(Expression expr) {
563577
private Aggregate.Measure singleArgumentArithmeticAggregate(
564578
Expression expr, String functionName, Type outputType) {
565579
String typeString = ToTypeString.apply(expr.getType());
566-
var declaration =
580+
SimpleExtension.AggregateFunctionVariant declaration =
567581
extensions.getAggregateFunction(
568582
SimpleExtension.FunctionAnchor.of(
569583
DefaultExtensionCatalog.FUNCTIONS_ARITHMETIC,
@@ -585,7 +599,7 @@ private Aggregate.Measure singleArgumentArithmeticAggregate(
585599

586600
public Expression.ScalarFunctionInvocation negate(Expression expr) {
587601
// output type of negate is the same as the input type
588-
var outputType = expr.getType();
602+
Type outputType = expr.getType();
589603
return scalarFn(
590604
DefaultExtensionCatalog.FUNCTIONS_ARITHMETIC,
591605
String.format("negate:%s", ToTypeString.apply(outputType)),
@@ -611,12 +625,12 @@ public Expression.ScalarFunctionInvocation divide(Expression left, Expression ri
611625

612626
private Expression.ScalarFunctionInvocation arithmeticFunction(
613627
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);
628+
String leftTypeStr = ToTypeString.apply(left.getType());
629+
String rightTypeStr = ToTypeString.apply(right.getType());
630+
String key = String.format("%s:%s_%s", fname, leftTypeStr, rightTypeStr);
617631

618-
var isOutputNullable = left.getType().nullable() || right.getType().nullable();
619-
var outputType = left.getType();
632+
boolean isOutputNullable = left.getType().nullable() || right.getType().nullable();
633+
Type outputType = left.getType();
620634
outputType =
621635
isOutputNullable
622636
? TypeCreator.asNullable(outputType)
@@ -633,14 +647,14 @@ public Expression.ScalarFunctionInvocation equal(Expression left, Expression rig
633647
public Expression.ScalarFunctionInvocation or(Expression... args) {
634648
// If any arg is nullable, the output of or is potentially nullable
635649
// 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;
650+
boolean isOutputNullable = Arrays.stream(args).anyMatch(a -> a.getType().nullable());
651+
Type outputType = isOutputNullable ? N.BOOLEAN : R.BOOLEAN;
638652
return scalarFn(DefaultExtensionCatalog.FUNCTIONS_BOOLEAN, "or:bool", outputType, args);
639653
}
640654

641655
public Expression.ScalarFunctionInvocation scalarFn(
642656
String namespace, String key, Type outputType, FunctionArg... args) {
643-
var declaration =
657+
SimpleExtension.ScalarFunctionVariant declaration =
644658
extensions.getScalarFunction(SimpleExtension.FunctionAnchor.of(namespace, key));
645659
return Expression.ScalarFunctionInvocation.builder()
646660
.declaration(declaration)
@@ -659,7 +673,7 @@ public Expression.WindowFunctionInvocation windowFn(
659673
WindowBound lowerBound,
660674
WindowBound upperBound,
661675
Expression... args) {
662-
var declaration =
676+
SimpleExtension.WindowFunctionVariant declaration =
663677
extensions.getWindowFunction(SimpleExtension.FunctionAnchor.of(namespace, key));
664678
return Expression.WindowFunctionInvocation.builder()
665679
.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
@@ -833,7 +833,7 @@ public io.substrait.proto.Expression.WindowFunction.BoundsType toProto() {
833833

834834
public static WindowBoundsType fromProto(
835835
io.substrait.proto.Expression.WindowFunction.BoundsType proto) {
836-
for (var v : values()) {
836+
for (WindowBoundsType v : values()) {
837837
if (v.proto == proto) {
838838
return v;
839839
}
@@ -984,7 +984,7 @@ public io.substrait.proto.Expression.Subquery.SetPredicate.PredicateOp toProto()
984984

985985
public static PredicateOp fromProto(
986986
io.substrait.proto.Expression.Subquery.SetPredicate.PredicateOp proto) {
987-
for (var v : values()) {
987+
for (PredicateOp v : values()) {
988988
if (v.proto == proto) {
989989
return v;
990990
}
@@ -1010,7 +1010,7 @@ public io.substrait.proto.AggregateFunction.AggregationInvocation toProto() {
10101010
}
10111011

10121012
public static AggregationInvocation fromProto(AggregateFunction.AggregationInvocation proto) {
1013-
for (var v : values()) {
1013+
for (AggregationInvocation v : values()) {
10141014
if (v.proto == proto) {
10151015
return v;
10161016
}
@@ -1041,7 +1041,7 @@ public io.substrait.proto.AggregationPhase toProto() {
10411041
}
10421042

10431043
public static AggregationPhase fromProto(io.substrait.proto.AggregationPhase proto) {
1044-
for (var v : values()) {
1044+
for (AggregationPhase v : values()) {
10451045
if (v.proto == proto) {
10461046
return v;
10471047
}
@@ -1069,7 +1069,7 @@ public io.substrait.proto.SortField.SortDirection toProto() {
10691069
}
10701070

10711071
public static SortDirection fromProto(io.substrait.proto.SortField.SortDirection proto) {
1072-
for (var v : values()) {
1072+
for (SortDirection v : values()) {
10731073
if (v.proto == proto) {
10741074
return v;
10751075
}
@@ -1097,7 +1097,7 @@ public io.substrait.proto.Expression.Cast.FailureBehavior toProto() {
10971097

10981098
public static FailureBehavior fromProto(
10991099
io.substrait.proto.Expression.Cast.FailureBehavior proto) {
1100-
for (var v : values()) {
1100+
for (FailureBehavior v : values()) {
11011101
if (v.proto == proto) {
11021102
return v;
11031103
}

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
@@ -225,7 +225,7 @@ private static FieldReference of(
225225
Collections.reverse(segments);
226226
for (int i = 0; i < segments.size(); i++) {
227227
if (i == 0) {
228-
var last = segments.get(0);
228+
ReferenceSegment last = segments.get(0);
229229
reference =
230230
struct == null ? last.constructOnExpression(expression) : last.constructOnRoot(struct);
231231
} else {

0 commit comments

Comments
 (0)