You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/05/14 12:11:33 UTC

[GitHub] [flink] wuchong opened a new pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

wuchong opened a new pull request #12152:
URL: https://github.com/apache/flink/pull/12152


   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Travis CI to do that following [this guide](https://flink.apache.org/contributing/contribute-code.html#open-a-pull-request).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   Introduce `DebeziumFormatFactory` and `CanalFormatFactory` to read changelogs.
   
   ```sql
   CREATE TABLE my_table (
     ...
   ) WITH (
     'connector'='...',  -- e.g. 'kafka'
     'format'='debezium-json',
     'debezium-json.schema-include'='true' -- default false, Debeizum can be configured to include or exclude the message schema
     'debezium-json.ignore-parse-errors'='true' -- default false
   );
   
   CREATE TABLE my_table (
     ...
   ) WITH (
    'connector'='...', -- e.g. 'kafka'
    'format'='canal-json',
    'canal-json.ignore-parse-errors'='true' -- default false
   );
   ```
   
   ## Brief change log
   
   - The first commit is from #12140, will rebase once it gets merged.
   - Introduced `DebeziumJsonDeserializationSchema` and `DebeziumFormatFactory` to deserialize Debezium messages.
   - Introduced `CanalJsonDeserializationSchema` and `CanalFormatFactory` to deserialize Canal messages.
   - Throw exception in `DebeziumFormatFactory#createSinkFormat` and `CanalFormatFactory#createSinkFormat` to tell users they can't be as sink for now. 
   
   ## Verifying this change
   
   - Added `DebeziumJsonDeserializationSchemaTest` and `CanalsonDeserializationSchemaTest` to deserialize debezium messages and canal messages. 
   - Added `DebeziumFormatFactoryTest` and `CanalFormatFactoryTest` to unit test factories. 
   
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? yes
     - If yes, how is the feature documented? not documented
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-628617951


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1299",
       "triggerID" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1349",
       "triggerID" : "4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "aae6bd7bf9952a5baa6b7ced9dd395d834543f77",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1406",
       "triggerID" : "aae6bd7bf9952a5baa6b7ced9dd395d834543f77",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * aae6bd7bf9952a5baa6b7ced9dd395d834543f77 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1406) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] danny0405 commented on a change in pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #12152:
URL: https://github.com/apache/flink/pull/12152#discussion_r425633198



##########
File path: flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/canal/CanalJsonDeserializationSchema.java
##########
@@ -0,0 +1,179 @@
+/*
+ * 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 org.apache.flink.formats.json.canal;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.formats.json.JsonRowDataDeserializationSchema;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.ArrayData;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.Collector;
+
+import java.io.IOException;
+import java.util.Objects;
+
+import static java.lang.String.format;
+import static org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType;
+
+/**
+ * Deserialization schema from Canal JSON to Flink Table/SQL internal data structure {@link RowData}.
+ * The deserialization schema knows Debezium's schema definition and can extract the database data
+ * and convert into {@link RowData} with {@link RowKind}.
+ *
+ * <p>Deserializes a <code>byte[]</code> message as a JSON object and reads
+ * the specified fields.
+ *
+ * <p>Failures during deserialization are forwarded as wrapped IOExceptions.
+ *
+ * @see <a href="https://github.com/alibaba/canal">Alibaba Canal</a>
+ */
+public class CanalJsonDeserializationSchema implements DeserializationSchema<RowData> {
+	private static final long serialVersionUID = 1L;
+
+	private static final String OP_INSERT = "INSERT";
+	private static final String OP_UPDATE = "UPDATE";
+	private static final String OP_DELETE = "DELETE";
+
+	/** The deserializer to deserialize Debezium JSON data. */
+	private final JsonRowDataDeserializationSchema jsonDeserializer;
+
+	/** TypeInformation of the produced {@link RowData}. **/
+	private final TypeInformation<RowData> resultTypeInfo;
+
+	/** Flag indicating whether to ignore invalid fields/rows (default: throw an exception). */
+	private final boolean ignoreParseErrors;
+
+	/** Number of fields. */
+	private final int fieldCount;
+
+	public CanalJsonDeserializationSchema(
+			RowType rowType,
+			TypeInformation<RowData> resultTypeInfo,
+			boolean ignoreParseErrors) {
+		this.resultTypeInfo = resultTypeInfo;
+		this.ignoreParseErrors = ignoreParseErrors;
+		this.fieldCount = rowType.getFieldCount();
+		this.jsonDeserializer = new JsonRowDataDeserializationSchema(
+			createJsonRowType(fromLogicalToDataType(rowType)),
+			// the result type is never used, so it's fine to pass in Canal's result type
+			resultTypeInfo,
+			false, // ignoreParseErrors already contains the functionality of failOnMissingField
+			ignoreParseErrors);
+
+	}
+
+	@Override
+	public RowData deserialize(byte[] message) throws IOException {
+		throw new RuntimeException(
+			"Please invoke DeserializationSchema#deserialize(byte[], Collector<RowData>) instead.");
+	}
+
+	@Override
+	public void deserialize(byte[] message, Collector<RowData> out) throws IOException {
+		RowData row = jsonDeserializer.deserialize(message);
+		String type = row.getString(2).toString(); // "type" field
+		if (OP_INSERT.equals(type)) {
+			// "data" field is an array of row, contains inserted rows
+			ArrayData data = row.getArray(0);
+			for (int i = 0; i < data.size(); i++) {
+				RowData insert = data.getRow(i, fieldCount);
+				insert.setRowKind(RowKind.INSERT);
+				out.collect(insert);
+			}
+		} else if (OP_UPDATE.equals(type)) {
+			// "data" field is an array of row, contains new rows
+			ArrayData data = row.getArray(0);
+			// "old" field is an array of row, contains old values
+			ArrayData old = row.getArray(1);
+			for (int i = 0; i < data.size(); i++) {
+				// the underlying JSON deserialization schema always produce GenericRowData.
+				GenericRowData after = (GenericRowData) data.getRow(i, fieldCount);
+				GenericRowData before = (GenericRowData) old.getRow(i, fieldCount);
+				for (int f = 0; f < fieldCount; f++) {
+					if (before.isNullAt(f)) {
+						// not null fields in "old" (before) means the fields are changed
+						// null/empty fields in "old" (before) means the fields not not changed
+						// so we just copy the not changed fields into before
+						before.setField(f, after.getField(f));
+					}
+				}
+				before.setRowKind(RowKind.UPDATE_BEFORE);
+				after.setRowKind(RowKind.UPDATE_AFTER);
+				out.collect(before);
+				out.collect(after);
+			}
+		} else if (OP_DELETE.equals(type)) {
+			// "data" field is an array of row, contains deleted rows
+			ArrayData data = row.getArray(0);
+			for (int i = 0; i < data.size(); i++) {
+				RowData insert = data.getRow(i, fieldCount);
+				insert.setRowKind(RowKind.DELETE);
+				out.collect(insert);
+			}
+		} else {
+			if (!ignoreParseErrors) {
+				throw new IOException(format("Failed to deserialize Canal JSON '%s'.", new String(message)));
+			}

Review comment:
       Give more detailed exception for an intentionally thrown exception.

##########
File path: flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/debezium/DebeziumJsonDeserializationSchema.java
##########
@@ -0,0 +1,176 @@
+/*
+ * 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 org.apache.flink.formats.json.debezium;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.formats.json.JsonRowDataDeserializationSchema;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.Collector;
+
+import java.io.IOException;
+import java.util.Objects;
+
+import static java.lang.String.format;
+import static org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType;
+
+/**
+ * Deserialization schema from Debezium JSON to Flink Table/SQL internal data structure {@link RowData}.
+ * The deserialization schema knows Debezium's schema definition and can extract the database data
+ * and convert into {@link RowData} with {@link RowKind}.
+ *
+ * <p>Deserializes a <code>byte[]</code> message as a JSON object and reads
+ * the specified fields.
+ *
+ * <p>Failures during deserialization are forwarded as wrapped IOExceptions.
+ *
+ * @see <a href="https://debezium.io/">Debezium</a>
+ */
+@Internal
+public final class DebeziumJsonDeserializationSchema implements DeserializationSchema<RowData> {
+	private static final long serialVersionUID = 1L;
+
+	private static final String OP_CREATE = "c";
+	private static final String OP_UPDATE = "u";
+	private static final String OP_DELETE = "d";
+
+	/** The deserializer to deserialize Debezium JSON data. */
+	private final JsonRowDataDeserializationSchema jsonDeserializer;
+
+	/** TypeInformation of the produced {@link RowData}. **/
+	private final TypeInformation<RowData> resultTypeInfo;
+
+	/**
+	 * Flag indicating whether the Debezium JSON data contains schema part or not.
+	 * When Debezium Kafka Connect enables "value.converter.schemas.enable", the JSON
+	 * will contain "schema" information, but we just ignore "schema" and extract data
+	 * from "payload".
+	 */
+	private final boolean schemaInclude;
+
+	/** Flag indicating whether to ignore invalid fields/rows (default: throw an exception). */
+	private final boolean ignoreParseErrors;
+
+	public DebeziumJsonDeserializationSchema(
+			RowType rowType,
+			TypeInformation<RowData> resultTypeInfo,
+			boolean schemaInclude,
+			boolean ignoreParseErrors) {
+		this.resultTypeInfo = resultTypeInfo;
+		this.schemaInclude = schemaInclude;
+		this.ignoreParseErrors = ignoreParseErrors;
+		this.jsonDeserializer = new JsonRowDataDeserializationSchema(
+			createJsonRowType(fromLogicalToDataType(rowType), schemaInclude),
+			// the result type is never used, so it's fine to pass in Debezium's result type
+			resultTypeInfo,
+			false, // ignoreParseErrors already contains the functionality of failOnMissingField
+			ignoreParseErrors);
+	}
+
+	@Override
+	public RowData deserialize(byte[] message) throws IOException {
+		throw new RuntimeException(
+			"Please invoke DeserializationSchema#deserialize(byte[], Collector<RowData>) instead.");
+	}
+
+	@Override
+	public void deserialize(byte[] message, Collector<RowData> out) throws IOException {
+		GenericRowData row = (GenericRowData) jsonDeserializer.deserialize(message);
+		GenericRowData payload;
+		if (schemaInclude) {
+			payload = (GenericRowData) row.getField(0);
+		} else {
+			payload = row;
+		}
+
+		GenericRowData before = (GenericRowData) payload.getField(0);
+		GenericRowData after = (GenericRowData) payload.getField(1);
+		String op = payload.getField(2).toString();
+		if (OP_CREATE.equals(op) && after != null) {
+			after.setRowKind(RowKind.INSERT);
+			out.collect(after);
+		} else if (OP_UPDATE.equals(op) && (before != null && after != null)) {
+			before.setRowKind(RowKind.UPDATE_BEFORE);
+			after.setRowKind(RowKind.UPDATE_AFTER);
+			out.collect(before);
+			out.collect(after);
+		} else if (OP_DELETE.equals(op) && before != null) {
+			before.setRowKind(RowKind.DELETE);
+			out.collect(before);
+		} else {
+			if (!ignoreParseErrors) {
+				throw new IOException(format("Failed to deserialize Debezium JSON '%s'.", new String(message)));
+			}

Review comment:
       Give more detailed message about why the deserialization fails.

##########
File path: flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/debezium/DebeziumFormatFactory.java
##########
@@ -0,0 +1,126 @@
+/*
+ * 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 org.apache.flink.formats.json.debezium;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.serialization.SerializationSchema;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.format.ScanFormat;
+import org.apache.flink.table.connector.format.SinkFormat;
+import org.apache.flink.table.connector.source.ScanTableSource;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.factories.DeserializationFormatFactory;
+import org.apache.flink.table.factories.DynamicTableFactory;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.factories.SerializationFormatFactory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.types.RowKind;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Format factory for providing configured instances of Debezium JSON to RowData {@link DeserializationSchema}.
+ */
+public class DebeziumFormatFactory implements DeserializationFormatFactory, SerializationFormatFactory {
+
+	public static final String IDENTIFIER = "debezium-json";

Review comment:
       `DebeziumJsonFormatFactory ` or maybe we can make the underlying format configurable.

##########
File path: flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/canal/CanalJsonDeserializationSchema.java
##########
@@ -0,0 +1,179 @@
+/*
+ * 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 org.apache.flink.formats.json.canal;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.formats.json.JsonRowDataDeserializationSchema;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.ArrayData;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.Collector;
+
+import java.io.IOException;
+import java.util.Objects;
+
+import static java.lang.String.format;
+import static org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType;
+
+/**
+ * Deserialization schema from Canal JSON to Flink Table/SQL internal data structure {@link RowData}.
+ * The deserialization schema knows Debezium's schema definition and can extract the database data
+ * and convert into {@link RowData} with {@link RowKind}.
+ *
+ * <p>Deserializes a <code>byte[]</code> message as a JSON object and reads
+ * the specified fields.
+ *
+ * <p>Failures during deserialization are forwarded as wrapped IOExceptions.
+ *
+ * @see <a href="https://github.com/alibaba/canal">Alibaba Canal</a>
+ */
+public class CanalJsonDeserializationSchema implements DeserializationSchema<RowData> {
+	private static final long serialVersionUID = 1L;
+
+	private static final String OP_INSERT = "INSERT";
+	private static final String OP_UPDATE = "UPDATE";
+	private static final String OP_DELETE = "DELETE";
+
+	/** The deserializer to deserialize Debezium JSON data. */
+	private final JsonRowDataDeserializationSchema jsonDeserializer;
+
+	/** TypeInformation of the produced {@link RowData}. **/
+	private final TypeInformation<RowData> resultTypeInfo;
+
+	/** Flag indicating whether to ignore invalid fields/rows (default: throw an exception). */
+	private final boolean ignoreParseErrors;
+
+	/** Number of fields. */
+	private final int fieldCount;
+
+	public CanalJsonDeserializationSchema(
+			RowType rowType,
+			TypeInformation<RowData> resultTypeInfo,
+			boolean ignoreParseErrors) {
+		this.resultTypeInfo = resultTypeInfo;
+		this.ignoreParseErrors = ignoreParseErrors;
+		this.fieldCount = rowType.getFieldCount();
+		this.jsonDeserializer = new JsonRowDataDeserializationSchema(
+			createJsonRowType(fromLogicalToDataType(rowType)),
+			// the result type is never used, so it's fine to pass in Canal's result type
+			resultTypeInfo,
+			false, // ignoreParseErrors already contains the functionality of failOnMissingField
+			ignoreParseErrors);
+
+	}
+
+	@Override
+	public RowData deserialize(byte[] message) throws IOException {
+		throw new RuntimeException(
+			"Please invoke DeserializationSchema#deserialize(byte[], Collector<RowData>) instead.");
+	}
+
+	@Override
+	public void deserialize(byte[] message, Collector<RowData> out) throws IOException {
+		RowData row = jsonDeserializer.deserialize(message);
+		String type = row.getString(2).toString(); // "type" field
+		if (OP_INSERT.equals(type)) {
+			// "data" field is an array of row, contains inserted rows

Review comment:
       Replace the if else clause with switch case seems better.

##########
File path: flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/canal/CanalJsonDeserializationSchema.java
##########
@@ -0,0 +1,179 @@
+/*
+ * 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 org.apache.flink.formats.json.canal;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.formats.json.JsonRowDataDeserializationSchema;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.ArrayData;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.Collector;
+
+import java.io.IOException;
+import java.util.Objects;
+
+import static java.lang.String.format;
+import static org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType;
+
+/**
+ * Deserialization schema from Canal JSON to Flink Table/SQL internal data structure {@link RowData}.
+ * The deserialization schema knows Debezium's schema definition and can extract the database data
+ * and convert into {@link RowData} with {@link RowKind}.
+ *
+ * <p>Deserializes a <code>byte[]</code> message as a JSON object and reads
+ * the specified fields.
+ *
+ * <p>Failures during deserialization are forwarded as wrapped IOExceptions.
+ *
+ * @see <a href="https://github.com/alibaba/canal">Alibaba Canal</a>
+ */
+public class CanalJsonDeserializationSchema implements DeserializationSchema<RowData> {
+	private static final long serialVersionUID = 1L;
+
+	private static final String OP_INSERT = "INSERT";
+	private static final String OP_UPDATE = "UPDATE";
+	private static final String OP_DELETE = "DELETE";
+
+	/** The deserializer to deserialize Debezium JSON data. */
+	private final JsonRowDataDeserializationSchema jsonDeserializer;
+
+	/** TypeInformation of the produced {@link RowData}. **/
+	private final TypeInformation<RowData> resultTypeInfo;
+
+	/** Flag indicating whether to ignore invalid fields/rows (default: throw an exception). */
+	private final boolean ignoreParseErrors;
+
+	/** Number of fields. */
+	private final int fieldCount;
+
+	public CanalJsonDeserializationSchema(
+			RowType rowType,
+			TypeInformation<RowData> resultTypeInfo,
+			boolean ignoreParseErrors) {
+		this.resultTypeInfo = resultTypeInfo;
+		this.ignoreParseErrors = ignoreParseErrors;
+		this.fieldCount = rowType.getFieldCount();
+		this.jsonDeserializer = new JsonRowDataDeserializationSchema(
+			createJsonRowType(fromLogicalToDataType(rowType)),
+			// the result type is never used, so it's fine to pass in Canal's result type
+			resultTypeInfo,
+			false, // ignoreParseErrors already contains the functionality of failOnMissingField
+			ignoreParseErrors);
+
+	}
+
+	@Override
+	public RowData deserialize(byte[] message) throws IOException {
+		throw new RuntimeException(
+			"Please invoke DeserializationSchema#deserialize(byte[], Collector<RowData>) instead.");
+	}
+
+	@Override
+	public void deserialize(byte[] message, Collector<RowData> out) throws IOException {
+		RowData row = jsonDeserializer.deserialize(message);
+		String type = row.getString(2).toString(); // "type" field
+		if (OP_INSERT.equals(type)) {
+			// "data" field is an array of row, contains inserted rows
+			ArrayData data = row.getArray(0);
+			for (int i = 0; i < data.size(); i++) {
+				RowData insert = data.getRow(i, fieldCount);
+				insert.setRowKind(RowKind.INSERT);
+				out.collect(insert);
+			}
+		} else if (OP_UPDATE.equals(type)) {
+			// "data" field is an array of row, contains new rows
+			ArrayData data = row.getArray(0);
+			// "old" field is an array of row, contains old values
+			ArrayData old = row.getArray(1);
+			for (int i = 0; i < data.size(); i++) {
+				// the underlying JSON deserialization schema always produce GenericRowData.
+				GenericRowData after = (GenericRowData) data.getRow(i, fieldCount);
+				GenericRowData before = (GenericRowData) old.getRow(i, fieldCount);
+				for (int f = 0; f < fieldCount; f++) {
+					if (before.isNullAt(f)) {
+						// not null fields in "old" (before) means the fields are changed
+						// null/empty fields in "old" (before) means the fields not not changed
+						// so we just copy the not changed fields into before

Review comment:
       `not not changed` => `are not changed`

##########
File path: flink-formats/flink-json/src/test/java/org/apache/flink/formats/json/canal/CanalJsonDeserializationSchemaTest.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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 org.apache.flink.formats.json.canal;
+
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.runtime.typeutils.RowDataTypeInfo;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.util.Collector;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.table.api.DataTypes.FIELD;
+import static org.apache.flink.table.api.DataTypes.FLOAT;
+import static org.apache.flink.table.api.DataTypes.INT;
+import static org.apache.flink.table.api.DataTypes.ROW;
+import static org.apache.flink.table.api.DataTypes.STRING;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for {@link CanalJsonDeserializationSchema}.
+ */
+public class CanalJsonDeserializationSchemaTest {
+
+	@Rule
+	public ExpectedException thrown = ExpectedException.none();
+
+	private static final RowType SCHEMA = (RowType) ROW(
+		FIELD("id", INT().notNull()),
+		FIELD("name", STRING()),
+		FIELD("description", STRING()),
+		FIELD("weight", FLOAT())
+	).getLogicalType();
+
+	@Test
+	public void testDeserialization() throws Exception {
+		List<String> lines = readLines("canal-data.txt");
+		CanalJsonDeserializationSchema deserializationSchema = new CanalJsonDeserializationSchema(
+			SCHEMA,
+			new RowDataTypeInfo(SCHEMA),
+			false);
+
+		SimpleCollector collector = new SimpleCollector();
+		for (String line : lines) {
+			deserializationSchema.deserialize(line.getBytes(StandardCharsets.UTF_8), collector);
+		}
+
+		// Debezium captures change data (`debezium-data-schema-include.txt`) on the `product` table:
+		//

Review comment:
       Canal ?

##########
File path: flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/canal/CanalFormatFactory.java
##########
@@ -0,0 +1,114 @@
+/*
+ * 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 org.apache.flink.formats.json.canal;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.serialization.SerializationSchema;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.format.ScanFormat;
+import org.apache.flink.table.connector.format.SinkFormat;
+import org.apache.flink.table.connector.source.ScanTableSource;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.factories.DeserializationFormatFactory;
+import org.apache.flink.table.factories.DynamicTableFactory;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.factories.SerializationFormatFactory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.types.RowKind;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Format factory for providing configured instances of Canal JSON to RowData {@link DeserializationSchema}.
+ */
+public class CanalFormatFactory implements DeserializationFormatFactory, SerializationFormatFactory {
+
+	public static final String IDENTIFIER = "canal-json";

Review comment:
       `CanalJsonFormatFactory` ? or makes the underlying format configurable because Canal default format is Protobuf




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-628595484


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit 81d1f17f7dad4bed004616df23aa37a0e700b96a (Thu May 14 12:17:34 UTC 2020)
   
   **Warnings:**
    * **2 pom.xml files were touched**: Check for build and licensing issues.
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-628617951


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1299",
       "triggerID" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 81d1f17f7dad4bed004616df23aa37a0e700b96a Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1299) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-628617951


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1299",
       "triggerID" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1349",
       "triggerID" : "4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "aae6bd7bf9952a5baa6b7ced9dd395d834543f77",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1406",
       "triggerID" : "aae6bd7bf9952a5baa6b7ced9dd395d834543f77",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1349) 
   * aae6bd7bf9952a5baa6b7ced9dd395d834543f77 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1406) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] wuchong commented on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
wuchong commented on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-629269766


   Thanks for the reviewing @danny0405 . 
   
   Merging...


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-628617951


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 81d1f17f7dad4bed004616df23aa37a0e700b96a UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-628617951


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1299",
       "triggerID" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1349",
       "triggerID" : "4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "aae6bd7bf9952a5baa6b7ced9dd395d834543f77",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "aae6bd7bf9952a5baa6b7ced9dd395d834543f77",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1349) 
   * aae6bd7bf9952a5baa6b7ced9dd395d834543f77 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] wuchong commented on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
wuchong commented on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-629292739


   The failed kafka case is related to FLINK-16383.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] wuchong commented on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
wuchong commented on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-629116280


   Thanks for the reviewing @danny0405 . PR updated.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] wuchong commented on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
wuchong commented on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-628592513


   cc @danny0405 


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] wuchong commented on a change in pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
wuchong commented on a change in pull request #12152:
URL: https://github.com/apache/flink/pull/12152#discussion_r425656042



##########
File path: flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/canal/CanalJsonDeserializationSchema.java
##########
@@ -0,0 +1,179 @@
+/*
+ * 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 org.apache.flink.formats.json.canal;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.formats.json.JsonRowDataDeserializationSchema;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.ArrayData;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.Collector;
+
+import java.io.IOException;
+import java.util.Objects;
+
+import static java.lang.String.format;
+import static org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType;
+
+/**
+ * Deserialization schema from Canal JSON to Flink Table/SQL internal data structure {@link RowData}.
+ * The deserialization schema knows Debezium's schema definition and can extract the database data
+ * and convert into {@link RowData} with {@link RowKind}.
+ *
+ * <p>Deserializes a <code>byte[]</code> message as a JSON object and reads
+ * the specified fields.
+ *
+ * <p>Failures during deserialization are forwarded as wrapped IOExceptions.
+ *
+ * @see <a href="https://github.com/alibaba/canal">Alibaba Canal</a>
+ */
+public class CanalJsonDeserializationSchema implements DeserializationSchema<RowData> {
+	private static final long serialVersionUID = 1L;
+
+	private static final String OP_INSERT = "INSERT";
+	private static final String OP_UPDATE = "UPDATE";
+	private static final String OP_DELETE = "DELETE";
+
+	/** The deserializer to deserialize Debezium JSON data. */
+	private final JsonRowDataDeserializationSchema jsonDeserializer;
+
+	/** TypeInformation of the produced {@link RowData}. **/
+	private final TypeInformation<RowData> resultTypeInfo;
+
+	/** Flag indicating whether to ignore invalid fields/rows (default: throw an exception). */
+	private final boolean ignoreParseErrors;
+
+	/** Number of fields. */
+	private final int fieldCount;
+
+	public CanalJsonDeserializationSchema(
+			RowType rowType,
+			TypeInformation<RowData> resultTypeInfo,
+			boolean ignoreParseErrors) {
+		this.resultTypeInfo = resultTypeInfo;
+		this.ignoreParseErrors = ignoreParseErrors;
+		this.fieldCount = rowType.getFieldCount();
+		this.jsonDeserializer = new JsonRowDataDeserializationSchema(
+			createJsonRowType(fromLogicalToDataType(rowType)),
+			// the result type is never used, so it's fine to pass in Canal's result type
+			resultTypeInfo,
+			false, // ignoreParseErrors already contains the functionality of failOnMissingField
+			ignoreParseErrors);
+
+	}
+
+	@Override
+	public RowData deserialize(byte[] message) throws IOException {
+		throw new RuntimeException(
+			"Please invoke DeserializationSchema#deserialize(byte[], Collector<RowData>) instead.");
+	}
+
+	@Override
+	public void deserialize(byte[] message, Collector<RowData> out) throws IOException {
+		RowData row = jsonDeserializer.deserialize(message);
+		String type = row.getString(2).toString(); // "type" field
+		if (OP_INSERT.equals(type)) {
+			// "data" field is an array of row, contains inserted rows

Review comment:
       It's not easy to rewrite in switch case, because we can't allocate local variable with the same naem. 

##########
File path: flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/canal/CanalJsonDeserializationSchema.java
##########
@@ -0,0 +1,179 @@
+/*
+ * 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 org.apache.flink.formats.json.canal;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.formats.json.JsonRowDataDeserializationSchema;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.ArrayData;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.Collector;
+
+import java.io.IOException;
+import java.util.Objects;
+
+import static java.lang.String.format;
+import static org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType;
+
+/**
+ * Deserialization schema from Canal JSON to Flink Table/SQL internal data structure {@link RowData}.
+ * The deserialization schema knows Debezium's schema definition and can extract the database data
+ * and convert into {@link RowData} with {@link RowKind}.
+ *
+ * <p>Deserializes a <code>byte[]</code> message as a JSON object and reads
+ * the specified fields.
+ *
+ * <p>Failures during deserialization are forwarded as wrapped IOExceptions.
+ *
+ * @see <a href="https://github.com/alibaba/canal">Alibaba Canal</a>
+ */
+public class CanalJsonDeserializationSchema implements DeserializationSchema<RowData> {
+	private static final long serialVersionUID = 1L;
+
+	private static final String OP_INSERT = "INSERT";
+	private static final String OP_UPDATE = "UPDATE";
+	private static final String OP_DELETE = "DELETE";
+
+	/** The deserializer to deserialize Debezium JSON data. */
+	private final JsonRowDataDeserializationSchema jsonDeserializer;
+
+	/** TypeInformation of the produced {@link RowData}. **/
+	private final TypeInformation<RowData> resultTypeInfo;
+
+	/** Flag indicating whether to ignore invalid fields/rows (default: throw an exception). */
+	private final boolean ignoreParseErrors;
+
+	/** Number of fields. */
+	private final int fieldCount;
+
+	public CanalJsonDeserializationSchema(
+			RowType rowType,
+			TypeInformation<RowData> resultTypeInfo,
+			boolean ignoreParseErrors) {
+		this.resultTypeInfo = resultTypeInfo;
+		this.ignoreParseErrors = ignoreParseErrors;
+		this.fieldCount = rowType.getFieldCount();
+		this.jsonDeserializer = new JsonRowDataDeserializationSchema(
+			createJsonRowType(fromLogicalToDataType(rowType)),
+			// the result type is never used, so it's fine to pass in Canal's result type
+			resultTypeInfo,
+			false, // ignoreParseErrors already contains the functionality of failOnMissingField
+			ignoreParseErrors);
+
+	}
+
+	@Override
+	public RowData deserialize(byte[] message) throws IOException {
+		throw new RuntimeException(
+			"Please invoke DeserializationSchema#deserialize(byte[], Collector<RowData>) instead.");
+	}
+
+	@Override
+	public void deserialize(byte[] message, Collector<RowData> out) throws IOException {
+		RowData row = jsonDeserializer.deserialize(message);
+		String type = row.getString(2).toString(); // "type" field
+		if (OP_INSERT.equals(type)) {
+			// "data" field is an array of row, contains inserted rows

Review comment:
       It's not easy to rewrite in switch case, because we can't allocate local variable with the same name. 




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-628617951


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1299",
       "triggerID" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 81d1f17f7dad4bed004616df23aa37a0e700b96a Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1299) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-628617951


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1299",
       "triggerID" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1349",
       "triggerID" : "4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 81d1f17f7dad4bed004616df23aa37a0e700b96a Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1299) 
   * 4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1349) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-628617951


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1299",
       "triggerID" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1349",
       "triggerID" : "4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1349) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #12152:
URL: https://github.com/apache/flink/pull/12152#issuecomment-628617951


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1299",
       "triggerID" : "81d1f17f7dad4bed004616df23aa37a0e700b96a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 81d1f17f7dad4bed004616df23aa37a0e700b96a Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1299) 
   * 4ddbfe93c3b83b22ffc9f3417983a493cab5e6f3 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] wuchong closed pull request #12152: [FLINK-17149][debezium][canal] Introduce Debezium and Canal changelog format

Posted by GitBox <gi...@apache.org>.
wuchong closed pull request #12152:
URL: https://github.com/apache/flink/pull/12152


   


----------------------------------------------------------------
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:
users@infra.apache.org