wuchong commented on a change in pull request #12421:
URL: https://github.com/apache/flink/pull/12421#discussion_r453418557



##########
File path: 
flink-formats/flink-json/src/test/java/org/apache/flink/formats/json/JsonRowDataSerDeSchemaTest.java
##########
@@ -326,22 +322,30 @@ public void testDeserializationMissingNode() throws 
Exception {
                deserializationSchema = deserializationSchema = new 
JsonRowDataDeserializationSchema(
                        schema, WrapperTypeInfo.of(schema), true, false, 
TimestampFormat.ISO_8601);
 
-               thrown.expect(IOException.class);
-               thrown.expectMessage("Failed to deserialize JSON 
'{\"id\":123123123}'");
-               deserializationSchema.deserialize(serializedJson);
+               String errorMessage = "Failed to deserialize JSON 
'{\"id\":123123123}'.";
+               try {
+                       deserializationSchema.deserialize(serializedJson);
+                       throw new RuntimeException("expecting exception 
message: " + errorMessage);

Review comment:
       Use `org.junit.Assert#fail(java.lang.String)` instead: `fail("expecting 
exception message: " + errorMessage);` 

##########
File path: 
flink-formats/flink-json/src/test/java/org/apache/flink/formats/json/JsonRowDataSerDeSchemaTest.java
##########
@@ -428,84 +436,111 @@ private void testParseErrors(TestSpec spec) throws 
Exception {
                TestSpec
                        .json("{\"id\":\"long\"}")
                        .rowType(ROW(FIELD("id", BIGINT())))
-                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"long\"}'"),
+                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"long\"}'."),
 
                TestSpec
                        .json("{\"id\":\"112.013.123\"}")
                        .rowType(ROW(FIELD("id", FLOAT())))
-                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"112.013.123\"}'"),
+                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"112.013.123\"}'."),
 
                TestSpec
                        .json("{\"id\":\"112.013.123\"}")
                        .rowType(ROW(FIELD("id", DOUBLE())))
-                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"112.013.123\"}'"),
+                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"112.013.123\"}'."),
 
                TestSpec
                        .json("{\"id\":\"18:00:243\"}")
                        .rowType(ROW(FIELD("id", TIME())))
-                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"18:00:243\"}'"),
+                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"18:00:243\"}'."),
 
                TestSpec
                        .json("{\"id\":\"18:00:243\"}")
                        .rowType(ROW(FIELD("id", TIME())))
-                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"18:00:243\"}'"),
+                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"18:00:243\"}'."),
 
                TestSpec
                        .json("{\"id\":\"20191112\"}")
                        .rowType(ROW(FIELD("id", DATE())))
-                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"20191112\"}'"),
+                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"20191112\"}'."),
 
                TestSpec
                        .json("{\"id\":\"20191112\"}")
                        .rowType(ROW(FIELD("id", DATE())))
-                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"20191112\"}'"),
+                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"20191112\"}'."),
+
+               TestSpec
+                       .json("{\"id\":true}")
+                       .rowType(ROW(FIELD("id", STRING())))
+                       .expect(Row.of("true")),
+
+               TestSpec
+                       .json("{\"id\":123.234}")
+                       .rowType(ROW(FIELD("id", STRING())))
+                       .expect(Row.of("123.234")),
+
+               TestSpec
+                       .json("{\"id\":1234567}")
+                       .rowType(ROW(FIELD("id", STRING())))
+                       .expect(Row.of("1234567")),
+
+               TestSpec
+                       .json("{\"id\":\"string field\"}")
+                       .rowType(ROW(FIELD("id", STRING())))
+                       .expect(Row.of("string field")),
+
+               TestSpec
+                       .json("{\"id\":[\"array data1\",\"array 
data2\",123,234.345]}")
+                       .rowType(ROW(FIELD("id", STRING())))
+                       .expect(Row.of("[\"array data1\",\"array 
data2\",123,234.345]")),
+
+               TestSpec
+                       
.json("{\"id\":{\"k1\":123,\"k2\":234.234,\"k3\":\"string data\"}}")
+                       .rowType(ROW(FIELD("id", STRING())))
+                       
.expect(Row.of("{\"k1\":123,\"k2\":234.234,\"k3\":\"string data\"}")),
 
                TestSpec
                        .json("{\"id\":\"2019-11-12 18:00:12\"}")
                        .rowType(ROW(FIELD("id", TIMESTAMP(0))))
                        .timestampFormat(TimestampFormat.ISO_8601)
-                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"2019-11-12 18:00:12\"}'"),
+                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"2019-11-12 18:00:12\"}'."),
 
                TestSpec
                        .json("{\"id\":\"2019-11-12T18:00:12\"}")
                        .rowType(ROW(FIELD("id", TIMESTAMP(0))))
-                       .expectErrorMessage("Failed to deserialize JSON 
'{\"id\":\"2019-11-12T18:00:12\"}'"),
+                       
.expect(Row.of(LocalDateTime.parse("2019-11-12T18:00:12"))),

Review comment:
       This should fail. We should update `testIgnoreParseErrors` to use 
`spec.timestampFormat` instead of hard code ISO. 

##########
File path: 
flink-formats/flink-json/src/test/java/org/apache/flink/formats/json/JsonRowDataSerDeSchemaTest.java
##########
@@ -326,22 +322,30 @@ public void testDeserializationMissingNode() throws 
Exception {
                deserializationSchema = deserializationSchema = new 
JsonRowDataDeserializationSchema(
                        schema, WrapperTypeInfo.of(schema), true, false, 
TimestampFormat.ISO_8601);
 
-               thrown.expect(IOException.class);
-               thrown.expectMessage("Failed to deserialize JSON 
'{\"id\":123123123}'");
-               deserializationSchema.deserialize(serializedJson);
+               String errorMessage = "Failed to deserialize JSON 
'{\"id\":123123123}'.";
+               try {
+                       deserializationSchema.deserialize(serializedJson);
+                       throw new RuntimeException("expecting exception 
message: " + errorMessage);
+               } catch (Throwable t) {
+                       assertEquals(errorMessage, t.getMessage());
+               }
 
                // ignore on parse error
                deserializationSchema = new JsonRowDataDeserializationSchema(
                        schema, WrapperTypeInfo.of(schema), false, true, 
TimestampFormat.ISO_8601);
                actual = 
convertToExternal(deserializationSchema.deserialize(serializedJson), dataType);
                assertEquals(expected, actual);
 
-               thrown.expect(IllegalArgumentException.class);
-               thrown.expectMessage("JSON format doesn't support 
failOnMissingField and ignoreParseErrors are both enabled");
-               // failOnMissingField and ignoreParseErrors both enabled
-               //noinspection ConstantConditions
-               new JsonRowDataDeserializationSchema(
-                       schema, WrapperTypeInfo.of(schema), true, true, 
TimestampFormat.ISO_8601);
+               errorMessage = "JSON format doesn't support failOnMissingField 
and ignoreParseErrors are both enabled.";
+               try {
+                       // failOnMissingField and ignoreParseErrors both enabled
+                       //noinspection ConstantConditions
+                       new JsonRowDataDeserializationSchema(
+                               schema, new RowDataTypeInfo(schema), true, 
true, TimestampFormat.ISO_8601);

Review comment:
       Use `WrapperTypeInfo.of(schema)` instead of `new 
RowDataTypeInfo(schema)`. We are in the progress of removing `RowDataTypeInfo`.




----------------------------------------------------------------
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.

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


Reply via email to