Skip to content

Commit ae9b591

Browse files
committed
Applied rewrite java 17 migration
$ mvn clean -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.migrate.UpgradeToJava17 -Drewrite.exportDatatables=true Signed-off-by: Marvin Froeder <marvin@datasqrl.com>
1 parent abfbc4c commit ae9b591

File tree

19 files changed

+60
-75
lines changed

19 files changed

+60
-75
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
uses: actions/setup-java@v3
3333
with:
3434
distribution: 'temurin'
35-
java-version: '11'
35+
java-version: '17'
3636

3737
- name: Import GPG Key
3838
if: github.event_name != 'pull_request'

.github/workflows/uber-jar.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
uses: actions/setup-java@v3
3737
with:
3838
distribution: 'temurin'
39-
java-version: '11'
39+
java-version: '17'
4040

4141
- name: Generate settings.xml
4242
run: |

connectors/postgresql-connector/src/main/java/com/datasqrl/connector/postgresql/jdbc/SqrlBaseJdbcRowConverter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public JdbcDeserializationConverter createInternalConverter(LogicalType type) {
6666

6767
if (root == LogicalTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
6868
return val ->
69-
val instanceof LocalDateTime
70-
? TimestampData.fromLocalDateTime((LocalDateTime) val)
69+
val instanceof LocalDateTime ldt
70+
? TimestampData.fromLocalDateTime(ldt)
7171
: TimestampData.fromTimestamp((Timestamp) val);
7272
} else if (root == LogicalTypeRoot.ARRAY) {
7373
ArrayType arrayType = (ArrayType) type;
@@ -101,10 +101,10 @@ private void createSqlArrayObject(
101101
// Scalar arrays of any dimension are one array call
102102
if (isScalarArray(type)) {
103103
Object[] boxed;
104-
if (data instanceof GenericArrayData) {
105-
boxed = ((GenericArrayData) data).toObjectArray();
106-
} else if (data instanceof BinaryArrayData) {
107-
boxed = ((BinaryArrayData) data).toObjectArray(getBaseFlinkArrayType(type));
104+
if (data instanceof GenericArrayData arrayData) {
105+
boxed = arrayData.toObjectArray();
106+
} else if (data instanceof BinaryArrayData arrayData) {
107+
boxed = arrayData.toObjectArray(getBaseFlinkArrayType(type));
108108
} else {
109109
throw new RuntimeException("Unsupported ArrayData type: " + data.getClass());
110110
}

connectors/postgresql-connector/src/main/java/com/datasqrl/connector/postgresql/jdbc/SqrlJdbcDynamicTableFactory.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -229,38 +229,36 @@ private void validateConfigOptions(ReadableConfig config, ClassLoader classLoade
229229
long upperBound = config.get(SCAN_PARTITION_UPPER_BOUND);
230230
if (lowerBound > upperBound) {
231231
throw new IllegalArgumentException(
232-
String.format(
233-
"'%s'='%s' must not be larger than '%s'='%s'.",
234-
SCAN_PARTITION_LOWER_BOUND.key(),
235-
lowerBound,
236-
SCAN_PARTITION_UPPER_BOUND.key(),
237-
upperBound));
232+
"'%s'='%s' must not be larger than '%s'='%s'."
233+
.formatted(
234+
SCAN_PARTITION_LOWER_BOUND.key(),
235+
lowerBound,
236+
SCAN_PARTITION_UPPER_BOUND.key(),
237+
upperBound));
238238
}
239239
}
240240

241241
checkAllOrNone(config, new ConfigOption[] {LOOKUP_CACHE_MAX_ROWS, LOOKUP_CACHE_TTL});
242242

243243
if (config.get(LOOKUP_MAX_RETRIES) < 0) {
244244
throw new IllegalArgumentException(
245-
String.format(
246-
"The value of '%s' option shouldn't be negative, but is %s.",
247-
LOOKUP_MAX_RETRIES.key(), config.get(LOOKUP_MAX_RETRIES)));
245+
"The value of '%s' option shouldn't be negative, but is %s."
246+
.formatted(LOOKUP_MAX_RETRIES.key(), config.get(LOOKUP_MAX_RETRIES)));
248247
}
249248

250249
if (config.get(SINK_MAX_RETRIES) < 0) {
251250
throw new IllegalArgumentException(
252-
String.format(
253-
"The value of '%s' option shouldn't be negative, but is %s.",
254-
SINK_MAX_RETRIES.key(), config.get(SINK_MAX_RETRIES)));
251+
"The value of '%s' option shouldn't be negative, but is %s."
252+
.formatted(SINK_MAX_RETRIES.key(), config.get(SINK_MAX_RETRIES)));
255253
}
256254

257255
if (config.get(MAX_RETRY_TIMEOUT).getSeconds() <= 0) {
258256
throw new IllegalArgumentException(
259-
String.format(
260-
"The value of '%s' option must be in second granularity and shouldn't be smaller than 1 second, but is %s.",
261-
MAX_RETRY_TIMEOUT.key(),
262-
config.get(
263-
ConfigOptions.key(MAX_RETRY_TIMEOUT.key()).stringType().noDefaultValue())));
257+
"The value of '%s' option must be in second granularity and shouldn't be smaller than 1 second, but is %s."
258+
.formatted(
259+
MAX_RETRY_TIMEOUT.key(),
260+
config.get(
261+
ConfigOptions.key(MAX_RETRY_TIMEOUT.key()).stringType().noDefaultValue())));
264262
}
265263
}
266264

connectors/postgresql-connector/src/main/java/com/datasqrl/connector/postgresql/jdbc/SqrlPostgresDialect.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.datasqrl.connector.postgresql.jdbc;
1717

18+
import java.io.Serial;
1819
import java.util.Arrays;
1920
import java.util.EnumSet;
2021
import java.util.List;
@@ -36,7 +37,7 @@
3637
*/
3738
public class SqrlPostgresDialect extends AbstractDialect {
3839

39-
private static final long serialVersionUID = 1L;
40+
@Serial private static final long serialVersionUID = 1L;
4041

4142
// Define MAX/MIN precision of TIMESTAMP type according to PostgreSQL docs:
4243
// https://www.postgresql.org/docs/12/datatype-datetime.html
@@ -93,8 +94,8 @@ public void validate(RowType rowType) throws ValidationException {
9394

9495
if (!unsupportedTypes.isEmpty()) {
9596
throw new ValidationException(
96-
String.format(
97-
"The %s dialect doesn't support type: %s.", this.dialectName(), unsupportedTypes));
97+
"The %s dialect doesn't support type: %s."
98+
.formatted(this.dialectName(), unsupportedTypes));
9899
}
99100

100101
super.validate(rowType);

connectors/postgresql-connector/src/main/java/com/datasqrl/connector/postgresql/jdbc/SqrlPostgresRowConverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.datasqrl.connector.postgresql.jdbc;
1717

1818
import com.datasqrl.connector.postgresql.type.JdbcTypeSerializer;
19+
import java.io.Serial;
1920
import java.lang.reflect.Type;
2021
import java.util.Map;
2122
import java.util.ServiceLoader;
@@ -35,7 +36,7 @@
3536
*/
3637
public class SqrlPostgresRowConverter extends SqrlBaseJdbcRowConverter {
3738

38-
private static final long serialVersionUID = 1L;
39+
@Serial private static final long serialVersionUID = 1L;
3940

4041
public static final Map<
4142
Type, JdbcTypeSerializer<JdbcDeserializationConverter, JdbcSerializationConverter>>
@@ -104,8 +105,7 @@ public JdbcDeserializationConverter createArrayConverter(ArrayType arrayType) {
104105
// sqrl: check if scalar array
105106

106107
Object[] in;
107-
if (val instanceof PgArray) {
108-
PgArray pgArray = (PgArray) val;
108+
if (val instanceof PgArray pgArray) {
109109
in = (Object[]) pgArray.getArray();
110110
} else {
111111
in = (Object[]) val;

connectors/postgresql-connector/src/main/java/com/datasqrl/connector/postgresql/type/FlinkArrayTypeUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
public class FlinkArrayTypeUtil {
2222

2323
public static LogicalType getBaseFlinkArrayType(LogicalType type) {
24-
if (type instanceof ArrayType) {
25-
return getBaseFlinkArrayType(((ArrayType) type).getElementType());
24+
if (type instanceof ArrayType arrayType) {
25+
return getBaseFlinkArrayType(arrayType.getElementType());
2626
}
2727
return type;
2828
}
2929

3030
public static boolean isScalarArray(LogicalType type) {
31-
if (type instanceof ArrayType) {
32-
LogicalType elementType = ((ArrayType) type).getElementType();
31+
if (type instanceof ArrayType arrayType) {
32+
LogicalType elementType = arrayType.getElementType();
3333
return isScalar(elementType) || isScalarArray(elementType);
3434
}
3535
return false;

flink-sql-runner/pom.xml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -476,16 +476,7 @@
476476
<flink.version>1.19.2</flink.version>
477477
<jdbc.version>3.2.0-1.19</jdbc.version>
478478
<kafka.version>3.2.0-1.19</kafka.version>
479-
<flink-base-image>1.19.2-scala_2.12-java11</flink-base-image>
480-
</properties>
481-
</profile>
482-
<profile>
483-
<id>flink-1.18</id>
484-
<properties>
485-
<flink.version>1.18.1</flink.version>
486-
<jdbc.version>3.2.0-1.18</jdbc.version>
487-
<kafka.version>3.2.0-1.18</kafka.version>
488-
<flink-base-image>1.18.1-scala_2.12-java11</flink-base-image>
479+
<flink-base-image>1.19.2-scala_2.12-java17</flink-base-image>
489480
</properties>
490481
</profile>
491482

flink-sql-runner/src/main/java/com/datasqrl/EnvironmentVariablesUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static String replaceWithEnv(String command, Map<String, String> envVaria
4343
String key = matcher.group(1);
4444
String envValue = envVariables.get(key);
4545
if (envValue == null) {
46-
throw new IllegalStateException(String.format("Missing environment variable: %s", key));
46+
throw new IllegalStateException("Missing environment variable: %s".formatted(key));
4747
}
4848
matcher.appendReplacement(result, Matcher.quoteReplacement(envValue));
4949
}

flink-sql-runner/src/main/java/com/datasqrl/FlinkMain.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ public int run() throws Exception {
111111
EnvironmentVariablesUtils.validateEnvironmentVariables(script);
112112
if (!missingEnvironmentVariables.isEmpty()) {
113113
throw new IllegalStateException(
114-
String.format(
115-
"Could not find the following environment variables: %s",
116-
missingEnvironmentVariables));
114+
"Could not find the following environment variables: %s"
115+
.formatted(missingEnvironmentVariables));
117116
}
118117

119118
tableResult = sqlExecutor.executeScript(script);
@@ -125,9 +124,8 @@ public int run() throws Exception {
125124
EnvironmentVariablesUtils.validateEnvironmentVariables(planJson);
126125
if (!missingEnvironmentVariables.isEmpty()) {
127126
throw new IllegalStateException(
128-
String.format(
129-
"Could not find the following environment variables: %s",
130-
missingEnvironmentVariables));
127+
"Could not find the following environment variables: %s"
128+
.formatted(missingEnvironmentVariables));
131129
}
132130

133131
planJson = replaceScriptWithEnv(planJson);

flink-sql-runner/src/main/java/com/datasqrl/SqlExecutor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ public void setupSystemFunctions() {
6666
standardLibraryFunctions.forEach(
6767
function -> {
6868
String sql =
69-
String.format(
70-
"CREATE TEMPORARY FUNCTION IF NOT EXISTS `%s` AS '%s' LANGUAGE JAVA;",
71-
getFunctionNameFromClass(function.getClass()), function.getClass().getName());
69+
"CREATE TEMPORARY FUNCTION IF NOT EXISTS `%s` AS '%s' LANGUAGE JAVA;"
70+
.formatted(
71+
getFunctionNameFromClass(function.getClass()),
72+
function.getClass().getName());
7273

7374
System.out.println(sql);
7475

flink-sql-runner/src/test/java/com/datasqrl/CommandLineUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public static String execute(Path workDir, String command) throws ExecuteExcepti
6565
} catch (IOException e) {
6666
var result = new String(output.toByteArray());
6767
log.error("Error while executing command:\n{}\noutput:\n{}", command, result);
68-
if (e instanceof ExecuteException) {
69-
ExecuteException ee = (ExecuteException) e;
68+
if (e instanceof ExecuteException ee) {
7069
throw new ExecuteException(result, ee.getExitValue(), ee);
7170
}
7271
throw new RuntimeException(e);

formats/flexible-json-format/src/main/java/com/datasqrl/flink/format/json/SqrlJsonRowDataSerializationSchema.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* limitations under the License.
3232
*/
3333

34+
import java.io.Serial;
3435
import java.util.Objects;
3536
import org.apache.flink.annotation.Internal;
3637
import org.apache.flink.api.common.serialization.SerializationSchema;
@@ -59,7 +60,7 @@
5960
*/
6061
@Internal
6162
public class SqrlJsonRowDataSerializationSchema implements SerializationSchema<RowData> {
62-
private static final long serialVersionUID = 1L;
63+
@Serial private static final long serialVersionUID = 1L;
6364

6465
/** RowType to generate the runtime converter. */
6566
private final RowType rowType;
@@ -118,7 +119,7 @@ public byte[] serialize(RowData row) {
118119
runtimeConverter.convert(mapper, node, row);
119120
return mapper.writeValueAsBytes(node);
120121
} catch (Throwable t) {
121-
throw new RuntimeException(String.format("Could not serialize row '%s'.", row), t);
122+
throw new RuntimeException("Could not serialize row '%s'.".formatted(row), t);
122123
}
123124
}
124125

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@
9898
<lombok.version>1.18.38</lombok.version>
9999

100100
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
101-
<maven.compiler.source>11</maven.compiler.source>
102-
<maven.compiler.target>11</maven.compiler.target>
101+
<maven.compiler.source>17</maven.compiler.source>
102+
<maven.compiler.target>17</maven.compiler.target>
103103

104104
<!-- Example: skip install hooks, etc. -->
105105
<gcf.skipInstallHooks>true</gcf.skipInstallHooks>

types/json-type/src/main/java/com/datasqrl/types/json/functions/JsonArray.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public FlinkJsonType eval(Object... objects) {
4040
ArrayNode arrayNode = mapper.createArrayNode();
4141

4242
for (Object value : objects) {
43-
if (value instanceof FlinkJsonType) {
44-
FlinkJsonType type = (FlinkJsonType) value;
43+
if (value instanceof FlinkJsonType type) {
4544
arrayNode.add(type.json);
4645
} else {
4746
arrayNode.addPOJO(value);

types/json-type/src/main/java/com/datasqrl/types/json/functions/JsonArrayAgg.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public void merge(ArrayAgg accumulator, java.lang.Iterable<ArrayAgg> iterable) {
9191
public FlinkJsonType getValue(ArrayAgg accumulator) {
9292
ArrayNode arrayNode = mapper.createArrayNode();
9393
for (Object o : accumulator.getObjects()) {
94-
if (o instanceof FlinkJsonType) {
95-
arrayNode.add(((FlinkJsonType) o).json);
94+
if (o instanceof FlinkJsonType type) {
95+
arrayNode.add(type.json);
9696
} else {
9797
arrayNode.addPOJO(o);
9898
}

types/json-type/src/main/java/com/datasqrl/types/json/functions/JsonObject.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public FlinkJsonType eval(Object... objects) {
5454
}
5555
String key = (String) objects[i];
5656
Object value = objects[i + 1];
57-
if (value instanceof FlinkJsonType) {
58-
FlinkJsonType type = (FlinkJsonType) value;
57+
if (value instanceof FlinkJsonType type) {
5958
objectNode.put(key, type.json);
6059
} else {
6160
objectNode.putPOJO(key, value);

types/json-type/src/main/java/com/datasqrl/types/json/functions/JsonObjectAgg.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public void accumulate(ObjectAgg accumulator, String key, String value) {
5151

5252
public void accumulate(
5353
ObjectAgg accumulator, String key, @DataTypeHint(inputGroup = InputGroup.ANY) Object value) {
54-
if (value instanceof FlinkJsonType) {
55-
accumulateObject(accumulator, key, ((FlinkJsonType) value).getJson());
54+
if (value instanceof FlinkJsonType type) {
55+
accumulateObject(accumulator, key, type.getJson());
5656
} else {
5757
accumulator.add(key, mapper.getNodeFactory().pojoNode(value));
5858
}

types/json-type/src/main/java/com/datasqrl/types/json/functions/ToJson.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,15 @@ public FlinkJsonType eval(@DataTypeHint(inputGroup = InputGroup.ANY) Object json
5050
if (json == null) {
5151
return null;
5252
}
53-
if (json instanceof FlinkJsonType) {
54-
return (FlinkJsonType) json;
53+
if (json instanceof FlinkJsonType type) {
54+
return type;
5555
}
5656

5757
return new FlinkJsonType(unboxFlinkToJsonNode(json));
5858
}
5959

6060
JsonNode unboxFlinkToJsonNode(Object json) {
61-
if (json instanceof Row) {
62-
Row row = (Row) json;
61+
if (json instanceof Row row) {
6362
ObjectNode objectNode = mapper.createObjectNode();
6463
String[] fieldNames =
6564
row.getFieldNames(true).toArray(new String[0]); // Get field names in an array
@@ -68,8 +67,7 @@ JsonNode unboxFlinkToJsonNode(Object json) {
6867
objectNode.set(fieldName, unboxFlinkToJsonNode(field)); // Recursively unbox each field
6968
}
7069
return objectNode;
71-
} else if (json instanceof Row[]) {
72-
Row[] rows = (Row[]) json;
70+
} else if (json instanceof Row[] rows) {
7371
ArrayNode arrayNode = mapper.createArrayNode();
7472
for (Row row : rows) {
7573
if (row == null) {

0 commit comments

Comments
 (0)