Skip to content

Commit 8cf0b1f

Browse files
committed
Address review: use StandardCharsets.UTF_8 and hasToString() throughout RawFormatLineDelimiterTest
1 parent b219d10 commit 8cf0b1f

1 file changed

Lines changed: 50 additions & 21 deletions

File tree

flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/formats/raw/RawFormatLineDelimiterTest.java

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ class RawFormatLineDelimiterTest {
5656
void testDeserializeWithoutDelimiter_singleRow() throws Exception {
5757
RawFormatDeserializationSchema schema =
5858
new RawFormatDeserializationSchema(
59-
STRING_TYPE, TypeInformation.of(RowData.class), "UTF-8", true, null);
59+
STRING_TYPE,
60+
TypeInformation.of(RowData.class),
61+
StandardCharsets.UTF_8.name(),
62+
true,
63+
null);
6064
openDeser(schema);
6165

6266
List<RowData> rows = collectRows(schema, "hello".getBytes(StandardCharsets.UTF_8));
@@ -68,37 +72,49 @@ void testDeserializeWithoutDelimiter_singleRow() throws Exception {
6872
void testDeserializeWithNewlineDelimiter_multipleRows() throws Exception {
6973
RawFormatDeserializationSchema schema =
7074
new RawFormatDeserializationSchema(
71-
STRING_TYPE, TypeInformation.of(RowData.class), "UTF-8", true, "\n");
75+
STRING_TYPE,
76+
TypeInformation.of(RowData.class),
77+
StandardCharsets.UTF_8.name(),
78+
true,
79+
"\n");
7280
openDeser(schema);
7381

7482
byte[] message = "line1\nline2\nline3".getBytes(StandardCharsets.UTF_8);
7583
List<RowData> rows = collectRows(schema, message);
7684
assertThat(rows).hasSize(3);
77-
assertThat(rows.get(0).getString(0).toString()).isEqualTo("line1");
78-
assertThat(rows.get(1).getString(0).toString()).isEqualTo("line2");
79-
assertThat(rows.get(2).getString(0).toString()).isEqualTo("line3");
85+
assertThat(rows.get(0).getString(0)).hasToString("line1");
86+
assertThat(rows.get(1).getString(0)).hasToString("line2");
87+
assertThat(rows.get(2).getString(0)).hasToString("line3");
8088
}
8189

8290
@Test
8391
void testDeserializeWithCustomMultiCharDelimiter() throws Exception {
8492
RawFormatDeserializationSchema schema =
8593
new RawFormatDeserializationSchema(
86-
STRING_TYPE, TypeInformation.of(RowData.class), "UTF-8", true, "||");
94+
STRING_TYPE,
95+
TypeInformation.of(RowData.class),
96+
StandardCharsets.UTF_8.name(),
97+
true,
98+
"||");
8799
openDeser(schema);
88100

89101
byte[] message = "record1||record2||record3".getBytes(StandardCharsets.UTF_8);
90102
List<RowData> rows = collectRows(schema, message);
91103
assertThat(rows).hasSize(3);
92-
assertThat(rows.get(0).getString(0).toString()).isEqualTo("record1");
93-
assertThat(rows.get(1).getString(0).toString()).isEqualTo("record2");
94-
assertThat(rows.get(2).getString(0).toString()).isEqualTo("record3");
104+
assertThat(rows.get(0).getString(0)).hasToString("record1");
105+
assertThat(rows.get(1).getString(0)).hasToString("record2");
106+
assertThat(rows.get(2).getString(0)).hasToString("record3");
95107
}
96108

97109
@Test
98110
void testDeserializeWithNullMessage_noOutput() throws Exception {
99111
RawFormatDeserializationSchema schema =
100112
new RawFormatDeserializationSchema(
101-
STRING_TYPE, TypeInformation.of(RowData.class), "UTF-8", true, "\n");
113+
STRING_TYPE,
114+
TypeInformation.of(RowData.class),
115+
StandardCharsets.UTF_8.name(),
116+
true,
117+
"\n");
102118
openDeser(schema);
103119

104120
List<RowData> rows = collectRows(schema, null);
@@ -118,8 +134,8 @@ void testDeserializeWithGbkCharset() throws Exception {
118134

119135
List<RowData> rows = collectRows(schema, message);
120136
assertThat(rows).hasSize(2);
121-
assertThat(rows.get(0).getString(0).toString()).isEqualTo("你好");
122-
assertThat(rows.get(1).getString(0).toString()).isEqualTo("世界");
137+
assertThat(rows.get(0).getString(0)).hasToString("你好");
138+
assertThat(rows.get(1).getString(0)).hasToString("世界");
123139
}
124140

125141
// -----------------------------------------------------------------------
@@ -129,7 +145,8 @@ void testDeserializeWithGbkCharset() throws Exception {
129145
@Test
130146
void testSerializeWithoutDelimiter_noAppend() throws Exception {
131147
RawFormatSerializationSchema schema =
132-
new RawFormatSerializationSchema(STRING_TYPE, "UTF-8", true, null);
148+
new RawFormatSerializationSchema(
149+
STRING_TYPE, StandardCharsets.UTF_8.name(), true, null);
133150
openSer(schema);
134151

135152
RowData row = buildStringRow("hello");
@@ -140,7 +157,8 @@ void testSerializeWithoutDelimiter_noAppend() throws Exception {
140157
@Test
141158
void testSerializeWithNewlineDelimiter_appendsDelimiter() throws Exception {
142159
RawFormatSerializationSchema schema =
143-
new RawFormatSerializationSchema(STRING_TYPE, "UTF-8", true, "\n");
160+
new RawFormatSerializationSchema(
161+
STRING_TYPE, StandardCharsets.UTF_8.name(), true, "\n");
144162
openSer(schema);
145163

146164
RowData row = buildStringRow("hello");
@@ -151,7 +169,8 @@ void testSerializeWithNewlineDelimiter_appendsDelimiter() throws Exception {
151169
@Test
152170
void testSerializeWithCustomDelimiter_appendsDelimiter() throws Exception {
153171
RawFormatSerializationSchema schema =
154-
new RawFormatSerializationSchema(STRING_TYPE, "UTF-8", true, "||");
172+
new RawFormatSerializationSchema(
173+
STRING_TYPE, StandardCharsets.UTF_8.name(), true, "||");
155174
openSer(schema);
156175

157176
RowData row = buildStringRow("record1");
@@ -162,7 +181,8 @@ void testSerializeWithCustomDelimiter_appendsDelimiter() throws Exception {
162181
@Test
163182
void testSerializeNullRow_returnsNull() throws Exception {
164183
RawFormatSerializationSchema schema =
165-
new RawFormatSerializationSchema(STRING_TYPE, "UTF-8", true, "\n");
184+
new RawFormatSerializationSchema(
185+
STRING_TYPE, StandardCharsets.UTF_8.name(), true, "\n");
166186
openSer(schema);
167187

168188
GenericRowData nullRow = new GenericRowData(1);
@@ -178,27 +198,36 @@ void testDeserializeTrailingDelimiter_noExtraRow() throws Exception {
178198
// deserialize -> ["hello"] (1 row, not 2).
179199
RawFormatDeserializationSchema schema =
180200
new RawFormatDeserializationSchema(
181-
STRING_TYPE, TypeInformation.of(RowData.class), "UTF-8", true, "\n");
201+
STRING_TYPE,
202+
TypeInformation.of(RowData.class),
203+
StandardCharsets.UTF_8.name(),
204+
true,
205+
"\n");
182206
openDeser(schema);
183207

184208
// Message already ends with the delimiter (as produced by the serializer)
185209
byte[] message = "hello\n".getBytes(StandardCharsets.UTF_8);
186210
List<RowData> rows = collectRows(schema, message);
187211
assertThat(rows).hasSize(1);
188-
assertThat(rows.get(0).getString(0).toString()).isEqualTo("hello");
212+
assertThat(rows.get(0).getString(0)).hasToString("hello");
189213
}
190214

191215
@Test
192216
void testRoundTrip_serializeThenDeserialize() throws Exception {
193217
// Verify that rows written by the serializer can be read back correctly by the
194218
// deserializer when both share the same delimiter configuration.
195219
RawFormatSerializationSchema ser =
196-
new RawFormatSerializationSchema(STRING_TYPE, "UTF-8", true, "\n");
220+
new RawFormatSerializationSchema(
221+
STRING_TYPE, StandardCharsets.UTF_8.name(), true, "\n");
197222
openSer(ser);
198223

199224
RawFormatDeserializationSchema deser =
200225
new RawFormatDeserializationSchema(
201-
STRING_TYPE, TypeInformation.of(RowData.class), "UTF-8", true, "\n");
226+
STRING_TYPE,
227+
TypeInformation.of(RowData.class),
228+
StandardCharsets.UTF_8.name(),
229+
true,
230+
"\n");
202231
openDeser(deser);
203232

204233
// Serialize a single row -> "hello\n"
@@ -207,7 +236,7 @@ void testRoundTrip_serializeThenDeserialize() throws Exception {
207236
// Deserialize "hello\n" -> should yield exactly 1 row
208237
List<RowData> rows = collectRows(deser, serialized);
209238
assertThat(rows).hasSize(1);
210-
assertThat(rows.get(0).getString(0).toString()).isEqualTo("hello");
239+
assertThat(rows.get(0).getString(0)).hasToString("hello");
211240
}
212241

213242
// -----------------------------------------------------------------------

0 commit comments

Comments
 (0)