twalthr commented on a change in pull request #18342:
URL: https://github.com/apache/flink/pull/18342#discussion_r783933173
##########
File path:
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/serde/RelDataTypeJsonSerdeTest.java
##########
@@ -46,83 +35,113 @@
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.sql.type.SqlTypeName;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.runners.Parameterized.Parameters;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
+import static
org.apache.flink.table.planner.plan.nodes.exec.serde.JsonSerdeMocks.configuredSerdeContext;
+import static
org.apache.flink.table.planner.plan.nodes.exec.serde.JsonSerdeMocks.toJson;
+import static
org.apache.flink.table.planner.plan.nodes.exec.serde.JsonSerdeMocks.toObject;
+import static org.assertj.core.api.Assertions.assertThat;
-/** Tests for serialization/deserialization of {@link RelDataType}. */
-@RunWith(Parameterized.class)
+/** Tests for {@link RelDataType} serialization and deserialization. */
public class RelDataTypeJsonSerdeTest {
+
private static final FlinkTypeFactory FACTORY =
FlinkTypeFactory.INSTANCE();
- @Parameterized.Parameters(name = "type = {0}")
- public static Collection<RelDataType> parameters() {
+ @ParameterizedTest
+ @MethodSource("testRelDataTypeSerde")
+ public void testRelDataTypeSerde(RelDataType relDataType) throws
IOException {
+ final SerdeContext serdeContext = configuredSerdeContext();
+
+ final String json = toJson(serdeContext, relDataType);
+ final RelDataType actual = toObject(serdeContext, json,
RelDataType.class);
+
+ assertThat(actual).isSameAs(relDataType);
+ }
+
+ @Test
+ public void testMissingPrecisionAndScale() {
+ final SerdeContext serdeContext = configuredSerdeContext();
+
+ final String json =
+ toJson(
+ serdeContext,
+ FACTORY.createSqlIntervalType(
+ new SqlIntervalQualifier(
+ TimeUnit.DAY, TimeUnit.SECOND,
SqlParserPos.ZERO)));
+ final RelDataType actual = toObject(serdeContext, json,
RelDataType.class);
+
+ assertThat(actual)
+ .isSameAs(
+ FACTORY.createSqlIntervalType(
+ new SqlIntervalQualifier(
+ TimeUnit.DAY,
+
DayTimeIntervalType.DEFAULT_DAY_PRECISION,
+ TimeUnit.SECOND,
+
DayTimeIntervalType.DEFAULT_FRACTIONAL_PRECISION,
+ SqlParserPos.ZERO)));
+ }
+
+ //
--------------------------------------------------------------------------------------------
+ // Test data
+ //
--------------------------------------------------------------------------------------------
+
+ @Parameters(name = "{0}")
+ public static List<RelDataType> testRelDataTypeSerde() {
// the values in the list do not care about nullable.
- List<RelDataType> types =
+ final List<RelDataType> types =
Arrays.asList(
FACTORY.createSqlType(SqlTypeName.BOOLEAN),
FACTORY.createSqlType(SqlTypeName.TINYINT),
FACTORY.createSqlType(SqlTypeName.SMALLINT),
FACTORY.createSqlType(SqlTypeName.INTEGER),
FACTORY.createSqlType(SqlTypeName.BIGINT),
- FACTORY.createSqlType(SqlTypeName.DECIMAL, 3, 10),
- FACTORY.createSqlType(SqlTypeName.DECIMAL, 0, 19),
- FACTORY.createSqlType(SqlTypeName.DECIMAL, -1, 19),
Review comment:
correct me if I'm wrong, but why should we support negative precision or
scale that is smaller than precision? it looks like a bug in the tests to me.
--
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]