From b5aaca16737bdeab0f4ab54419953967de01834f Mon Sep 17 00:00:00 2001 From: Niels Pardon Date: Sun, 13 Jul 2025 11:24:33 +0200 Subject: [PATCH 1/2] style: avoid using star imports Signed-off-by: Niels Pardon --- .../extension/ExtensionCollector.java | 4 +- .../substrait/extension/SimpleExtension.java | 7 +- .../main/java/io/substrait/type/YamlRead.java | 5 +- .../ExtendedExpressionRoundTripTest.java | 6 +- .../java/io/substrait/relation/SetTest.java | 7 +- .../type/proto/GenericRoundtripTest.java | 2 +- .../isthmus/cli/RegisterAtRuntime.java | 26 ++++++- .../expression/FieldSelectionConverter.java | 4 +- .../isthmus/expression/LiteralConverter.java | 76 +++++++++++-------- .../io/substrait/isthmus/CalciteCallTest.java | 18 +++-- .../substrait/isthmus/CalciteLiteralTest.java | 69 +++++++++-------- .../AggregateFunctionConverterTest.java | 3 +- 12 files changed, 147 insertions(+), 80 deletions(-) diff --git a/core/src/main/java/io/substrait/extension/ExtensionCollector.java b/core/src/main/java/io/substrait/extension/ExtensionCollector.java index 36897835f..6108a9734 100644 --- a/core/src/main/java/io/substrait/extension/ExtensionCollector.java +++ b/core/src/main/java/io/substrait/extension/ExtensionCollector.java @@ -4,7 +4,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; /** diff --git a/core/src/main/java/io/substrait/extension/SimpleExtension.java b/core/src/main/java/io/substrait/extension/SimpleExtension.java index 9f7d64e6b..74f79253a 100644 --- a/core/src/main/java/io/substrait/extension/SimpleExtension.java +++ b/core/src/main/java/io/substrait/extension/SimpleExtension.java @@ -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; diff --git a/core/src/main/java/io/substrait/type/YamlRead.java b/core/src/main/java/io/substrait/type/YamlRead.java index bd473e2cc..7a9afe476 100644 --- a/core/src/main/java/io/substrait/type/YamlRead.java +++ b/core/src/main/java/io/substrait/type/YamlRead.java @@ -6,7 +6,10 @@ import io.substrait.extension.DefaultExtensionCatalog; import io.substrait.extension.SimpleExtension; import java.io.File; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; import org.slf4j.Logger; diff --git a/core/src/test/java/io/substrait/extendedexpression/ExtendedExpressionRoundTripTest.java b/core/src/test/java/io/substrait/extendedexpression/ExtendedExpressionRoundTripTest.java index b417b15a6..50ce1572b 100644 --- a/core/src/test/java/io/substrait/extendedexpression/ExtendedExpressionRoundTripTest.java +++ b/core/src/test/java/io/substrait/extendedexpression/ExtendedExpressionRoundTripTest.java @@ -2,7 +2,11 @@ import io.substrait.TestBase; import io.substrait.dsl.SubstraitBuilder; -import io.substrait.expression.*; +import io.substrait.expression.AggregateFunctionInvocation; +import io.substrait.expression.Expression; +import io.substrait.expression.ExpressionCreator; +import io.substrait.expression.FieldReference; +import io.substrait.expression.ImmutableFieldReference; import io.substrait.extension.DefaultExtensionCatalog; import io.substrait.relation.Aggregate; import io.substrait.type.NamedStruct; diff --git a/core/src/test/java/io/substrait/relation/SetTest.java b/core/src/test/java/io/substrait/relation/SetTest.java index 4f27c1ecc..8c857fb3a 100644 --- a/core/src/test/java/io/substrait/relation/SetTest.java +++ b/core/src/test/java/io/substrait/relation/SetTest.java @@ -1,12 +1,15 @@ package io.substrait.relation; -import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import io.substrait.type.NamedStruct; import io.substrait.type.Type; import io.substrait.type.TypeCreator; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.junit.jupiter.api.Test; class SetTest { diff --git a/core/src/test/java/io/substrait/type/proto/GenericRoundtripTest.java b/core/src/test/java/io/substrait/type/proto/GenericRoundtripTest.java index 47f53c110..7643d7b1f 100644 --- a/core/src/test/java/io/substrait/type/proto/GenericRoundtripTest.java +++ b/core/src/test/java/io/substrait/type/proto/GenericRoundtripTest.java @@ -19,8 +19,8 @@ import java.math.BigDecimal; import java.time.Instant; import java.time.LocalDateTime; -import java.util.*; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Random; import java.util.UUID; diff --git a/isthmus-cli/src/main/java/io/substrait/isthmus/cli/RegisterAtRuntime.java b/isthmus-cli/src/main/java/io/substrait/isthmus/cli/RegisterAtRuntime.java index 416574208..dd8e8ed04 100644 --- a/isthmus-cli/src/main/java/io/substrait/isthmus/cli/RegisterAtRuntime.java +++ b/isthmus-cli/src/main/java/io/substrait/isthmus/cli/RegisterAtRuntime.java @@ -7,7 +7,31 @@ import io.substrait.extension.SimpleExtension; import java.lang.annotation.Annotation; import java.util.Arrays; -import org.apache.calcite.rel.metadata.*; +import org.apache.calcite.rel.metadata.BuiltInMetadata; +import org.apache.calcite.rel.metadata.Metadata; +import org.apache.calcite.rel.metadata.MetadataHandler; +import org.apache.calcite.rel.metadata.RelMdAllPredicates; +import org.apache.calcite.rel.metadata.RelMdCollation; +import org.apache.calcite.rel.metadata.RelMdColumnOrigins; +import org.apache.calcite.rel.metadata.RelMdColumnUniqueness; +import org.apache.calcite.rel.metadata.RelMdDistinctRowCount; +import org.apache.calcite.rel.metadata.RelMdDistribution; +import org.apache.calcite.rel.metadata.RelMdExplainVisibility; +import org.apache.calcite.rel.metadata.RelMdExpressionLineage; +import org.apache.calcite.rel.metadata.RelMdLowerBoundCost; +import org.apache.calcite.rel.metadata.RelMdMaxRowCount; +import org.apache.calcite.rel.metadata.RelMdMemory; +import org.apache.calcite.rel.metadata.RelMdMinRowCount; +import org.apache.calcite.rel.metadata.RelMdNodeTypes; +import org.apache.calcite.rel.metadata.RelMdParallelism; +import org.apache.calcite.rel.metadata.RelMdPercentageOriginalRows; +import org.apache.calcite.rel.metadata.RelMdPopulationSize; +import org.apache.calcite.rel.metadata.RelMdPredicates; +import org.apache.calcite.rel.metadata.RelMdRowCount; +import org.apache.calcite.rel.metadata.RelMdSelectivity; +import org.apache.calcite.rel.metadata.RelMdSize; +import org.apache.calcite.rel.metadata.RelMdTableReferences; +import org.apache.calcite.rel.metadata.RelMdUniqueKeys; import org.apache.calcite.runtime.CalciteContextException; import org.apache.calcite.runtime.Resources; import org.apache.calcite.sql.fun.SqlStdOperatorTable; diff --git a/isthmus/src/main/java/io/substrait/isthmus/expression/FieldSelectionConverter.java b/isthmus/src/main/java/io/substrait/isthmus/expression/FieldSelectionConverter.java index 5a0ea037b..634398348 100644 --- a/isthmus/src/main/java/io/substrait/isthmus/expression/FieldSelectionConverter.java +++ b/isthmus/src/main/java/io/substrait/isthmus/expression/FieldSelectionConverter.java @@ -7,7 +7,9 @@ import io.substrait.isthmus.TypeConverter; import java.util.Optional; import java.util.function.Function; -import org.apache.calcite.rex.*; +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlKind; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/isthmus/src/main/java/io/substrait/isthmus/expression/LiteralConverter.java b/isthmus/src/main/java/io/substrait/isthmus/expression/LiteralConverter.java index 2a0e50395..965bb490b 100644 --- a/isthmus/src/main/java/io/substrait/isthmus/expression/LiteralConverter.java +++ b/isthmus/src/main/java/io/substrait/isthmus/expression/LiteralConverter.java @@ -1,9 +1,5 @@ package io.substrait.isthmus.expression; -import static io.substrait.expression.ExpressionCreator.*; -import static java.time.temporal.ChronoField.*; -import static java.util.concurrent.TimeUnit.NANOSECONDS; - import com.google.protobuf.ByteString; import io.substrait.expression.Expression; import io.substrait.expression.ExpressionCreator; @@ -11,16 +7,27 @@ import io.substrait.type.Type; import java.math.BigDecimal; import java.math.RoundingMode; -import java.time.*; +import java.time.Duration; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rex.RexLiteral; -import org.apache.calcite.util.*; +import org.apache.calcite.util.DateString; +import org.apache.calcite.util.NlsString; +import org.apache.calcite.util.TimeString; +import org.apache.calcite.util.TimestampString; public class LiteralConverter { // TODO: Handle conversion of user-defined type literals @@ -34,13 +41,13 @@ public LiteralConverter(TypeConverter typeConverter) { static final DateTimeFormatter CALCITE_LOCAL_DATE_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE; static final DateTimeFormatter CALCITE_LOCAL_TIME_FORMATTER = new DateTimeFormatterBuilder() - .appendValue(HOUR_OF_DAY, 2) + .appendValue(ChronoField.HOUR_OF_DAY, 2) .appendLiteral(':') - .appendValue(MINUTE_OF_HOUR, 2) + .appendValue(ChronoField.MINUTE_OF_HOUR, 2) .appendLiteral(':') - .appendValue(SECOND_OF_MINUTE, 2) + .appendValue(ChronoField.SECOND_OF_MINUTE, 2) .optionalStart() - .appendFraction(NANO_OF_SECOND, 0, 9, true) + .appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true) .toFormatter(); private static final DateTimeFormatter CALCITE_LOCAL_DATETIME_FORMATTER = new DateTimeFormatterBuilder() @@ -85,67 +92,70 @@ public Expression.Literal convert(RexLiteral literal) { final boolean n = type.nullable(); if (literal.isNull()) { - return typedNull(type); + return ExpressionCreator.typedNull(type); } switch (literal.getType().getSqlTypeName()) { case TINYINT: - return i8(n, i(literal).intValue()); + return ExpressionCreator.i8(n, i(literal).intValue()); case SMALLINT: - return i16(n, i(literal).intValue()); + return ExpressionCreator.i16(n, i(literal).intValue()); case INTEGER: - return i32(n, i(literal).intValue()); + return ExpressionCreator.i32(n, i(literal).intValue()); case BIGINT: - return i64(n, i(literal).longValue()); + return ExpressionCreator.i64(n, i(literal).longValue()); case BOOLEAN: - return bool(n, literal.getValueAs(Boolean.class)); + return ExpressionCreator.bool(n, literal.getValueAs(Boolean.class)); case CHAR: { var val = literal.getValue(); if (val instanceof NlsString) { var nls = (NlsString) val; - return fixedChar(n, nls.getValue()); + return ExpressionCreator.fixedChar(n, nls.getValue()); } throw new UnsupportedOperationException("Unable to handle char type: " + val); } case FLOAT: case DOUBLE: - return fp64(n, literal.getValueAs(Double.class)); + return ExpressionCreator.fp64(n, literal.getValueAs(Double.class)); case REAL: - return fp32(n, literal.getValueAs(Float.class)); + return ExpressionCreator.fp32(n, literal.getValueAs(Float.class)); case DECIMAL: { BigDecimal bd = bd(literal); - return decimal(n, bd, literal.getType().getPrecision(), literal.getType().getScale()); + return ExpressionCreator.decimal( + n, bd, literal.getType().getPrecision(), literal.getType().getScale()); } case VARCHAR: { if (literal.getType().getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED) { - return string(n, s(literal)); + return ExpressionCreator.string(n, s(literal)); } - return varChar(n, s(literal), literal.getType().getPrecision()); + return ExpressionCreator.varChar(n, s(literal), literal.getType().getPrecision()); } case BINARY: - return fixedBinary( + return ExpressionCreator.fixedBinary( n, ByteString.copyFrom( padRightIfNeeded( literal.getValueAs(org.apache.calcite.avatica.util.ByteString.class), literal.getType().getPrecision()))); case VARBINARY: - return binary(n, ByteString.copyFrom(literal.getValueAs(byte[].class))); + return ExpressionCreator.binary(n, ByteString.copyFrom(literal.getValueAs(byte[].class))); case SYMBOL: { Object value = literal.getValue(); // case TimeUnitRange tur -> string(n, tur.name()); if (value instanceof NlsString) { - return string(n, ((NlsString) value).getValue()); + return ExpressionCreator.string(n, ((NlsString) value).getValue()); } else if (value instanceof Enum) { Enum v = (Enum) value; Optional r = - EnumConverter.canConvert(v) ? Optional.of(string(n, v.name())) : Optional.empty(); + EnumConverter.canConvert(v) + ? Optional.of(ExpressionCreator.string(n, v.name())) + : Optional.empty(); return r.orElseThrow( () -> new UnsupportedOperationException("Unable to handle symbol: " + value)); } else { @@ -162,7 +172,7 @@ public Expression.Literal convert(RexLiteral literal) { { TimeString time = literal.getValueAs(TimeString.class); LocalTime localTime = LocalTime.parse(time.toString(), CALCITE_LOCAL_TIME_FORMATTER); - return time(n, NANOSECONDS.toMicros(localTime.toNanoOfDay())); + return ExpressionCreator.time(n, TimeUnit.NANOSECONDS.toMicros(localTime.toNanoOfDay())); } case TIMESTAMP: case TIMESTAMP_WITH_LOCAL_TIME_ZONE: @@ -170,7 +180,7 @@ public Expression.Literal convert(RexLiteral literal) { TimestampString timestamp = literal.getValueAs(TimestampString.class); LocalDateTime ldt = LocalDateTime.parse(timestamp.toString(), CALCITE_LOCAL_DATETIME_FORMATTER); - return timestamp(n, ldt); + return ExpressionCreator.timestamp(n, ldt); } case INTERVAL_YEAR: case INTERVAL_YEAR_MONTH: @@ -179,7 +189,7 @@ public Expression.Literal convert(RexLiteral literal) { long intervalLength = Objects.requireNonNull(literal.getValueAs(Long.class)); var years = intervalLength / 12; var months = intervalLength - years * 12; - return intervalYear(n, (int) years, (int) months); + return ExpressionCreator.intervalYear(n, (int) years, (int) months); } case INTERVAL_DAY: case INTERVAL_DAY_HOUR: @@ -200,19 +210,21 @@ public Expression.Literal convert(RexLiteral literal) { var seconds = interval.minusDays(days).toSeconds(); var micros = interval.toMillisPart() * 1000; - return intervalDay(n, (int) days, (int) seconds, micros, 6); + return ExpressionCreator.intervalDay(n, (int) days, (int) seconds, micros, 6); } case ROW: { List literals = (List) literal.getValue(); - return struct(n, literals.stream().map(this::convert).collect(Collectors.toList())); + return ExpressionCreator.struct( + n, literals.stream().map(this::convert).collect(Collectors.toList())); } case ARRAY: { List literals = (List) literal.getValue(); - return list(n, literals.stream().map(this::convert).collect(Collectors.toList())); + return ExpressionCreator.list( + n, literals.stream().map(this::convert).collect(Collectors.toList())); } default: diff --git a/isthmus/src/test/java/io/substrait/isthmus/CalciteCallTest.java b/isthmus/src/test/java/io/substrait/isthmus/CalciteCallTest.java index 341dda8e7..dcc2ee8e4 100644 --- a/isthmus/src/test/java/io/substrait/isthmus/CalciteCallTest.java +++ b/isthmus/src/test/java/io/substrait/isthmus/CalciteCallTest.java @@ -1,6 +1,5 @@ package io.substrait.isthmus; -import static org.apache.calcite.sql.fun.SqlStdOperatorTable.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -48,7 +47,8 @@ public void extract() { public void coerceNumericOp() { test( "add:i64_i64", - rex.makeCall(PLUS, c(20, SqlTypeName.INTEGER), c(4, SqlTypeName.BIGINT)), + rex.makeCall( + SqlStdOperatorTable.PLUS, c(20, SqlTypeName.INTEGER), c(4, SqlTypeName.BIGINT)), func -> { // check that there is a cast for the incorrect argument type. assertEquals( @@ -65,7 +65,7 @@ public void coerceNumericOp() { public void directMatchPlus() { test( "add:i64_i64", - rex.makeCall(PLUS, c(4, SqlTypeName.BIGINT), c(4, SqlTypeName.BIGINT)), + rex.makeCall(SqlStdOperatorTable.PLUS, c(4, SqlTypeName.BIGINT), c(4, SqlTypeName.BIGINT)), func -> { // ensure both literals are included directly. @@ -77,17 +77,23 @@ public void directMatchPlus() { @Test public void directMatchAnd() { - test("and:bool", rex.makeCall(AND, c(true, SqlTypeName.BOOLEAN), c(true, SqlTypeName.BOOLEAN))); + test( + "and:bool", + rex.makeCall( + SqlStdOperatorTable.AND, c(true, SqlTypeName.BOOLEAN), c(true, SqlTypeName.BOOLEAN))); } @Test public void directMatchOr() { - test("or:bool", rex.makeCall(OR, c(false, SqlTypeName.BOOLEAN), c(true, SqlTypeName.BOOLEAN))); + test( + "or:bool", + rex.makeCall( + SqlStdOperatorTable.OR, c(false, SqlTypeName.BOOLEAN), c(true, SqlTypeName.BOOLEAN))); } @Test public void not() { - test("not:bool", rex.makeCall(NOT, c(false, SqlTypeName.BOOLEAN))); + test("not:bool", rex.makeCall(SqlStdOperatorTable.NOT, c(false, SqlTypeName.BOOLEAN))); } private void test(String expectedName, RexNode call) { diff --git a/isthmus/src/test/java/io/substrait/isthmus/CalciteLiteralTest.java b/isthmus/src/test/java/io/substrait/isthmus/CalciteLiteralTest.java index ae62d9042..cb08298b2 100644 --- a/isthmus/src/test/java/io/substrait/isthmus/CalciteLiteralTest.java +++ b/isthmus/src/test/java/io/substrait/isthmus/CalciteLiteralTest.java @@ -1,13 +1,12 @@ package io.substrait.isthmus; -import static io.substrait.expression.ExpressionCreator.*; -import static io.substrait.isthmus.SqlConverterBase.EXTENSION_COLLECTION; import static io.substrait.isthmus.SqlToSubstrait.EXTENSION_COLLECTION; import static io.substrait.isthmus.SubstraitTypeSystem.YEAR_MONTH_INTERVAL; import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.common.collect.ImmutableMap; import io.substrait.expression.Expression; +import io.substrait.expression.ExpressionCreator; import io.substrait.isthmus.SubstraitRelNodeConverter.Context; import io.substrait.isthmus.expression.ExpressionRexConverter; import io.substrait.isthmus.expression.RexExpressionConverter; @@ -44,62 +43,62 @@ public class CalciteLiteralTest extends CalciteObjs { @Test void nullLiteral() { bitest( - typedNull(TypeCreator.NULLABLE.varChar(10)), + ExpressionCreator.typedNull(TypeCreator.NULLABLE.varChar(10)), rex.makeNullLiteral(tN(SqlTypeName.VARCHAR, 10))); } @Test void tI8() { - bitest(i8(false, 4), c(4, SqlTypeName.TINYINT)); + bitest(ExpressionCreator.i8(false, 4), c(4, SqlTypeName.TINYINT)); } @Test void tI16() { - bitest(i16(false, 4), c(4, SqlTypeName.SMALLINT)); + bitest(ExpressionCreator.i16(false, 4), c(4, SqlTypeName.SMALLINT)); } @Test void tI32() { - bitest(i32(false, 4), c(4, SqlTypeName.INTEGER)); + bitest(ExpressionCreator.i32(false, 4), c(4, SqlTypeName.INTEGER)); } @Test void tI64() { - bitest(i64(false, 1234L), c(1234L, SqlTypeName.BIGINT)); + bitest(ExpressionCreator.i64(false, 1234L), c(1234L, SqlTypeName.BIGINT)); } @Test void tFP32() { - bitest(fp32(false, 4.44F), c(4.44F, SqlTypeName.REAL)); + bitest(ExpressionCreator.fp32(false, 4.44F), c(4.44F, SqlTypeName.REAL)); } @Test void tFP64() { - bitest(fp64(false, 4.45F), c(4.45F, SqlTypeName.DOUBLE)); + bitest(ExpressionCreator.fp64(false, 4.45F), c(4.45F, SqlTypeName.DOUBLE)); } @Test void tFloatFP64() { - test(fp64(false, 4.45F), c(4.45F, SqlTypeName.FLOAT)); + test(ExpressionCreator.fp64(false, 4.45F), c(4.45F, SqlTypeName.FLOAT)); } @Test void tStr() { - bitest(string(false, "my test"), c("my test", SqlTypeName.VARCHAR)); + bitest(ExpressionCreator.string(false, "my test"), c("my test", SqlTypeName.VARCHAR)); } @Test void tBinary() { var val = "my test".getBytes(StandardCharsets.UTF_8); bitest( - binary(false, val), + ExpressionCreator.binary(false, val), c(new org.apache.calcite.avatica.util.ByteString(val), SqlTypeName.VARBINARY)); } @Test void tTime() { bitest( - time(false, (14L * 60 * 60 + 22 * 60 + 47) * 1000 * 1000), + ExpressionCreator.time(false, (14L * 60 * 60 + 22 * 60 + 47) * 1000 * 1000), rex.makeTimeLiteral(new TimeString(14, 22, 47), 6)); } @@ -115,7 +114,7 @@ void tTimeWithMicroSecond() { new TimeString("14:22:47.123456")); bitest( - time(false, (14L * 60 * 60 + 22 * 60 + 47) * 1000 * 1000 + 123456), + ExpressionCreator.time(false, (14L * 60 * 60 + 22 * 60 + 47) * 1000 * 1000 + 123456), rex.makeTimeLiteral(new TimeString("14:22:47.123456"), 6)); } @@ -129,13 +128,13 @@ void tTimeWithNanoSecond() { @Test void tDate() { bitest( - date(false, (int) LocalDate.of(2002, 2, 14).toEpochDay()), + ExpressionCreator.date(false, (int) LocalDate.of(2002, 2, 14).toEpochDay()), rex.makeDateLiteral(new DateString(2002, 2, 14))); } @Test void tTimestamp() { - var ts = timestamp(false, 2002, 2, 14, 16, 20, 47, 123); + var ts = ExpressionCreator.timestamp(false, 2002, 2, 14, 16, 20, 47, 123); var nano = (int) TimeUnit.MICROSECONDS.toNanos(123); var tsx = new TimestampString(2002, 2, 14, 16, 20, 47).withNanos(nano); bitest(ts, rex.makeTimestampLiteral(tsx, 6)); @@ -143,7 +142,7 @@ void tTimestamp() { @Test void tTimestampWithMilliMacroSeconds() { - var ts = timestamp(false, 2002, 2, 14, 16, 20, 47, 123456); + var ts = ExpressionCreator.timestamp(false, 2002, 2, 14, 16, 20, 47, 123456); var nano = (int) TimeUnit.MICROSECONDS.toNanos(123456); var tsx = new TimestampString(2002, 2, 14, 16, 20, 47).withNanos(nano); bitest(ts, rex.makeTimestampLiteral(tsx, 6)); @@ -161,7 +160,7 @@ void tTimestampTZ() { void tIntervalYearMonth() { BigDecimal bd = new BigDecimal(3 * 12 + 5); // '3-5' year to month RexLiteral intervalYearMonth = rex.makeIntervalLiteral(bd, YEAR_MONTH_INTERVAL); - var intervalYearMonthExpr = intervalYear(false, 3, 5); + var intervalYearMonthExpr = ExpressionCreator.intervalYear(false, 3, 5); bitest(intervalYearMonthExpr, intervalYearMonth); } @@ -177,7 +176,7 @@ void tIntervalYearMonthWithPrecision() { org.apache.calcite.avatica.util.TimeUnit.MONTH, -1, SqlParserPos.QUOTED_ZERO)); - var intervalYearMonthExpr = intervalYear(false, 123, 5); + var intervalYearMonthExpr = ExpressionCreator.intervalYear(false, 123, 5); // rex --> expression assertEquals(intervalYearMonthExpr, intervalYearMonth.accept(rexExpressionConverter)); @@ -212,7 +211,8 @@ void tIntervalMillisecond() { org.apache.calcite.avatica.util.TimeUnit.SECOND, 3, SqlParserPos.ZERO)); - var intervalDaySecondExpr = intervalDay(false, 3, 5 * 3600 + 7 * 60 + 9, 500_000, 6); + var intervalDaySecondExpr = + ExpressionCreator.intervalDay(false, 3, 5 * 3600 + 7 * 60 + 9, 500_000, 6); bitest(intervalDaySecondExpr, intervalDaySecond); } @@ -225,7 +225,7 @@ void tIntervalDay() { bd, new SqlIntervalQualifier( org.apache.calcite.avatica.util.TimeUnit.DAY, -1, null, -1, SqlParserPos.ZERO)); - var intervalDayExpr = intervalDay(false, 5, 0, 0, 6); + var intervalDayExpr = ExpressionCreator.intervalDay(false, 5, 0, 0, 6); // rex --> expression var convertedExpr = intervalDayLiteral.accept(rexExpressionConverter); @@ -252,7 +252,7 @@ void tIntervalYear() { null, -1, SqlParserPos.QUOTED_ZERO)); - var intervalYearExpr = intervalYear(false, 123, 0); + var intervalYearExpr = ExpressionCreator.intervalYear(false, 123, 0); // rex --> expression assertEquals(intervalYearExpr, intervalYear.accept(rexExpressionConverter)); @@ -278,7 +278,7 @@ void tIntervalMonth() { null, -1, SqlParserPos.QUOTED_ZERO)); - var intervalMonthExpr = intervalYear(false, 123 / 12, 123 % 12); + var intervalMonthExpr = ExpressionCreator.intervalYear(false, 123 / 12, 123 % 12); // rex --> expression assertEquals(intervalMonthExpr, intervalMonth.accept(rexExpressionConverter)); @@ -294,12 +294,12 @@ void tIntervalMonth() { @Test void tFixedChar() { - bitest(fixedChar(false, "hello "), c("hello ", SqlTypeName.CHAR)); + bitest(ExpressionCreator.fixedChar(false, "hello "), c("hello ", SqlTypeName.CHAR)); } @Test void tVarChar() { - bitest(varChar(false, "hello ", 10), c("hello ", SqlTypeName.VARCHAR, 10)); + bitest(ExpressionCreator.varChar(false, "hello ", 10), c("hello ", SqlTypeName.VARCHAR, 10)); } @Test @@ -311,7 +311,7 @@ void tDecimalLiteral() { new BigDecimal("123.450000"), new BigDecimal("-123.450000")); for (BigDecimal bd : decimalList) { - bitest(decimal(false, bd, 32, 6), c(bd, SqlTypeName.DECIMAL, 32, 6)); + bitest(ExpressionCreator.decimal(false, bd, 32, 6), c(bd, SqlTypeName.DECIMAL, 32, 6)); } } @@ -323,7 +323,7 @@ void tDecimalLiteral2() { new BigDecimal("99.123456789123456789123456789123456789") // scale = 36, precision = 38 ); for (BigDecimal bd : decimalList) { - bitest(decimal(false, bd, 38, 36), c(bd, SqlTypeName.DECIMAL, 38, 36)); + bitest(ExpressionCreator.decimal(false, bd, 38, 36), c(bd, SqlTypeName.DECIMAL, 38, 36)); } } @@ -344,20 +344,24 @@ void tDecimalUtil() { void tMap() { var ss = ImmutableMap.of( - string(false, "foo"), i32(false, 4), string(false, "bar"), i32(false, -1)); + ExpressionCreator.string(false, "foo"), + ExpressionCreator.i32(false, 4), + ExpressionCreator.string(false, "bar"), + ExpressionCreator.i32(false, -1)); var calcite = rex.makeLiteral( ImmutableMap.of("foo", 4, "bar", -1), type.createMapType(t(SqlTypeName.VARCHAR), t(SqlTypeName.INTEGER)), true, false); - bitest(map(false, ss), calcite); + bitest(ExpressionCreator.map(false, ss), calcite); } @Test void tList() { bitest( - list(false, i32(false, 4), i32(false, -1)), + ExpressionCreator.list( + false, ExpressionCreator.i32(false, 4), ExpressionCreator.i32(false, -1)), rex.makeLiteral( Arrays.asList(4, -1), type.createArrayType(t(SqlTypeName.INTEGER), -1), false, false)); } @@ -365,7 +369,8 @@ void tList() { @Test void tStruct() { test( - struct(false, i32(false, 4), i32(false, -1)), + ExpressionCreator.struct( + false, ExpressionCreator.i32(false, 4), ExpressionCreator.i32(false, -1)), rex.makeLiteral( Arrays.asList(4, -1), type.createStructType( @@ -379,7 +384,7 @@ void tStruct() { void tFixedBinary() { var val = "my test".getBytes(StandardCharsets.UTF_8); bitest( - fixedBinary(false, val), + ExpressionCreator.fixedBinary(false, val), c(new org.apache.calcite.avatica.util.ByteString(val), SqlTypeName.BINARY)); } diff --git a/isthmus/src/test/java/io/substrait/isthmus/expression/AggregateFunctionConverterTest.java b/isthmus/src/test/java/io/substrait/isthmus/expression/AggregateFunctionConverterTest.java index f72472d11..6cdff89fe 100644 --- a/isthmus/src/test/java/io/substrait/isthmus/expression/AggregateFunctionConverterTest.java +++ b/isthmus/src/test/java/io/substrait/isthmus/expression/AggregateFunctionConverterTest.java @@ -1,6 +1,7 @@ package io.substrait.isthmus.expression; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import io.substrait.isthmus.AggregateFunctions; import io.substrait.isthmus.PlanTestBase; From 52e9e559f84cc9453ec56b913f78cce30a276130 Mon Sep 17 00:00:00 2001 From: Niels Pardon Date: Thu, 17 Jul 2025 15:59:25 +0200 Subject: [PATCH 2/2] chore: update spotless and enable removeWildcardImports Signed-off-by: Niels Pardon --- build.gradle.kts | 3 ++- core/build.gradle.kts | 4 ++-- .../expression/proto/ProtoExpressionConverter.java | 2 +- .../io/substrait/type/proto/TypeExpressionProtoVisitor.java | 6 +++--- examples/substrait-spark/build.gradle.kts | 2 +- isthmus-cli/build.gradle.kts | 2 +- isthmus/build.gradle.kts | 2 +- spark/.scalafmt.conf | 2 +- spark/build.gradle.kts | 2 +- 9 files changed, 13 insertions(+), 12 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ec1b80873..005273a53 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 } @@ -55,6 +55,7 @@ allprojects { googleJavaFormat() removeUnusedImports() trimTrailingWhitespace() + removeWildcardImports() } } } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 150bf8b2b..5ba6cd33b 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -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") } @@ -261,7 +261,7 @@ project.configure { generatedSourceDirs.addAll( listOf( file("build/generated/sources/antlr/main"), - file("build/generated/source/proto/main/java") + file("build/generated/source/proto/main/java"), ) ) } diff --git a/core/src/main/java/io/substrait/expression/proto/ProtoExpressionConverter.java b/core/src/main/java/io/substrait/expression/proto/ProtoExpressionConverter.java index 0cf986513..db47cb278 100644 --- a/core/src/main/java/io/substrait/expression/proto/ProtoExpressionConverter.java +++ b/core/src/main/java/io/substrait/expression/proto/ProtoExpressionConverter.java @@ -258,7 +258,7 @@ public Type visit(Type.Struct type) throws RuntimeException { } } - // TODO enum. + // TODO enum. case ENUM: throw new UnsupportedOperationException("Unsupported type: " + expr.getRexTypeCase()); default: diff --git a/core/src/main/java/io/substrait/type/proto/TypeExpressionProtoVisitor.java b/core/src/main/java/io/substrait/type/proto/TypeExpressionProtoVisitor.java index 247f6f959..7e0575b7e 100644 --- a/core/src/main/java/io/substrait/type/proto/TypeExpressionProtoVisitor.java +++ b/core/src/main/java/io/substrait/type/proto/TypeExpressionProtoVisitor.java @@ -52,11 +52,11 @@ private DerivationExpression.BinaryOp.BinaryOpType getDerivationOpType( return DerivationExpression.BinaryOp.BinaryOpType.BINARY_OP_TYPE_MAX; case LT: return DerivationExpression.BinaryOp.BinaryOpType.BINARY_OP_TYPE_LESS_THAN; - // case LTE -> DerivationExpression.BinaryOp.BinaryOpType.BINARY_OP_TYPE_LESS_THAN; + // case LTE -> DerivationExpression.BinaryOp.BinaryOpType.BINARY_OP_TYPE_LESS_THAN; case GT: return DerivationExpression.BinaryOp.BinaryOpType.BINARY_OP_TYPE_GREATER_THAN; - // case GTE -> DerivationExpression.BinaryOp.BinaryOpType.BINARY_OP_TYPE_MINUS; - // case NOT_EQ -> DerivationExpression.BinaryOp.BinaryOpType.BINARY_OP_TYPE_EQ; + // case GTE -> DerivationExpression.BinaryOp.BinaryOpType.BINARY_OP_TYPE_MINUS; + // case NOT_EQ -> DerivationExpression.BinaryOp.BinaryOpType.BINARY_OP_TYPE_EQ; case EQ: return DerivationExpression.BinaryOp.BinaryOpType.BINARY_OP_TYPE_EQUALS; case COVERS: diff --git a/examples/substrait-spark/build.gradle.kts b/examples/substrait-spark/build.gradle.kts index 212f2b11c..7049a8928 100644 --- a/examples/substrait-spark/build.gradle.kts +++ b/examples/substrait-spark/build.gradle.kts @@ -1,7 +1,7 @@ plugins { // Apply the application plugin to add support for building a CLI application in Java. id("java") - id("com.diffplug.spotless") version "6.19.0" + id("com.diffplug.spotless") version "7.1.0" } repositories { diff --git a/isthmus-cli/build.gradle.kts b/isthmus-cli/build.gradle.kts index 693a01f5b..2d7674019 100644 --- a/isthmus-cli/build.gradle.kts +++ b/isthmus-cli/build.gradle.kts @@ -2,7 +2,7 @@ plugins { id("java") id("idea") id("com.palantir.graal") version "0.10.0" - id("com.diffplug.spotless") version "6.19.0" + id("com.diffplug.spotless") version "7.1.0" } java { diff --git a/isthmus/build.gradle.kts b/isthmus/build.gradle.kts index 64f9891a4..6ebfd8459 100644 --- a/isthmus/build.gradle.kts +++ b/isthmus/build.gradle.kts @@ -5,7 +5,7 @@ plugins { signing id("java-library") id("idea") - 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("com.google.protobuf") version "0.9.4" id("org.jreleaser") diff --git a/spark/.scalafmt.conf b/spark/.scalafmt.conf index fc6b14ef6..3606e3439 100644 --- a/spark/.scalafmt.conf +++ b/spark/.scalafmt.conf @@ -1,7 +1,7 @@ runner.dialect = scala212 # Version is required to make sure IntelliJ picks the right version -version = 3.7.3 +version = 3.8.1 preset = default # Max column diff --git a/spark/build.gradle.kts b/spark/build.gradle.kts index 6af7a3397..21ace5de3 100644 --- a/spark/build.gradle.kts +++ b/spark/build.gradle.kts @@ -4,7 +4,7 @@ plugins { id("java") id("scala") id("idea") - id("com.diffplug.spotless") version "6.19.0" + id("com.diffplug.spotless") version "7.1.0" id("org.jreleaser") }