yuxiqian commented on code in PR #3658: URL: https://github.com/apache/flink-cdc/pull/3658#discussion_r1860226446
########## flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/test/resources/ddl/column_type_test_mysql8.sql: ########## Review Comment: Accidental change? ########## flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/json/JsonStringFormatter.java: ########## @@ -0,0 +1,337 @@ +/* + * 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 com.github.shyiko.mysql.binlog.event.deserialization.json; + +import com.github.shyiko.mysql.binlog.event.deserialization.ColumnType; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Base64; + +import static org.apache.flink.cdc.connectors.mysql.source.config.MySqlSourceConfig.useLegacyJsonFormat; + +/** + * Copied from mysql-binlog-connector-java 0.27.2 to add whitespace before value and after comma. + * + * <p>Line 105: Added whitespace before value, Line 207: Added whitespace after comma Review Comment: Seems line numbers have been differed from actual changes. ########## flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/main/java/org/apache/flink/cdc/connectors/mysql/table/MySqlTableSourceFactory.java: ########## Review Comment: Since DataStream / Table source connectors' behavior also changed, corresponding integrated test cases might be necessary. ########## flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-mysql/src/test/java/org/apache/flink/cdc/connectors/mysql/source/MySqlFullTypesITCase.java: ########## @@ -457,6 +495,61 @@ private void testCommonDataTypes(UniqueDatabase database) throws Exception { .isEqualTo(expectedStreamRecord); } + private void testJsonDataType(UniqueDatabase database, Boolean useLegacyJsonFormat) + throws Exception { + database.createAndInitialize(); + CloseableIterator<Event> iterator = + env.fromSource( + getFlinkSourceProvider( + new String[] {"json_types"}, + database, + useLegacyJsonFormat) + .getSource(), + WatermarkStrategy.noWatermarks(), + "Event-Source") + .executeAndCollect(); + + Object[] expectedSnapshot = + new Object[] { + DecimalData.fromBigDecimal(new BigDecimal("1"), 20, 0), + BinaryStringData.fromString("{\"key1\": \"value1\"}"), + BinaryStringData.fromString("{\"key1\": \"value1\", \"key2\": \"value2\"}"), + BinaryStringData.fromString( + "[{\"key1\": \"value1\", \"key2\": {\"key2_1\": \"value2_1\", \"key2_2\": \"value2_2\"}, \"key3\": [\"value3\"], \"key4\": [\"value4_1\", \"value4_2\"]}, {\"key5\": \"value5\"}]"), + 1 + }; + + // skip CreateTableEvent + List<Event> snapshotResults = + MySqSourceTestUtils.fetchResultsAndCreateTableEvent(iterator, 1).f0; + RecordData snapshotRecord = ((DataChangeEvent) snapshotResults.get(0)).after(); + Assertions.assertThat(RecordDataTestUtils.recordFields(snapshotRecord, JSON_TYPES)) + .isEqualTo(expectedSnapshot); + + try (Connection connection = database.getJdbcConnection(); + Statement statement = connection.createStatement()) { + statement.execute("UPDATE json_types SET int_c = null WHERE id = 1;"); + } + + Object[] expectedStreamRecord = expectedSnapshot; + + if (useLegacyJsonFormat) { + expectedSnapshot[1] = BinaryStringData.fromString("{\"key1\":\"value1\"}"); + expectedSnapshot[2] = + BinaryStringData.fromString("{\"key1\":\"value1\",\"key2\":\"value2\"}"); + expectedSnapshot[3] = + BinaryStringData.fromString( + "[{\"key1\":\"value1\",\"key2\":{\"key2_1\":\"value2_1\",\"key2_2\":\"value2_2\"},\"key3\":[\"value3\"],\"key4\":[\"value4_1\",\"value4_2\"]},{\"key5\":\"value5\"}]"); + } + expectedSnapshot[4] = null; Review Comment: Modifying expected data is a little confusing. Will something like ```java if (useLegacyJsonFormat) { assertThat(RecordDataTestUtils.recordFields(...)) .containsExactly( BinaryStringData.fromString("{\"key1\":\"value1\"}"), BinaryStringData.fromString("{\"key2\":\"value2\"}"), ... ); } else { assertThat(RecordDataTestUtils.recordFields(...)) .containsExactly(...); } ``` be clearer? -- 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]
