wuchong commented on a change in pull request #12421:
URL: https://github.com/apache/flink/pull/12421#discussion_r433038726
##########
File path:
flink-formats/flink-json/src/test/java/org/apache/flink/formats/json/JsonRowDataSerDeSchemaTest.java
##########
@@ -403,57 +407,84 @@ 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\":\"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))))
- .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\":\"abc\"}")
.rowType(ROW(FIELD("id", DECIMAL(10, 3))))
- .expectErrorMessage("Failed to deserialize JSON
'{\"id\":\"abc\"}'"),
+ .expectErrorMessage("Failed to deserialize JSON
'{\"id\":\"abc\"}'."),
TestSpec
.json("{\"row\":{\"id\":\"abc\"}}")
.rowType(ROW(FIELD("row", ROW(FIELD("id", BOOLEAN())))))
- .expect(Row.of(new Row(1)))
- .expectErrorMessage("Failed to deserialize JSON
'{\"row\":{\"id\":\"abc\"}}'"),
+ .expect(Row.of(Row.of(false))),
Review comment:
Why the previous one can pass the tests....?
##########
File path:
flink-formats/flink-json/src/test/java/org/apache/flink/formats/json/JsonRowDataSerDeSchemaTest.java
##########
@@ -375,8 +375,12 @@ private void testParseErrors(TestSpec spec) throws
Exception {
JsonRowDataDeserializationSchema failingSchema = new
JsonRowDataDeserializationSchema(
spec.rowType, new RowDataTypeInfo(spec.rowType),
false, false);
- thrown.expectMessage(spec.errorMessage);
- failingSchema.deserialize(spec.json.getBytes());
+ try {
+ failingSchema.deserialize(spec.json.getBytes());
+ throw new RuntimeException("expecting exception " +
spec.errorMessage);
+ } catch (Throwable t) {
+ assertEquals(t.getMessage(), spec.errorMessage);
+ }
Review comment:
IMO, `thrown.expectMessage` is more concise for the exception
validation. Do we have a reason to change this?
----------------------------------------------------------------
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]