From 895afe6dd87127e78db3b69d7fa37ff2bd7b8349 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:24:39 +0530 Subject: [PATCH 01/28] Use SqlRuntimeCast for CAST in predicates Replace the previous ad-hoc CAST handling in FilterPredicateImpl with a call to SqlRuntimeCast.castValue(input.get(0), returnType). This removes the TODO and the previous fallback logic that relied on widenToDouble/ensureComparable, delegating runtime casting to the centralized SqlRuntimeCast implementation for more accurate casting behavior. --- .../sql/calcite/converter/functions/FilterPredicateImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/FilterPredicateImpl.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/FilterPredicateImpl.java index 17409cb3e..1b0acb209 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/FilterPredicateImpl.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/FilterPredicateImpl.java @@ -56,8 +56,7 @@ public SerializableFunction, Object> deriveOperation(final SqlKind case OR -> input.stream().anyMatch(obj -> Boolean.class.cast(obj).booleanValue()); case MINUS -> widenToDouble.apply(input.get(0)) - widenToDouble.apply(input.get(1)); case PLUS -> widenToDouble.apply(input.get(0)) + widenToDouble.apply(input.get(1)); - // TODO: may need better support for CASTing in the future. See sqlCast() in this file. - case CAST -> input.get(0) instanceof Number ? widenToDouble.apply(input.get(0)) : ensureComparable.apply(input.get(0)); + case CAST -> SqlRuntimeCast.castValue(input.get(0), returnType); case SEARCH -> { if (input.get(0) instanceof final ImmutableRangeSet range) { assert input.get(1) instanceof Comparable From 769cc6d935d28db11931d7c50b08b15b8e13f359 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:24:53 +0530 Subject: [PATCH 02/28] Remove unused sqlCast method Remove the private sqlCast(Object, SqlTypeName) stub from FilterPredicateImpl which threw UnsupportedOperationException and was not used. Cleans up dead code in the SQL conversion functions. --- .../converter/functions/FilterPredicateImpl.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/FilterPredicateImpl.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/FilterPredicateImpl.java index 1b0acb209..745a3453a 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/FilterPredicateImpl.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/FilterPredicateImpl.java @@ -83,16 +83,6 @@ public SerializableFunction, Object> deriveOperation(final SqlKind }; } - /** - * Java implementation of SQL cast. - * @param input input field - * @param type the new return type of the field - * @return Java-type equivalent to {@link SqlTypeName} counterpart. - */ - private static Object sqlCast(Object input, SqlTypeName type){ - throw new UnsupportedOperationException("sqlCasting is not yet implemented."); - } - /** * Java equivalent of SQL like clauses * From 7bf7e088c153c9ae344312387a2832b1c8c7101f Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:25:33 +0530 Subject: [PATCH 03/28] Add SqlRuntimeCast.java with license header Add a new placeholder source file SqlRuntimeCast.java under wayang-api-sql's calcite converter functions package. The file currently contains only the Apache ASF v2.0 license header; implementation will be added in a follow-up change. --- .../converter/functions/SqlRuntimeCast.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java new file mode 100644 index 000000000..e5cdfe96e --- /dev/null +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + From 9baa6e0efd0b0436e43e50e6873c81dcc8316aa4 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:25:52 +0530 Subject: [PATCH 04/28] Add package and imports to SqlRuntimeCast Add package declaration and necessary imports to SqlRuntimeCast.java (BigDecimal, Calendar, Date, Calcite SqlFunctions/SqlTypeName, DateString, NlsString). Prepares the file for implementing runtime cast logic and resolves missing references for date/number/string handling. --- .../calcite/converter/functions/SqlRuntimeCast.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index e5cdfe96e..dc17dad05 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -16,3 +16,14 @@ * limitations under the License. */ +package org.apache.wayang.api.sql.calcite.converter.functions; + +import java.math.BigDecimal; +import java.util.Calendar; +import java.util.Date; + +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.calcite.util.DateString; +import org.apache.calcite.util.NlsString; + From 7bdd636397a72cadd3a2dbae87d257d3830f8f93 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:26:08 +0530 Subject: [PATCH 05/28] Add SqlRuntimeCast for Java filter CASTs Introduce SqlRuntimeCast utility used for runtime SQL CAST evaluation in Wayang Java filters. Adds a private constructor and a castValue(Object, SqlTypeName) method that unwraps inputs, returns null for SQL NULL, and delegates conversions to SqlFunctions for BOOLEAN, numeric types (TINYINT, SMALLINT, INTEGER, BIGINT, DECIMAL), FLOAT/REAL, DOUBLE, and CHAR/VARCHAR. Unsupported target types throw UnsupportedOperationException. --- .../converter/functions/SqlRuntimeCast.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index dc17dad05..4285f317f 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -27,3 +27,36 @@ import org.apache.calcite.util.DateString; import org.apache.calcite.util.NlsString; +/** + * Runtime SQL {@code CAST} for Wayang Java filter evaluation, delegating to + * {@link SqlFunctions} where possible. + */ +public final class SqlRuntimeCast { + + private SqlRuntimeCast() {} + + /** + * @param input evaluated operand (SQL NULL is {@code null}) + * @param target destination SQL type name of the cast (from the RexCall result type) + * @return value suitable for comparisons and filter logic + */ + public static Object castValue(final Object input, final SqlTypeName target) { + if (input == null) { + return null; + } + final Object v = unwrapForCast(input); + return switch (target) { + case BOOLEAN -> SqlFunctions.toBoolean(v); + case TINYINT -> SqlFunctions.toByte(v); + case SMALLINT -> SqlFunctions.toShort(v); + case INTEGER -> SqlFunctions.toInt(v); + case BIGINT -> SqlFunctions.toLong(v); + case DECIMAL -> SqlFunctions.toBigDecimal(v); + case FLOAT, REAL -> castToFloat(v); + case DOUBLE -> castToDouble(v); + case CHAR, VARCHAR -> castToString(v); + default -> throw new UnsupportedOperationException( + "CAST to " + target + " is not supported in Java filter evaluation yet."); + }; + } + From 91322ed2e0bb52c8e5fe0123ca34d986a3dc3c0d Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:26:22 +0530 Subject: [PATCH 06/28] Add unwrapForCast helper to SqlRuntimeCast Introduce a private unwrapForCast(Object) method to normalize inputs before runtime casting. It extracts the underlying String from NlsString and converts Character to String, returning the original object otherwise to ensure Cast operations handle Calcite-specific wrappers and char values correctly. --- .../sql/calcite/converter/functions/SqlRuntimeCast.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index 4285f317f..c05c1b870 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -60,3 +60,12 @@ public static Object castValue(final Object input, final SqlTypeName target) { }; } + private static Object unwrapForCast(final Object o) { + if (o instanceof final NlsString nls) { + return nls.getValue(); + } + if (o instanceof final Character c) { + return c.toString(); + } + return o; + } From b70e56b96e728e6bfdad7c50b40a6a3dee2c5379 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:26:39 +0530 Subject: [PATCH 07/28] Add castToFloat handling date types Introduce a private castToFloat(Object) in SqlRuntimeCast that converts DateString, Date, and Calendar to their millisecond instant as a float, falling back to SqlFunctions.toFloat(v). This enables correct runtime casting of date/time values to float in SQL conversions. --- .../converter/functions/SqlRuntimeCast.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index c05c1b870..25acd044e 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -69,3 +69,17 @@ private static Object unwrapForCast(final Object o) { } return o; } + + private static float castToFloat(final Object v) { + if (v instanceof final DateString ds) { + return (float) ds.getMillisSinceEpoch(); + } + if (v instanceof final Date d) { + return (float) d.getTime(); + } + if (v instanceof final Calendar cal) { + return (float) cal.getTimeInMillis(); + } + return SqlFunctions.toFloat(v); + } + From 083644764b7777732b793ddd7b0b4fc283ac9fcd Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:26:55 +0530 Subject: [PATCH 08/28] Add castToDouble handling date types Introduce castToDouble in SqlRuntimeCast to convert DateString, java.util.Date, and Calendar values to milliseconds-as-double, falling back to SqlFunctions.toDouble for other types. This ensures runtime casts of date/time inputs to DOUBLE produce consistent epoch-millisecond values. --- .../calcite/converter/functions/SqlRuntimeCast.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index 25acd044e..62cc64792 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -83,3 +83,16 @@ private static float castToFloat(final Object v) { return SqlFunctions.toFloat(v); } + private static double castToDouble(final Object v) { + if (v instanceof final DateString ds) { + return (double) ds.getMillisSinceEpoch(); + } + if (v instanceof final Date d) { + return (double) d.getTime(); + } + if (v instanceof final Calendar cal) { + return (double) cal.getTimeInMillis(); + } + return SqlFunctions.toDouble(v); + } + From 04c8134a18b0b0020425dae471c5bd0900a960b1 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:27:12 +0530 Subject: [PATCH 09/28] Add castToString to SqlRuntimeCast Introduce a private helper method castToString(Object) in SqlRuntimeCast to support runtime casting to STRING. The new method handles native String and NlsString instances and delegates Boolean, Float and Double conversions to SqlFunctions.toString. This centralizes string casting logic for the SQL calcite converter. --- .../converter/functions/SqlRuntimeCast.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index 62cc64792..28c4db6a1 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -96,3 +96,19 @@ private static double castToDouble(final Object v) { return SqlFunctions.toDouble(v); } + private static String castToString(final Object v) { + if (v instanceof final String s) { + return s; + } + if (v instanceof final NlsString nls) { + return nls.getValue(); + } + if (v instanceof final Boolean b) { + return SqlFunctions.toString(b); + } + if (v instanceof final Float f) { + return SqlFunctions.toString(f); + } + if (v instanceof final Double d) { + return SqlFunctions.toString(d); + } From 1deab5308131cb6ccb6e561202f0e5e1b1358d91 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:27:26 +0530 Subject: [PATCH 10/28] Handle more value types in SqlRuntimeCast Add runtime-to-string handling for additional value types in SqlRuntimeCast: BigDecimal (via SqlFunctions.toString), general Number, DateString, Character, and java.util.Date. This ensures values of these types are converted to their string representations during SQL runtime casting to avoid unexpected behavior or missing cases. --- .../converter/functions/SqlRuntimeCast.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index 28c4db6a1..058bdfbcd 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -112,3 +112,18 @@ private static String castToString(final Object v) { if (v instanceof final Double d) { return SqlFunctions.toString(d); } + if (v instanceof final BigDecimal bd) { + return SqlFunctions.toString(bd); + } + if (v instanceof final Number n) { + return n.toString(); + } + if (v instanceof final DateString ds) { + return ds.toString(); + } + if (v instanceof final Character c) { + return c.toString(); + } + if (v instanceof final Date d) { + return d.toString(); + } From 6f453df318ab5f68937caa7f3a65421314e43934 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:27:38 +0530 Subject: [PATCH 11/28] Handle Calendar and add fallback in SqlRuntimeCast Add handling for Calendar instances by converting cal.getTime().toString(), and add a generic fallback return String.valueOf(v). This ensures Calendar values and any other runtime objects produce a String representation, improving robustness of SqlRuntimeCast. --- .../api/sql/calcite/converter/functions/SqlRuntimeCast.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index 058bdfbcd..ce9da252e 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -127,3 +127,9 @@ private static String castToString(final Object v) { if (v instanceof final Date d) { return d.toString(); } + if (v instanceof final Calendar cal) { + return cal.getTime().toString(); + } + return String.valueOf(v); + } +} From 91c75e4139442b15bc4e5be3caa80f7b3859b66e Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:27:51 +0530 Subject: [PATCH 12/28] Add SqlRuntimeCastTest skeleton Create new test file wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java containing the Apache license header. This is a placeholder/skeleton for future unit tests related to SQL runtime cast conversion in the Calcite converter; no test code implemented yet. --- .../functions/SqlRuntimeCastTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java diff --git a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java new file mode 100644 index 000000000..e5cdfe96e --- /dev/null +++ b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + From 00f6ba35afc95c33d56cbdc6a79066164b6fbf33 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:28:05 +0530 Subject: [PATCH 13/28] Add package and imports to SqlRuntimeCastTest Add package declaration and necessary imports to SqlRuntimeCastTest.java, including JUnit assertions and Test, BigDecimal, and Calcite types (SqlTypeName, NlsString). Prepares the file for implementing unit tests for SQL runtime cast conversions. --- .../converter/functions/SqlRuntimeCastTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java index e5cdfe96e..d2ef2b3fd 100644 --- a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java +++ b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java @@ -16,3 +16,15 @@ * limitations under the License. */ +package org.apache.wayang.api.sql.calcite.converter.functions; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.math.BigDecimal; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.calcite.util.NlsString; +import org.junit.jupiter.api.Test; + From 88343089ecf63ef72c1c386b1f8770bb579b22cf Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:28:21 +0530 Subject: [PATCH 14/28] Add test for SqlRuntimeCast null handling Introduce SqlRuntimeCastTest#castNullYieldsNull which asserts that SqlRuntimeCast.castValue(null, SqlTypeName.INTEGER) returns null. This verifies that runtime casting preserves null inputs and prevents NPEs during null handling. --- .../calcite/converter/functions/SqlRuntimeCastTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java index d2ef2b3fd..b9dee6f29 100644 --- a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java +++ b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java @@ -28,3 +28,11 @@ import org.apache.calcite.util.NlsString; import org.junit.jupiter.api.Test; +class SqlRuntimeCastTest { + + @Test + void castNullYieldsNull() { + assertNull(SqlRuntimeCast.castValue(null, SqlTypeName.INTEGER)); + } + +} From 98dd8562faa03a4c0363cf9b220b5b27fabf680c Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:28:34 +0530 Subject: [PATCH 15/28] Add tests for SqlRuntimeCast int<->varchar Add two unit tests to SqlRuntimeCastTest verifying runtime casting: one ensures an Integer value is cast to VARCHAR (expecting "1"), and the other ensures a numeric String is cast to INTEGER (expecting 42). These tests cover basic int<->varchar conversion behavior. --- .../converter/functions/SqlRuntimeCastTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java index b9dee6f29..898fc49fc 100644 --- a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java +++ b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java @@ -35,4 +35,14 @@ void castNullYieldsNull() { assertNull(SqlRuntimeCast.castValue(null, SqlTypeName.INTEGER)); } + @Test + void castIntegerToVarchar() { + assertEquals("1", SqlRuntimeCast.castValue(1, SqlTypeName.VARCHAR)); + } + + @Test + void castStringToInteger() { + assertEquals(42, SqlRuntimeCast.castValue("42", SqlTypeName.INTEGER)); + } + } From 689396c0aa42361880c02bb04fea95a1c437bd7f Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:29:01 +0530 Subject: [PATCH 16/28] Add tests for SqlRuntimeCast conversions Add unit tests verifying SqlRuntimeCast.castValue handles string-to-double and NlsString-to-integer conversions. Adds castStringToDouble (asserts "1.5" -> DOUBLE with delta 1e-9) and castNlsStringToInteger (asserts NlsString("7", "UTF-8", null) -> INTEGER). --- .../converter/functions/SqlRuntimeCastTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java index 898fc49fc..42690e882 100644 --- a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java +++ b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java @@ -45,4 +45,15 @@ void castStringToInteger() { assertEquals(42, SqlRuntimeCast.castValue("42", SqlTypeName.INTEGER)); } + @Test + void castStringToDouble() { + assertEquals(1.5d, (Double) SqlRuntimeCast.castValue("1.5", SqlTypeName.DOUBLE), 1e-9); + } + + @Test + void castNlsStringToInteger() { + final NlsString nls = new NlsString("7", "UTF-8", null); + assertEquals(7, SqlRuntimeCast.castValue(nls, SqlTypeName.INTEGER)); + } + } From f265fafa6c64ae7e03f18f40f071c358105d94a7 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:29:11 +0530 Subject: [PATCH 17/28] Add test for casting string to boolean Add unit test in SqlRuntimeCastTest to verify that casting the string "TRUE" to SqlTypeName.BOOLEAN returns a Boolean instance and evaluates to true. Ensures runtime cast handles string-to-boolean conversion correctly. --- .../sql/calcite/converter/functions/SqlRuntimeCastTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java index 42690e882..443678f24 100644 --- a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java +++ b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java @@ -56,4 +56,10 @@ void castNlsStringToInteger() { assertEquals(7, SqlRuntimeCast.castValue(nls, SqlTypeName.INTEGER)); } + @Test + void castStringToBoolean() { + assertTrue(SqlRuntimeCast.castValue("TRUE", SqlTypeName.BOOLEAN) instanceof Boolean); + assertEquals(true, SqlRuntimeCast.castValue("TRUE", SqlTypeName.BOOLEAN)); + } + } From 7d89d4879418f14a9e6f21d0f31d53a1f50f083b Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:29:22 +0530 Subject: [PATCH 18/28] Add tests for SqlRuntimeCast edge cases Extend SqlRuntimeCastTest with additional unit tests covering error and formatting behavior: verify invalid boolean input throws RuntimeException, ensure BigDecimal -> VARCHAR conversion uses SQL formatting, and assert that casting to DATE is unsupported (throws UnsupportedOperationException). --- .../converter/functions/SqlRuntimeCastTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java index 443678f24..0b531f574 100644 --- a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java +++ b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCastTest.java @@ -62,4 +62,20 @@ void castStringToBoolean() { assertEquals(true, SqlRuntimeCast.castValue("TRUE", SqlTypeName.BOOLEAN)); } + @Test + void castInvalidBooleanThrows() { + assertThrows(RuntimeException.class, () -> SqlRuntimeCast.castValue("maybe", SqlTypeName.BOOLEAN)); + } + + @Test + void castBigDecimalToVarcharUsesSqlFormat() { + final String s = SqlRuntimeCast.castValue(BigDecimal.valueOf(1, 1), SqlTypeName.VARCHAR).toString(); + assertTrue(s.contains("1")); + } + + @Test + void castToDateUnsupported() { + assertThrows(UnsupportedOperationException.class, + () -> SqlRuntimeCast.castValue("2020-01-01", SqlTypeName.DATE)); + } } From 57fdacf2886eee62dca6aa65af3512540cff4084 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:29:37 +0530 Subject: [PATCH 19/28] Add test for CAST int->VARCHAR filter Add javaFilterWithCastIntColumnToVarchar unit test in SqlToWayangRelTest. The test builds and executes a plan for "SELECT * FROM fs.exampleInt WHERE CAST(NAMEB AS VARCHAR) = '1'", forces the Java platform for execution, and asserts non-empty results and that the filtered NAMEB field equals 1. This verifies casting an INT column to VARCHAR in a WHERE clause works as expected on the Java platform. --- .../wayang/api/sql/SqlToWayangRelTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/SqlToWayangRelTest.java b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/SqlToWayangRelTest.java index 88114774b..e5adfc6d6 100755 --- a/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/SqlToWayangRelTest.java +++ b/wayang-api/wayang-api-sql/src/test/java/org/apache/wayang/api/sql/SqlToWayangRelTest.java @@ -172,6 +172,23 @@ void javaFilterWithCast() throws Exception { assertTrue(result.stream().allMatch(field -> field.getField(1).equals("test1"))); } + @Test + void javaFilterWithCastIntColumnToVarchar() throws Exception { + final SqlContext sqlContext = this.createSqlContext("/data/exampleInt.csv"); + final Tuple2, WayangPlan> t = this.buildCollectorAndWayangPlan(sqlContext, + "SELECT * FROM fs.exampleInt WHERE CAST(NAMEB AS VARCHAR) = '1'"); + final Collection result = t.field0; + final WayangPlan wayangPlan = t.field1; + + PlanTraversal.upstream().traverse(wayangPlan.getSinks()).getTraversedNodes() + .forEach(node -> node.addTargetPlatform(Java.platform())); + + sqlContext.execute(wayangPlan); + + assertTrue(!result.isEmpty()); + assertTrue(result.stream().allMatch(field -> field.getField(1).equals(1))); + } + @Test void sqlApiSourceTest() throws Exception { final JavaTypeFactoryImpl typeFactory = new JavaTypeFactoryImpl(); From 7ad1fe0fe4ab29b22ab9ea2d0eb465347a20cc5d Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:43:33 +0530 Subject: [PATCH 20/28] Remove Java cast handling switch in SqlRuntimeCast MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the hard-coded switch statement that mapped SQL target types to Java conversion helpers in SqlRuntimeCast. This deletes per-type cases (BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, DECIMAL, FLOAT/REAL, DOUBLE, CHAR/VARCHAR) and the UnsupportedOperationException for unsupported targets — likely part of a refactor to centralize or replace cast handling. --- .../calcite/converter/functions/SqlRuntimeCast.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index ce9da252e..3667d6cf8 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -45,19 +45,6 @@ public static Object castValue(final Object input, final SqlTypeName target) { return null; } final Object v = unwrapForCast(input); - return switch (target) { - case BOOLEAN -> SqlFunctions.toBoolean(v); - case TINYINT -> SqlFunctions.toByte(v); - case SMALLINT -> SqlFunctions.toShort(v); - case INTEGER -> SqlFunctions.toInt(v); - case BIGINT -> SqlFunctions.toLong(v); - case DECIMAL -> SqlFunctions.toBigDecimal(v); - case FLOAT, REAL -> castToFloat(v); - case DOUBLE -> castToDouble(v); - case CHAR, VARCHAR -> castToString(v); - default -> throw new UnsupportedOperationException( - "CAST to " + target + " is not supported in Java filter evaluation yet."); - }; } private static Object unwrapForCast(final Object o) { From f91ba2a9ee8f4667cbed6640d77c85bebaf9ccb4 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:43:47 +0530 Subject: [PATCH 21/28] Support additional CAST target types in SqlRuntimeCast Add a switch on the target SqlTypeName in SqlRuntimeCast to perform runtime conversions using existing SqlFunctions and helper methods. Implements casting for BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, DECIMAL, FLOAT/REAL, DOUBLE and CHAR/VARCHAR, and throws an UnsupportedOperationException for other types. This enables Java-side evaluation of these CAST operations. --- .../converter/functions/SqlRuntimeCast.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index 3667d6cf8..51f1ef483 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -45,6 +45,31 @@ public static Object castValue(final Object input, final SqlTypeName target) { return null; } final Object v = unwrapForCast(input); + switch (target) { + case BOOLEAN: + return SqlFunctions.toBoolean(v); + case TINYINT: + return SqlFunctions.toByte(v); + case SMALLINT: + return SqlFunctions.toShort(v); + case INTEGER: + return SqlFunctions.toInt(v); + case BIGINT: + return SqlFunctions.toLong(v); + case DECIMAL: + return SqlFunctions.toBigDecimal(v); + case FLOAT: + case REAL: + return castToFloat(v); + case DOUBLE: + return castToDouble(v); + case CHAR: + case VARCHAR: + return castToString(v); + default: + throw new UnsupportedOperationException( + "CAST to " + target + " is not supported in Java filter evaluation yet."); + } } private static Object unwrapForCast(final Object o) { From 439cebdd48be909615aca6c7ebbb9a01b428da86 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:44:27 +0530 Subject: [PATCH 22/28] Replace pattern-matching instanceof for NlsString Use a traditional instanceof check plus cast for NlsString in unwrapForCast instead of pattern-matching. This avoids relying on newer Java pattern-matching features (or preview syntax) while preserving the original unwrapping behavior. --- .../api/sql/calcite/converter/functions/SqlRuntimeCast.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index 51f1ef483..33e89cfd5 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -73,8 +73,8 @@ public static Object castValue(final Object input, final SqlTypeName target) { } private static Object unwrapForCast(final Object o) { - if (o instanceof final NlsString nls) { - return nls.getValue(); + if (o instanceof NlsString) { + return ((NlsString) o).getValue(); } if (o instanceof final Character c) { return c.toString(); From ba95efb336fa539c41078ec96e8e46421d7a8cf8 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:44:52 +0530 Subject: [PATCH 23/28] Replace instanceof pattern variables with casts Modify SqlRuntimeCast to avoid Java pattern-matching instanceof syntax by using traditional instanceof checks and explicit casts. Updated Character, DateString, and Date branches to use classic casts (and o.toString()) to improve compatibility with Java versions that don't support the instanceof variable form; no functional behavior changes. --- .../calcite/converter/functions/SqlRuntimeCast.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index 33e89cfd5..f19491ea8 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -76,18 +76,18 @@ private static Object unwrapForCast(final Object o) { if (o instanceof NlsString) { return ((NlsString) o).getValue(); } - if (o instanceof final Character c) { - return c.toString(); + if (o instanceof Character) { + return o.toString(); } return o; } private static float castToFloat(final Object v) { - if (v instanceof final DateString ds) { - return (float) ds.getMillisSinceEpoch(); + if (v instanceof DateString) { + return (float) ((DateString) v).getMillisSinceEpoch(); } - if (v instanceof final Date d) { - return (float) d.getTime(); + if (v instanceof Date) { + return (float) ((Date) v).getTime(); } if (v instanceof final Calendar cal) { return (float) cal.getTimeInMillis(); From 0e3c51996e466bcf5552cf0baaca4af7120c6293 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:45:10 +0530 Subject: [PATCH 24/28] Use explicit casts instead of pattern-matching instanceof Replace pattern-matching instanceof usages with explicit casts in SqlRuntimeCast.java (for DateString, Date and Calendar). This is a syntactic change to avoid newer pattern-matching syntax and improve compatibility/consistency; runtime behavior is unchanged. --- .../converter/functions/SqlRuntimeCast.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index f19491ea8..6ab621f28 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -89,21 +89,21 @@ private static float castToFloat(final Object v) { if (v instanceof Date) { return (float) ((Date) v).getTime(); } - if (v instanceof final Calendar cal) { - return (float) cal.getTimeInMillis(); + if (v instanceof Calendar) { + return (float) ((Calendar) v).getTimeInMillis(); } return SqlFunctions.toFloat(v); } private static double castToDouble(final Object v) { - if (v instanceof final DateString ds) { - return (double) ds.getMillisSinceEpoch(); + if (v instanceof DateString) { + return (double) ((DateString) v).getMillisSinceEpoch(); } - if (v instanceof final Date d) { - return (double) d.getTime(); + if (v instanceof Date) { + return (double) ((Date) v).getTime(); } - if (v instanceof final Calendar cal) { - return (double) cal.getTimeInMillis(); + if (v instanceof Calendar) { + return (double) ((Calendar) v).getTimeInMillis(); } return SqlFunctions.toDouble(v); } From 152342d60dd5e302512f006fadc0a71b8cde8b54 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:45:40 +0530 Subject: [PATCH 25/28] Replace pattern-matching instanceof with casts Replace Java pattern-matching instanceof usages in SqlRuntimeCast with traditional instanceof checks and explicit casts (e.g. String, NlsString, Boolean cases). This removes preview/pattern-matching syntax and improves compatibility with Java versions that do not support pattern-matching; behavior remains unchanged. --- .../calcite/converter/functions/SqlRuntimeCast.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index 6ab621f28..c0d0912f0 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -109,14 +109,14 @@ private static double castToDouble(final Object v) { } private static String castToString(final Object v) { - if (v instanceof final String s) { - return s; + if (v instanceof String) { + return (String) v; } - if (v instanceof final NlsString nls) { - return nls.getValue(); + if (v instanceof NlsString) { + return ((NlsString) v).getValue(); } - if (v instanceof final Boolean b) { - return SqlFunctions.toString(b); + if (v instanceof Boolean) { + return SqlFunctions.toString((Boolean) v); } if (v instanceof final Float f) { return SqlFunctions.toString(f); From 85182636b933ea0e3a1b8be2027ad4965a07cbc0 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:46:00 +0530 Subject: [PATCH 26/28] Replace instanceof pattern variables with casts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace pattern-matching instanceof usages that declared pattern variables (e.g. 'if (v instanceof final Float f)') with traditional instanceof checks and explicit casts for Float, Double and BigDecimal in SqlRuntimeCast.java. No behavioral changes — this improves compatibility/readability by avoiding the newer pattern-variable syntax. --- .../calcite/converter/functions/SqlRuntimeCast.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index c0d0912f0..20bc1d576 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -118,14 +118,14 @@ private static String castToString(final Object v) { if (v instanceof Boolean) { return SqlFunctions.toString((Boolean) v); } - if (v instanceof final Float f) { - return SqlFunctions.toString(f); + if (v instanceof Float) { + return SqlFunctions.toString((Float) v); } - if (v instanceof final Double d) { - return SqlFunctions.toString(d); + if (v instanceof Double) { + return SqlFunctions.toString((Double) v); } - if (v instanceof final BigDecimal bd) { - return SqlFunctions.toString(bd); + if (v instanceof BigDecimal) { + return SqlFunctions.toString((BigDecimal) v); } if (v instanceof final Number n) { return n.toString(); From 1d5e0a30199668086bc9501cdcb52dcadbfed74e Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:46:31 +0530 Subject: [PATCH 27/28] Remove pattern-matching instanceof usages Replace Java pattern-matching instanceof (e.g., 'if (v instanceof final Number n)') with classic instanceof checks and explicit casts or direct v.toString() calls for DateString and Character in SqlRuntimeCast.java. This simplifies the code and improves compatibility with Java versions that do not support pattern-matching instanceof. --- .../calcite/converter/functions/SqlRuntimeCast.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index 20bc1d576..af87e010a 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -127,14 +127,14 @@ private static String castToString(final Object v) { if (v instanceof BigDecimal) { return SqlFunctions.toString((BigDecimal) v); } - if (v instanceof final Number n) { - return n.toString(); + if (v instanceof Number) { + return ((Number) v).toString(); } - if (v instanceof final DateString ds) { - return ds.toString(); + if (v instanceof DateString) { + return v.toString(); } - if (v instanceof final Character c) { - return c.toString(); + if (v instanceof Character) { + return v.toString(); } if (v instanceof final Date d) { return d.toString(); From 4f6e4f49db46aa81436edd282ab2782636b9d394 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Wed, 1 Apr 2026 23:46:54 +0530 Subject: [PATCH 28/28] Use classic instanceof checks for Date/Calendar Replace pattern-matching instanceof uses for Date and Calendar with traditional instanceof checks and explicit casts. The Date binding (previously 'instanceof final Date d') was removed in favor of v.toString(), and the Calendar case now casts to Calendar before calling getTime().toString(). This simplifies the code and improves compatibility with Java versions/compilers that don't support pattern-variable bindings. --- .../sql/calcite/converter/functions/SqlRuntimeCast.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java index af87e010a..667e13404 100644 --- a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java +++ b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/converter/functions/SqlRuntimeCast.java @@ -136,11 +136,11 @@ private static String castToString(final Object v) { if (v instanceof Character) { return v.toString(); } - if (v instanceof final Date d) { - return d.toString(); + if (v instanceof Date) { + return v.toString(); } - if (v instanceof final Calendar cal) { - return cal.getTime().toString(); + if (v instanceof Calendar) { + return ((Calendar) v).getTime().toString(); } return String.valueOf(v); }