You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "zhilinli123 (via GitHub)" <gi...@apache.org> on 2023/03/27 10:55:15 UTC

[GitHub] [incubator-seatunnel] zhilinli123 opened a new pull request, #4428: [Bug] [Writer] hdfs temp folder has not been cleaned up #4321

zhilinli123 opened a new pull request, #4428:
URL: https://github.com/apache/incubator-seatunnel/pull/4428

   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/incubator-seatunnel/issues).
   
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
   
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   
   -->
   
   ## Purpose of this pull request
   
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   ## Check list
   
   * [ ] Code changed are covered with tests, or it does not need tests for reason:
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   * [ ] If you are contributing the connector code, please check that the following files are updated:
     1. Update change log that in connector document. For more details you can refer to [connector-v2](https://github.com/apache/incubator-seatunnel/tree/dev/docs/en/connector-v2)
     2. Update [plugin-mapping.properties](https://github.com/apache/incubator-seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
     3. Update the pom file of [seatunnel-dist](https://github.com/apache/incubator-seatunnel/blob/dev/seatunnel-dist/pom.xml)
   * [ ] Update the [`release-note`](https://github.com/apache/incubator-seatunnel/blob/dev/release-note.md).


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#issuecomment-1811938852

   PTAL: @hailin0 @EricJoy2048 @Hisoka-X 


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on code in PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#discussion_r1399284932


##########
seatunnel-formats/seatunnel-format-json/src/main/java/org/apache/seatunnel/format/json/maxwell/MaxWellJsonDeserializationSchema.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * 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.seatunnel.format.json.maxwell;
+
+import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.JsonNode;
+import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.node.ObjectNode;
+
+import org.apache.seatunnel.api.serialization.DeserializationSchema;
+import org.apache.seatunnel.api.source.Collector;
+import org.apache.seatunnel.api.table.type.RowKind;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
+import org.apache.seatunnel.format.json.JsonDeserializationSchema;
+import org.apache.seatunnel.format.json.exception.SeaTunnelJsonFormatException;
+
+import java.io.IOException;
+import java.util.regex.Pattern;
+
+import static java.lang.String.format;
+
+public class MaxWellJsonDeserializationSchema implements DeserializationSchema<SeaTunnelRow> {
+
+    private static final long serialVersionUID = 1L;
+
+    private static final String FIELD_OLD = "old";
+
+    private static final String FIELD_DATA = "data";
+
+    private static final String FIELD_TYPE = "type";
+
+    private static final String OP_INSERT = "insert";
+
+    private static final String OP_UPDATE = "update";
+
+    private static final String OP_DELETE = "delete";
+
+    private static final String FIELD_DATABASE = "database";
+
+    private static final String FIELD_TABLE = "table";
+
+    private String database;
+
+    private String table;
+
+    /** Names of fields. */
+    private final String[] fieldNames;
+
+    /** Number of fields. */
+    private final int fieldCount;
+
+    private boolean ignoreParseErrors;
+
+    /** Pattern of the specific database. */
+    private final Pattern databasePattern;
+
+    /** Pattern of the specific table. */
+    private final Pattern tablePattern;
+
+    private final JsonDeserializationSchema jsonDeserializer;
+
+    private final SeaTunnelRowType physicalRowType;
+
+    public MaxWellJsonDeserializationSchema(
+            SeaTunnelRowType physicalRowType,
+            String database,
+            String table,
+            boolean ignoreParseErrors) {
+        this.physicalRowType = physicalRowType;
+        final SeaTunnelRowType jsonRowType = createJsonRowType(physicalRowType);
+        this.jsonDeserializer =
+                new JsonDeserializationSchema(false, ignoreParseErrors, jsonRowType);
+        this.database = database;
+        this.table = table;
+        this.fieldNames = physicalRowType.getFieldNames();
+        this.fieldCount = physicalRowType.getTotalFields();
+        this.ignoreParseErrors = ignoreParseErrors;
+        this.databasePattern = database == null ? null : Pattern.compile(database);
+        this.tablePattern = table == null ? null : Pattern.compile(table);
+    }
+
+    @Override
+    public SeaTunnelRow deserialize(byte[] message) throws IOException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public SeaTunnelDataType<SeaTunnelRow> getProducedType() {
+        return this.physicalRowType;
+    }
+
+    @Override
+    public void deserialize(byte[] message, Collector<SeaTunnelRow> out) {
+        if (message == null) {
+            return;
+        }
+        ObjectNode jsonNode = (ObjectNode) convertBytes(message);
+        assert jsonNode != null;

Review Comment:
   From the Flink source code see received null message without any exception thrown, I think this is a format procedure does not throw exceptions will be more friendly
   ![image](https://github.com/apache/seatunnel/assets/76689593/28311d4b-47ee-4bb5-add6-af2ec7214aaa)
   



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#issuecomment-1759422148

   > Please update your repository and merge the dev branch
   
   Done


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on pull request #4428: [Feature][connector][kafka] Support read Maxwell format message from kafka #4415

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4428:
URL: https://github.com/apache/incubator-seatunnel/pull/4428#issuecomment-1495545059

   @TyrantLucifer @TaoZex @Hisoka-X  Please  review thanks


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on code in PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#discussion_r1400663068


##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-kafka-e2e/src/test/resources/maxwellForMatIt/kafkasource_maxwell_cdc_to_pgsql.conf:
##########
@@ -0,0 +1,65 @@
+#
+# 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.
+#
+######
+###### This config file is a demonstration of streaming processing in seatunnel config
+######
+
+env {
+    execution.parallelism = 1
+    job.mode = "BATCH"
+
+    #spark config
+    spark.app.name = "SeaTunnel"
+    spark.executor.instances = 1
+    spark.executor.cores = 1
+    spark.executor.memory = "1g"
+    spark.master = local
+}
+
+source {
+  Kafka {
+    bootstrap.servers = "kafka_e2e:9092"
+    topic = "maxwell-test-cdc_mds"
+    result_table_name = "kafka_name"
+    consumer.group = "maxwell_json_to_pg_consumer"
+    start_mode = earliest
+    schema = {
+      fields {
+           id = "int"
+           name = "string"
+           description = "string"
+           weight = "string"

Review Comment:
   test all datatypes on maxwell format? 
   
   e.g.  float/double/decimal/date/time/timestamp/binary



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "CheneyYin (via GitHub)" <gi...@apache.org>.
CheneyYin commented on code in PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#discussion_r1404201933


##########
seatunnel-formats/seatunnel-format-json/src/main/java/org/apache/seatunnel/format/json/maxwell/MaxWellJsonDeserializationSchema.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * 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.seatunnel.format.json.maxwell;
+
+import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.JsonNode;
+import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.node.ObjectNode;
+
+import org.apache.seatunnel.api.serialization.DeserializationSchema;
+import org.apache.seatunnel.api.source.Collector;
+import org.apache.seatunnel.api.table.type.RowKind;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.common.exception.CommonErrorCodeDeprecated;
+import org.apache.seatunnel.format.json.JsonDeserializationSchema;
+import org.apache.seatunnel.format.json.exception.SeaTunnelJsonFormatException;
+
+import java.io.IOException;
+import java.util.regex.Pattern;
+
+import static java.lang.String.format;
+
+public class MaxWellJsonDeserializationSchema implements DeserializationSchema<SeaTunnelRow> {
+
+    private static final long serialVersionUID = 1L;
+
+    private static final String FIELD_OLD = "old";
+
+    private static final String FIELD_DATA = "data";
+
+    private static final String FIELD_TYPE = "type";
+
+    private static final String OP_INSERT = "insert";
+
+    private static final String OP_UPDATE = "update";
+
+    private static final String OP_DELETE = "delete";
+
+    private static final String FIELD_DATABASE = "database";
+
+    private static final String FIELD_TABLE = "table";
+
+    private String database;
+
+    private String table;
+
+    /** Names of fields. */
+    private final String[] fieldNames;
+
+    /** Number of fields. */
+    private final int fieldCount;
+
+    private boolean ignoreParseErrors;
+
+    /** Pattern of the specific database. */
+    private final Pattern databasePattern;
+
+    /** Pattern of the specific table. */
+    private final Pattern tablePattern;
+
+    private final JsonDeserializationSchema jsonDeserializer;
+
+    private final SeaTunnelRowType physicalRowType;
+
+    public MaxWellJsonDeserializationSchema(
+            SeaTunnelRowType physicalRowType,
+            String database,
+            String table,
+            boolean ignoreParseErrors) {
+        this.physicalRowType = physicalRowType;
+        final SeaTunnelRowType jsonRowType = createJsonRowType(physicalRowType);
+        this.jsonDeserializer =
+                new JsonDeserializationSchema(false, ignoreParseErrors, jsonRowType);
+        this.database = database;
+        this.table = table;
+        this.fieldNames = physicalRowType.getFieldNames();
+        this.fieldCount = physicalRowType.getTotalFields();
+        this.ignoreParseErrors = ignoreParseErrors;
+        this.databasePattern = database == null ? null : Pattern.compile(database);
+        this.tablePattern = table == null ? null : Pattern.compile(table);
+    }
+
+    @Override
+    public SeaTunnelRow deserialize(byte[] message) throws IOException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public SeaTunnelDataType<SeaTunnelRow> getProducedType() {
+        return this.physicalRowType;
+    }
+
+    @Override
+    public void deserialize(byte[] message, Collector<SeaTunnelRow> out) {
+        if (message == null) {
+            return;
+        }
+        ObjectNode jsonNode = (ObjectNode) convertBytes(message);
+        assert jsonNode != null;
+        if (database != null
+                && !databasePattern.matcher(jsonNode.get(FIELD_DATABASE).asText()).matches()) {
+            return;
+        }
+        if (table != null && !tablePattern.matcher(jsonNode.get(FIELD_TABLE).asText()).matches()) {
+            return;
+        }
+        JsonNode dataNode = jsonNode.get(FIELD_DATA);
+        String type = jsonNode.get(FIELD_TYPE).asText();
+        if (OP_INSERT.equals(type)) {
+            SeaTunnelRow rowInsert = convertJsonNode(dataNode);
+            rowInsert.setRowKind(RowKind.INSERT);
+            out.collect(rowInsert);
+        } else if (OP_UPDATE.equals(type)) {
+            SeaTunnelRow rowAfter = convertJsonNode(dataNode);
+            JsonNode oldNode = jsonNode.get(FIELD_OLD);
+            SeaTunnelRow rowBefore = convertJsonNode(oldNode);
+            for (int f = 0; f < fieldCount; f++) {
+                assert rowBefore != null;
+                if (rowBefore.isNullAt(f) && oldNode.findValue(fieldNames[f]) == null) {
+                    // fields in "old" (before) means the fields are changed
+                    // fields not in "old" (before) means the fields are not changed
+                    // so we just copy the not changed fields into before
+                    assert rowAfter != null;
+                    rowBefore.setField(f, rowAfter.getField(f));
+                }
+            }
+            assert rowBefore != null;
+            rowBefore.setRowKind(RowKind.UPDATE_BEFORE);
+            assert rowAfter != null;
+            rowAfter.setRowKind(RowKind.UPDATE_AFTER);
+            out.collect(rowBefore);
+            out.collect(rowAfter);
+        } else if (OP_DELETE.equals(type)) {
+            SeaTunnelRow rowDelete = convertJsonNode(dataNode);
+            rowDelete.setRowKind(RowKind.DELETE);
+            out.collect(rowDelete);
+        } else {
+            if (!ignoreParseErrors) {
+                throw new SeaTunnelJsonFormatException(
+                        CommonErrorCodeDeprecated.UNSUPPORTED_DATA_TYPE,

Review Comment:
   `CommonErrorCodeDeprecated` has been annotated with `@Deprecated`. Please replace it with new `CommonErrorCode`.



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on pull request #4428: [Feature][connector][kafka] Support read Maxwell format message from kafka #4415

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4428:
URL: https://github.com/apache/incubator-seatunnel/pull/4428#issuecomment-1486382172

   > Please add e2e test case, thanks!
   
   Ok, I'll finish it soon
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on pull request #4428: [Feature][connector][kafka] Support read Maxwell format message from kafka #4415

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4428:
URL: https://github.com/apache/incubator-seatunnel/pull/4428#issuecomment-1536009833

   @ic4y  help run ci thanks


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#issuecomment-1765543338

   I will continue to complete it after waiting for ogg format pr merge!
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on pull request #4428: [Feature][connector][kafka] Support read Maxwell format message from kafka #4415

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4428:
URL: https://github.com/apache/incubator-seatunnel/pull/4428#issuecomment-1536259251

   @ic4y  help run ci thanks


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#issuecomment-1759296463

   Please update your repository and merge the dev branch


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#issuecomment-1759294496

   Please check ci errors


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "CheneyYin (via GitHub)" <gi...@apache.org>.
CheneyYin commented on code in PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#discussion_r1404201933


##########
seatunnel-formats/seatunnel-format-json/src/main/java/org/apache/seatunnel/format/json/maxwell/MaxWellJsonDeserializationSchema.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * 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.seatunnel.format.json.maxwell;
+
+import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.JsonNode;
+import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.node.ObjectNode;
+
+import org.apache.seatunnel.api.serialization.DeserializationSchema;
+import org.apache.seatunnel.api.source.Collector;
+import org.apache.seatunnel.api.table.type.RowKind;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.common.exception.CommonErrorCodeDeprecated;
+import org.apache.seatunnel.format.json.JsonDeserializationSchema;
+import org.apache.seatunnel.format.json.exception.SeaTunnelJsonFormatException;
+
+import java.io.IOException;
+import java.util.regex.Pattern;
+
+import static java.lang.String.format;
+
+public class MaxWellJsonDeserializationSchema implements DeserializationSchema<SeaTunnelRow> {
+
+    private static final long serialVersionUID = 1L;
+
+    private static final String FIELD_OLD = "old";
+
+    private static final String FIELD_DATA = "data";
+
+    private static final String FIELD_TYPE = "type";
+
+    private static final String OP_INSERT = "insert";
+
+    private static final String OP_UPDATE = "update";
+
+    private static final String OP_DELETE = "delete";
+
+    private static final String FIELD_DATABASE = "database";
+
+    private static final String FIELD_TABLE = "table";
+
+    private String database;
+
+    private String table;
+
+    /** Names of fields. */
+    private final String[] fieldNames;
+
+    /** Number of fields. */
+    private final int fieldCount;
+
+    private boolean ignoreParseErrors;
+
+    /** Pattern of the specific database. */
+    private final Pattern databasePattern;
+
+    /** Pattern of the specific table. */
+    private final Pattern tablePattern;
+
+    private final JsonDeserializationSchema jsonDeserializer;
+
+    private final SeaTunnelRowType physicalRowType;
+
+    public MaxWellJsonDeserializationSchema(
+            SeaTunnelRowType physicalRowType,
+            String database,
+            String table,
+            boolean ignoreParseErrors) {
+        this.physicalRowType = physicalRowType;
+        final SeaTunnelRowType jsonRowType = createJsonRowType(physicalRowType);
+        this.jsonDeserializer =
+                new JsonDeserializationSchema(false, ignoreParseErrors, jsonRowType);
+        this.database = database;
+        this.table = table;
+        this.fieldNames = physicalRowType.getFieldNames();
+        this.fieldCount = physicalRowType.getTotalFields();
+        this.ignoreParseErrors = ignoreParseErrors;
+        this.databasePattern = database == null ? null : Pattern.compile(database);
+        this.tablePattern = table == null ? null : Pattern.compile(table);
+    }
+
+    @Override
+    public SeaTunnelRow deserialize(byte[] message) throws IOException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public SeaTunnelDataType<SeaTunnelRow> getProducedType() {
+        return this.physicalRowType;
+    }
+
+    @Override
+    public void deserialize(byte[] message, Collector<SeaTunnelRow> out) {
+        if (message == null) {
+            return;
+        }
+        ObjectNode jsonNode = (ObjectNode) convertBytes(message);
+        assert jsonNode != null;
+        if (database != null
+                && !databasePattern.matcher(jsonNode.get(FIELD_DATABASE).asText()).matches()) {
+            return;
+        }
+        if (table != null && !tablePattern.matcher(jsonNode.get(FIELD_TABLE).asText()).matches()) {
+            return;
+        }
+        JsonNode dataNode = jsonNode.get(FIELD_DATA);
+        String type = jsonNode.get(FIELD_TYPE).asText();
+        if (OP_INSERT.equals(type)) {
+            SeaTunnelRow rowInsert = convertJsonNode(dataNode);
+            rowInsert.setRowKind(RowKind.INSERT);
+            out.collect(rowInsert);
+        } else if (OP_UPDATE.equals(type)) {
+            SeaTunnelRow rowAfter = convertJsonNode(dataNode);
+            JsonNode oldNode = jsonNode.get(FIELD_OLD);
+            SeaTunnelRow rowBefore = convertJsonNode(oldNode);
+            for (int f = 0; f < fieldCount; f++) {
+                assert rowBefore != null;
+                if (rowBefore.isNullAt(f) && oldNode.findValue(fieldNames[f]) == null) {
+                    // fields in "old" (before) means the fields are changed
+                    // fields not in "old" (before) means the fields are not changed
+                    // so we just copy the not changed fields into before
+                    assert rowAfter != null;
+                    rowBefore.setField(f, rowAfter.getField(f));
+                }
+            }
+            assert rowBefore != null;
+            rowBefore.setRowKind(RowKind.UPDATE_BEFORE);
+            assert rowAfter != null;
+            rowAfter.setRowKind(RowKind.UPDATE_AFTER);
+            out.collect(rowBefore);
+            out.collect(rowAfter);
+        } else if (OP_DELETE.equals(type)) {
+            SeaTunnelRow rowDelete = convertJsonNode(dataNode);
+            rowDelete.setRowKind(RowKind.DELETE);
+            out.collect(rowDelete);
+        } else {
+            if (!ignoreParseErrors) {
+                throw new SeaTunnelJsonFormatException(
+                        CommonErrorCodeDeprecated.UNSUPPORTED_DATA_TYPE,

Review Comment:
   `CommonErrorCodeDeprecated` has been annotated with `@Deprecated`. Please replace it with `CommonErrorCode`.



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [seatunnel] zhilinli123 commented on pull request #4428: [Feature][connector][kafka] Support read Maxwell format message from kafka #4415

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#issuecomment-1686539130

   ![image](https://github.com/apache/seatunnel/assets/76689593/edc386c2-e66c-43de-ae5c-69ec6da5ac31)
   ci pass @liugddx  run ci thks


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#issuecomment-1797275376

   PTAL: @hailin0 @Hisoka-X thanks


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "CheneyYin (via GitHub)" <gi...@apache.org>.
CheneyYin commented on code in PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#discussion_r1398869916


##########
seatunnel-formats/seatunnel-format-json/src/main/java/org/apache/seatunnel/format/json/maxwell/MaxWellJsonDeserializationSchema.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * 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.seatunnel.format.json.maxwell;
+
+import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.JsonNode;
+import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.node.ObjectNode;
+
+import org.apache.seatunnel.api.serialization.DeserializationSchema;
+import org.apache.seatunnel.api.source.Collector;
+import org.apache.seatunnel.api.table.type.RowKind;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
+import org.apache.seatunnel.format.json.JsonDeserializationSchema;
+import org.apache.seatunnel.format.json.exception.SeaTunnelJsonFormatException;
+
+import java.io.IOException;
+import java.util.regex.Pattern;
+
+import static java.lang.String.format;
+
+public class MaxWellJsonDeserializationSchema implements DeserializationSchema<SeaTunnelRow> {
+
+    private static final long serialVersionUID = 1L;
+
+    private static final String FIELD_OLD = "old";
+
+    private static final String FIELD_DATA = "data";
+
+    private static final String FIELD_TYPE = "type";
+
+    private static final String OP_INSERT = "insert";
+
+    private static final String OP_UPDATE = "update";
+
+    private static final String OP_DELETE = "delete";
+
+    private static final String FIELD_DATABASE = "database";
+
+    private static final String FIELD_TABLE = "table";
+
+    private String database;
+
+    private String table;
+
+    /** Names of fields. */
+    private final String[] fieldNames;
+
+    /** Number of fields. */
+    private final int fieldCount;
+
+    private boolean ignoreParseErrors;
+
+    /** Pattern of the specific database. */
+    private final Pattern databasePattern;
+
+    /** Pattern of the specific table. */
+    private final Pattern tablePattern;
+
+    private final JsonDeserializationSchema jsonDeserializer;
+
+    private final SeaTunnelRowType physicalRowType;
+
+    public MaxWellJsonDeserializationSchema(
+            SeaTunnelRowType physicalRowType,
+            String database,
+            String table,
+            boolean ignoreParseErrors) {
+        this.physicalRowType = physicalRowType;
+        final SeaTunnelRowType jsonRowType = createJsonRowType(physicalRowType);
+        this.jsonDeserializer =
+                new JsonDeserializationSchema(false, ignoreParseErrors, jsonRowType);
+        this.database = database;
+        this.table = table;
+        this.fieldNames = physicalRowType.getFieldNames();
+        this.fieldCount = physicalRowType.getTotalFields();
+        this.ignoreParseErrors = ignoreParseErrors;
+        this.databasePattern = database == null ? null : Pattern.compile(database);
+        this.tablePattern = table == null ? null : Pattern.compile(table);
+    }
+
+    @Override
+    public SeaTunnelRow deserialize(byte[] message) throws IOException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public SeaTunnelDataType<SeaTunnelRow> getProducedType() {
+        return this.physicalRowType;
+    }
+
+    @Override
+    public void deserialize(byte[] message, Collector<SeaTunnelRow> out) {
+        if (message == null) {
+            return;
+        }
+        ObjectNode jsonNode = (ObjectNode) convertBytes(message);
+        assert jsonNode != null;

Review Comment:
   `assert` is turned off by default. I prefer throwing exceptions for non-test code.



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "CheneyYin (via GitHub)" <gi...@apache.org>.
CheneyYin commented on code in PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#discussion_r1399463691


##########
seatunnel-formats/seatunnel-format-json/src/main/java/org/apache/seatunnel/format/json/maxwell/MaxWellJsonDeserializationSchema.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * 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.seatunnel.format.json.maxwell;
+
+import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.JsonNode;
+import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.node.ObjectNode;
+
+import org.apache.seatunnel.api.serialization.DeserializationSchema;
+import org.apache.seatunnel.api.source.Collector;
+import org.apache.seatunnel.api.table.type.RowKind;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
+import org.apache.seatunnel.format.json.JsonDeserializationSchema;
+import org.apache.seatunnel.format.json.exception.SeaTunnelJsonFormatException;
+
+import java.io.IOException;
+import java.util.regex.Pattern;
+
+import static java.lang.String.format;
+
+public class MaxWellJsonDeserializationSchema implements DeserializationSchema<SeaTunnelRow> {
+
+    private static final long serialVersionUID = 1L;
+
+    private static final String FIELD_OLD = "old";
+
+    private static final String FIELD_DATA = "data";
+
+    private static final String FIELD_TYPE = "type";
+
+    private static final String OP_INSERT = "insert";
+
+    private static final String OP_UPDATE = "update";
+
+    private static final String OP_DELETE = "delete";
+
+    private static final String FIELD_DATABASE = "database";
+
+    private static final String FIELD_TABLE = "table";
+
+    private String database;
+
+    private String table;
+
+    /** Names of fields. */
+    private final String[] fieldNames;
+
+    /** Number of fields. */
+    private final int fieldCount;
+
+    private boolean ignoreParseErrors;
+
+    /** Pattern of the specific database. */
+    private final Pattern databasePattern;
+
+    /** Pattern of the specific table. */
+    private final Pattern tablePattern;
+
+    private final JsonDeserializationSchema jsonDeserializer;
+
+    private final SeaTunnelRowType physicalRowType;
+
+    public MaxWellJsonDeserializationSchema(
+            SeaTunnelRowType physicalRowType,
+            String database,
+            String table,
+            boolean ignoreParseErrors) {
+        this.physicalRowType = physicalRowType;
+        final SeaTunnelRowType jsonRowType = createJsonRowType(physicalRowType);
+        this.jsonDeserializer =
+                new JsonDeserializationSchema(false, ignoreParseErrors, jsonRowType);
+        this.database = database;
+        this.table = table;
+        this.fieldNames = physicalRowType.getFieldNames();
+        this.fieldCount = physicalRowType.getTotalFields();
+        this.ignoreParseErrors = ignoreParseErrors;
+        this.databasePattern = database == null ? null : Pattern.compile(database);
+        this.tablePattern = table == null ? null : Pattern.compile(table);
+    }
+
+    @Override
+    public SeaTunnelRow deserialize(byte[] message) throws IOException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public SeaTunnelDataType<SeaTunnelRow> getProducedType() {
+        return this.physicalRowType;
+    }
+
+    @Override
+    public void deserialize(byte[] message, Collector<SeaTunnelRow> out) {
+        if (message == null) {
+            return;
+        }
+        ObjectNode jsonNode = (ObjectNode) convertBytes(message);
+        assert jsonNode != null;

Review Comment:
   ACK



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][connector][kafka] Support read Maxwell format message from kafka #4415 [seatunnel]

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4428:
URL: https://github.com/apache/seatunnel/pull/4428#issuecomment-1820279833

   PTAL: @hailin0  @Hisoka-X  thks
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org