cjohnson-confluent commented on code in PR #29063:
URL: https://github.com/apache/flink/pull/29063#discussion_r3936296674


##########
flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/functions/SqlJsonUtilsConversionTest.java:
##########
@@ -0,0 +1,396 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.table.runtime.functions;
+
+import org.apache.flink.table.api.JsonValueOnEmptyOrError;
+import org.apache.flink.table.api.TableRuntimeException;
+import org.apache.flink.table.data.DecimalData;
+import org.apache.flink.table.data.GenericArrayData;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.stream.Stream;
+
+import static org.apache.flink.table.api.JsonQueryOnEmptyOrError.EMPTY_ARRAY;
+import static org.apache.flink.table.api.JsonQueryOnEmptyOrError.ERROR;
+import static org.apache.flink.table.api.JsonQueryOnEmptyOrError.NULL;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.BIGINT;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.BOOLEAN;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.DECIMAL;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.DOUBLE;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.FLOAT;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.INTEGER;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.SMALLINT;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.TINYINT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class SqlJsonUtilsConversionTest {
+
+    private static Object scalar(Object raw, LogicalTypeRoot type) {
+        return SqlJsonUtils.convertJsonScalar(raw, type, 0, 0, 
JsonValueOnEmptyOrError.NULL, null);
+    }
+
+    private static Object scalar(
+            Object raw,
+            LogicalTypeRoot type,
+            JsonValueOnEmptyOrError onError,
+            Object defaultValue) {
+        return SqlJsonUtils.convertJsonScalar(raw, type, 0, 0, onError, 
defaultValue);
+    }
+
+    private static Object scalarDecimal(Object raw, int precision, int scale) {
+        return SqlJsonUtils.convertJsonScalar(
+                raw, DECIMAL, precision, scale, JsonValueOnEmptyOrError.NULL, 
null);
+    }
+
+    private static GenericArrayData array(Object[] raw, LogicalTypeRoot 
elementType) {
+        return SqlJsonUtils.convertJsonArray(raw, elementType, 0, 0, NULL);
+    }
+
+    private static GenericArrayData arrayDecimal(
+            Object[] raw,
+            int precision,
+            int scale,
+            org.apache.flink.table.api.JsonQueryOnEmptyOrError onError) {

Review Comment:
   Applied.



##########
flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/functions/SqlJsonUtilsConversionTest.java:
##########
@@ -0,0 +1,396 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.table.runtime.functions;
+
+import org.apache.flink.table.api.JsonValueOnEmptyOrError;
+import org.apache.flink.table.api.TableRuntimeException;
+import org.apache.flink.table.data.DecimalData;
+import org.apache.flink.table.data.GenericArrayData;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.stream.Stream;
+
+import static org.apache.flink.table.api.JsonQueryOnEmptyOrError.EMPTY_ARRAY;
+import static org.apache.flink.table.api.JsonQueryOnEmptyOrError.ERROR;
+import static org.apache.flink.table.api.JsonQueryOnEmptyOrError.NULL;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.BIGINT;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.BOOLEAN;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.DECIMAL;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.DOUBLE;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.FLOAT;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.INTEGER;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.SMALLINT;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.TINYINT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class SqlJsonUtilsConversionTest {
+
+    private static Object scalar(Object raw, LogicalTypeRoot type) {
+        return SqlJsonUtils.convertJsonScalar(raw, type, 0, 0, 
JsonValueOnEmptyOrError.NULL, null);
+    }
+
+    private static Object scalar(
+            Object raw,
+            LogicalTypeRoot type,
+            JsonValueOnEmptyOrError onError,
+            Object defaultValue) {
+        return SqlJsonUtils.convertJsonScalar(raw, type, 0, 0, onError, 
defaultValue);
+    }
+
+    private static Object scalarDecimal(Object raw, int precision, int scale) {
+        return SqlJsonUtils.convertJsonScalar(
+                raw, DECIMAL, precision, scale, JsonValueOnEmptyOrError.NULL, 
null);
+    }
+
+    private static GenericArrayData array(Object[] raw, LogicalTypeRoot 
elementType) {
+        return SqlJsonUtils.convertJsonArray(raw, elementType, 0, 0, NULL);
+    }
+
+    private static GenericArrayData arrayDecimal(
+            Object[] raw,
+            int precision,
+            int scale,
+            org.apache.flink.table.api.JsonQueryOnEmptyOrError onError) {
+        return SqlJsonUtils.convertJsonArray(raw, DECIMAL, precision, scale, 
onError);
+    }
+
+    static Stream<Arguments> validConversions() {
+        return Stream.of(
+                Arguments.of(42, TINYINT, (byte) 42),
+                Arguments.of(127L, TINYINT, Byte.MAX_VALUE),
+                Arguments.of(-128L, TINYINT, Byte.MIN_VALUE),
+                Arguments.of(1000, SMALLINT, (short) 1000),
+                Arguments.of((long) Short.MAX_VALUE, SMALLINT, 
Short.MAX_VALUE),
+                Arguments.of(42L, INTEGER, 42),
+                Arguments.of((long) Integer.MAX_VALUE, INTEGER, 
Integer.MAX_VALUE),
+                Arguments.of(42, BIGINT, 42L),
+                Arguments.of(9_999_999_999L, BIGINT, 9_999_999_999L),
+                Arguments.of(13.37, FLOAT, 13.37f),
+                Arguments.of(13.37, DOUBLE, 13.37));
+    }
+
+    static Stream<Arguments> overflowCases() {
+        return Stream.of(
+                Arguments.of(128, TINYINT),
+                Arguments.of(-129, TINYINT),
+                Arguments.of(200L, TINYINT),
+                Arguments.of(-200L, TINYINT),
+                Arguments.of((long) Short.MAX_VALUE + 1, SMALLINT),
+                Arguments.of((long) Short.MIN_VALUE - 1, SMALLINT),
+                Arguments.of(40_000L, SMALLINT),
+                Arguments.of(-40_000L, SMALLINT),
+                Arguments.of(9_999_999_999L, INTEGER),
+                Arguments.of(-9_999_999_999L, INTEGER));
+    }
+
+    @Nested
+    class RangeCheckedConversions {
+
+        @ParameterizedTest(name = "{0} -> {1}")
+        @MethodSource(
+                
"org.apache.flink.table.runtime.functions.SqlJsonUtilsConversionTest#validConversions")

Review Comment:
   Java 11 source level forbids static methods in non-static inner classes, and 
`@Nested` test classes are non-static by definition. The `@MethodSource` 
providers must stay at the outer class level with FQN references.



##########
flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/functions/SqlJsonUtilsConversionTest.java:
##########
@@ -0,0 +1,396 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.table.runtime.functions;
+
+import org.apache.flink.table.api.JsonValueOnEmptyOrError;
+import org.apache.flink.table.api.TableRuntimeException;
+import org.apache.flink.table.data.DecimalData;
+import org.apache.flink.table.data.GenericArrayData;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.stream.Stream;
+
+import static org.apache.flink.table.api.JsonQueryOnEmptyOrError.EMPTY_ARRAY;
+import static org.apache.flink.table.api.JsonQueryOnEmptyOrError.ERROR;
+import static org.apache.flink.table.api.JsonQueryOnEmptyOrError.NULL;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.BIGINT;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.BOOLEAN;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.DECIMAL;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.DOUBLE;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.FLOAT;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.INTEGER;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.SMALLINT;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.TINYINT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class SqlJsonUtilsConversionTest {
+
+    private static Object scalar(Object raw, LogicalTypeRoot type) {
+        return SqlJsonUtils.convertJsonScalar(raw, type, 0, 0, 
JsonValueOnEmptyOrError.NULL, null);
+    }
+
+    private static Object scalar(
+            Object raw,
+            LogicalTypeRoot type,
+            JsonValueOnEmptyOrError onError,
+            Object defaultValue) {
+        return SqlJsonUtils.convertJsonScalar(raw, type, 0, 0, onError, 
defaultValue);
+    }
+
+    private static Object scalarDecimal(Object raw, int precision, int scale) {
+        return SqlJsonUtils.convertJsonScalar(
+                raw, DECIMAL, precision, scale, JsonValueOnEmptyOrError.NULL, 
null);
+    }
+
+    private static GenericArrayData array(Object[] raw, LogicalTypeRoot 
elementType) {
+        return SqlJsonUtils.convertJsonArray(raw, elementType, 0, 0, NULL);
+    }
+
+    private static GenericArrayData arrayDecimal(
+            Object[] raw,
+            int precision,
+            int scale,
+            org.apache.flink.table.api.JsonQueryOnEmptyOrError onError) {
+        return SqlJsonUtils.convertJsonArray(raw, DECIMAL, precision, scale, 
onError);
+    }
+
+    static Stream<Arguments> validConversions() {
+        return Stream.of(
+                Arguments.of(42, TINYINT, (byte) 42),
+                Arguments.of(127L, TINYINT, Byte.MAX_VALUE),
+                Arguments.of(-128L, TINYINT, Byte.MIN_VALUE),
+                Arguments.of(1000, SMALLINT, (short) 1000),
+                Arguments.of((long) Short.MAX_VALUE, SMALLINT, 
Short.MAX_VALUE),
+                Arguments.of(42L, INTEGER, 42),
+                Arguments.of((long) Integer.MAX_VALUE, INTEGER, 
Integer.MAX_VALUE),
+                Arguments.of(42, BIGINT, 42L),
+                Arguments.of(9_999_999_999L, BIGINT, 9_999_999_999L),
+                Arguments.of(13.37, FLOAT, 13.37f),
+                Arguments.of(13.37, DOUBLE, 13.37));
+    }
+
+    static Stream<Arguments> overflowCases() {
+        return Stream.of(
+                Arguments.of(128, TINYINT),
+                Arguments.of(-129, TINYINT),
+                Arguments.of(200L, TINYINT),
+                Arguments.of(-200L, TINYINT),
+                Arguments.of((long) Short.MAX_VALUE + 1, SMALLINT),
+                Arguments.of((long) Short.MIN_VALUE - 1, SMALLINT),
+                Arguments.of(40_000L, SMALLINT),
+                Arguments.of(-40_000L, SMALLINT),
+                Arguments.of(9_999_999_999L, INTEGER),
+                Arguments.of(-9_999_999_999L, INTEGER));
+    }
+
+    @Nested
+    class RangeCheckedConversions {
+
+        @ParameterizedTest(name = "{0} -> {1}")
+        @MethodSource(
+                
"org.apache.flink.table.runtime.functions.SqlJsonUtilsConversionTest#validConversions")
+        void convertsWithinRange(Number input, LogicalTypeRoot type, Object 
expected) {
+            assertThat(scalar(input, type)).isEqualTo(expected);
+        }
+
+        @ParameterizedTest(name = "{0} -> {1}")
+        @MethodSource(
+                
"org.apache.flink.table.runtime.functions.SqlJsonUtilsConversionTest#overflowCases")

Review Comment:
   The test data involves `LogicalTypeRoot` enums and typed expected values 
(`(byte) 42`, `BigDecimal`, `BigInteger`) that `@CsvSource` cannot represent.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to