You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/10/13 06:48:09 UTC

[GitHub] [inlong] yunqingmoswu opened a new pull request, #6165: [INLONG-6160][Sort] Support dynamic partition for KafkaLoadNode

yunqingmoswu opened a new pull request, #6165:
URL: https://github.com/apache/inlong/pull/6165

   ### Prepare a Pull Request
   *(Change the title refer to the following example)*
   
   Title: [INLONG-6160][Sort] Support dynamic partition for KafkaLoadNode
   
   *(The following *XYZ* should be replaced by the actual [GitHub Issue](https://github.com/apache/inlong/issues) number)*
   
   Fixes #6160 
   
   ### Motivation
   
   Support dynamic partition for KafkaLoadNode when the format of kafka is raw and the 'key.fields' is not specifyed.
   This is mainly for some whole database migration scenarios, we assume that the upstream input data is a mixed schema of whole database migration, we ignore the real schema for now, receive the entire record in a binary raw data format, and fetch and parse its schema and data on the kafka sink side, and according to Some data values ​​are dynamically written to related topic partitions.
   Dynamic partition writing has some limitations:
   1.The upstream data is raw format with a fixed inner format, only support [canal-json|debezium-json] at now
   2.The 'key.fields' is not specifyed
   3.It needs to specify 'sink.multiple.partition-pattern' and 'sink.multiple.format' for dynamically extracting partition from data
   4.It will extract primary key from raw data as the partition key used hash if the 'sink.multiple.partition-pattern'
    equals 'PRIMARY_KEY' else it will parse partition key from raw data.
   
   ### Modifications
   
   1.Add option of 'sink.multiple.partition-pattern'
   2.Add partitioner of 'RawDataHashPartitioner'
   3.Add method extractValues and extractPrimaryKeyNames and extractPrimaryKeyValues for the mode of 'DynamicSchemaFormat'
   
   ### Verifying this change
   
   *(Please pick either of the following options)*
   
   - [ ] This change is a trivial rework/code cleanup without any test coverage.
   
   - [x] This change is already covered by existing tests, such as:
     *(please describe tests)*
   
   - [ ] This change added tests and can be verified as follows:
   
     *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a follow-up issue for adding the documentation
   


-- 
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@inlong.apache.org

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


[GitHub] [inlong] healchow merged pull request #6165: [INLONG-6160][Sort] Support dynamic partition for KafkaLoadNode

Posted by GitBox <gi...@apache.org>.
healchow merged PR #6165:
URL: https://github.com/apache/inlong/pull/6165


-- 
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@inlong.apache.org

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


[GitHub] [inlong] yunqingmoswu commented on a diff in pull request #6165: [INLONG-6160][Sort] Support dynamic partition for KafkaLoadNode

Posted by GitBox <gi...@apache.org>.
yunqingmoswu commented on code in PR #6165:
URL: https://github.com/apache/inlong/pull/6165#discussion_r997657498


##########
inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/node/load/KafkaLoadNode.java:
##########
@@ -112,14 +119,23 @@ public KafkaLoadNode(@JsonProperty("id") String id,
             @JsonProperty("properties") Map<String, String> properties,
             @JsonProperty("primaryKey") String primaryKey,
             @Nullable @JsonProperty("sinkMultipleFormat") Format sinkMultipleFormat,
-            @Nullable @JsonProperty("topicPattern") String topicPattern) {
+            @Nullable @JsonProperty("topicPattern") String topicPattern,
+            @Nullable @JsonProperty("sinkPartitioner") String sinkPartitioner,
+            @Nullable @JsonProperty("partitionPattern") String partitionPattern) {
         super(id, name, fields, fieldRelations, filters, filterStrategy, sinkParallelism, properties);
         this.topic = Preconditions.checkNotNull(topic, "topic is null");
         this.bootstrapServers = Preconditions.checkNotNull(bootstrapServers, "bootstrapServers is null");
         this.format = Preconditions.checkNotNull(format, "format is null");
         this.primaryKey = primaryKey;
         this.sinkMultipleFormat = sinkMultipleFormat;
         this.topicPattern = topicPattern;
+        this.sinkPartitioner = sinkPartitioner;
+        if ("raw-hash".equals(sinkPartitioner)) {

Review Comment:
   ok



-- 
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@inlong.apache.org

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


[GitHub] [inlong] yunqingmoswu commented on a diff in pull request #6165: [INLONG-6160][Sort] Support dynamic partition for KafkaLoadNode

Posted by GitBox <gi...@apache.org>.
yunqingmoswu commented on code in PR #6165:
URL: https://github.com/apache/inlong/pull/6165#discussion_r997657340


##########
inlong-sort/sort-connectors/kafka/src/main/java/org/apache/inlong/sort/kafka/table/KafkaDynamicTableFactory.java:
##########
@@ -206,6 +216,18 @@ private static void validateSinkPartitioner(ReadableConfig tableOptions) {
                         throw new ValidationException(
                                 "Currently 'round-robin' partitioner only works "
                                         + "when option 'key.fields' is not specified.");
+                    } else if ((SINK_PARTITIONER_VALUE_RAW_HASH.equals(partitioner)
+                            || "org.apache.inlong.sort.kafka.partitioner.RawDataHashPartitioner".equals(partitioner))
+                            && (!"raw".equals(tableOptions.getOptional(FORMAT).orElse(null))
+                            || !tableOptions.getOptional(SINK_MULTIPLE_FORMAT).isPresent()
+                            || !tableOptions.getOptional(SINK_MULTIPLE_PARTITION_PATTERN).isPresent()
+                            || tableOptions.getOptional(SINK_MULTIPLE_FORMAT).get().isEmpty()
+                            || tableOptions.getOptional(SINK_MULTIPLE_PARTITION_PATTERN).get().isEmpty())) {
+                        throw new ValidationException(
+                                "Currently 'raw-hash' partitioner only works "
+                                        + "when option 'format' is 'raw' and option 'sink.multiple.format' "
+                                        + "and 'sink.multiple.partition-pattern' is specified.");

Review Comment:
   ok



-- 
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@inlong.apache.org

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


[GitHub] [inlong] gong commented on a diff in pull request #6165: [INLONG-6160][Sort] Support dynamic partition for KafkaLoadNode

Posted by GitBox <gi...@apache.org>.
gong commented on code in PR #6165:
URL: https://github.com/apache/inlong/pull/6165#discussion_r995717389


##########
inlong-sort/sort-connectors/kafka/src/main/java/org/apache/inlong/sort/kafka/table/KafkaDynamicTableFactory.java:
##########
@@ -206,6 +216,18 @@ private static void validateSinkPartitioner(ReadableConfig tableOptions) {
                         throw new ValidationException(
                                 "Currently 'round-robin' partitioner only works "
                                         + "when option 'key.fields' is not specified.");
+                    } else if ((SINK_PARTITIONER_VALUE_RAW_HASH.equals(partitioner)
+                            || "org.apache.inlong.sort.kafka.partitioner.RawDataHashPartitioner".equals(partitioner))
+                            && (!"raw".equals(tableOptions.getOptional(FORMAT).orElse(null))
+                            || !tableOptions.getOptional(SINK_MULTIPLE_FORMAT).isPresent()
+                            || !tableOptions.getOptional(SINK_MULTIPLE_PARTITION_PATTERN).isPresent()
+                            || tableOptions.getOptional(SINK_MULTIPLE_FORMAT).get().isEmpty()
+                            || tableOptions.getOptional(SINK_MULTIPLE_PARTITION_PATTERN).get().isEmpty())) {
+                        throw new ValidationException(
+                                "Currently 'raw-hash' partitioner only works "
+                                        + "when option 'format' is 'raw' and option 'sink.multiple.format' "
+                                        + "and 'sink.multiple.partition-pattern' is specified.");

Review Comment:
   Maybe, add a bool variable.
   ```java
    boolean notValidRawHashPartitionerConfig = (SINK_PARTITIONER_VALUE_RAW_HASH.equals(partitioner)
                   || "org.apache.inlong.sort.kafka.partitioner.RawDataHashPartitioner".equals(partitioner))
                   && (!"raw".equals(tableOptions.getOptional(FORMAT).orElse(null))
                   || !tableOptions.getOptional(SINK_MULTIPLE_FORMAT).isPresent()
                   || !tableOptions.getOptional(SINK_MULTIPLE_PARTITION_PATTERN).isPresent()
                   || tableOptions.getOptional(SINK_MULTIPLE_FORMAT).get().isEmpty()
                   || tableOptions.getOptional(SINK_MULTIPLE_PARTITION_PATTERN).get().isEmpty());
   ```



-- 
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@inlong.apache.org

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


[GitHub] [inlong] gong commented on a diff in pull request #6165: [INLONG-6160][Sort] Support dynamic partition for KafkaLoadNode

Posted by GitBox <gi...@apache.org>.
gong commented on code in PR #6165:
URL: https://github.com/apache/inlong/pull/6165#discussion_r995688516


##########
inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/node/load/KafkaLoadNode.java:
##########
@@ -157,6 +173,12 @@ public Map<String, String> tableOptions() {
                 if (StringUtils.isNotBlank(topicPattern)) {
                     options.put("topic-pattern", topicPattern);
                 }
+                if (StringUtils.isNotBlank(sinkPartitioner)) {
+                    options.put("sink.partitioner", sinkPartitioner);
+                }
+                if (StringUtils.isNotBlank(partitionPattern)) {
+                    options.put("sink.multiple.partition-pattern", partitionPattern);

Review Comment:
   Maybe, optional option  can be passed by properties object. we don't need change construction method.



-- 
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@inlong.apache.org

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


[GitHub] [inlong] gong commented on a diff in pull request #6165: [INLONG-6160][Sort] Support dynamic partition for KafkaLoadNode

Posted by GitBox <gi...@apache.org>.
gong commented on code in PR #6165:
URL: https://github.com/apache/inlong/pull/6165#discussion_r996451447


##########
inlong-sort/sort-connectors/kafka/src/main/java/org/apache/inlong/sort/kafka/table/KafkaDynamicTableFactory.java:
##########
@@ -206,6 +216,18 @@ private static void validateSinkPartitioner(ReadableConfig tableOptions) {
                         throw new ValidationException(
                                 "Currently 'round-robin' partitioner only works "
                                         + "when option 'key.fields' is not specified.");
+                    } else if ((SINK_PARTITIONER_VALUE_RAW_HASH.equals(partitioner)
+                            || "org.apache.inlong.sort.kafka.partitioner.RawDataHashPartitioner".equals(partitioner))
+                            && (!"raw".equals(tableOptions.getOptional(FORMAT).orElse(null))
+                            || !tableOptions.getOptional(SINK_MULTIPLE_FORMAT).isPresent()
+                            || !tableOptions.getOptional(SINK_MULTIPLE_PARTITION_PATTERN).isPresent()
+                            || tableOptions.getOptional(SINK_MULTIPLE_FORMAT).get().isEmpty()
+                            || tableOptions.getOptional(SINK_MULTIPLE_PARTITION_PATTERN).get().isEmpty())) {
+                        throw new ValidationException(
+                                "Currently 'raw-hash' partitioner only works "
+                                        + "when option 'format' is 'raw' and option 'sink.multiple.format' "
+                                        + "and 'sink.multiple.partition-pattern' is specified.");

Review Comment:
   > 
   
   @yunqingmoswu  Use boolean variables to store results of complicated statements temporarily will increase the code’s readability.[refer to](https://alibaba.github.io/Alibaba-Java-Coding-Guidelines/) 4th item of Flow Control Statements.
   



-- 
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@inlong.apache.org

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


[GitHub] [inlong] yunqingmoswu commented on a diff in pull request #6165: [INLONG-6160][Sort] Support dynamic partition for KafkaLoadNode

Posted by GitBox <gi...@apache.org>.
yunqingmoswu commented on code in PR #6165:
URL: https://github.com/apache/inlong/pull/6165#discussion_r996445059


##########
inlong-sort/sort-connectors/kafka/src/main/java/org/apache/inlong/sort/kafka/table/KafkaDynamicTableFactory.java:
##########
@@ -206,6 +216,18 @@ private static void validateSinkPartitioner(ReadableConfig tableOptions) {
                         throw new ValidationException(
                                 "Currently 'round-robin' partitioner only works "
                                         + "when option 'key.fields' is not specified.");
+                    } else if ((SINK_PARTITIONER_VALUE_RAW_HASH.equals(partitioner)
+                            || "org.apache.inlong.sort.kafka.partitioner.RawDataHashPartitioner".equals(partitioner))
+                            && (!"raw".equals(tableOptions.getOptional(FORMAT).orElse(null))
+                            || !tableOptions.getOptional(SINK_MULTIPLE_FORMAT).isPresent()
+                            || !tableOptions.getOptional(SINK_MULTIPLE_PARTITION_PATTERN).isPresent()
+                            || tableOptions.getOptional(SINK_MULTIPLE_FORMAT).get().isEmpty()
+                            || tableOptions.getOptional(SINK_MULTIPLE_PARTITION_PATTERN).get().isEmpty())) {
+                        throw new ValidationException(
+                                "Currently 'raw-hash' partitioner only works "
+                                        + "when option 'format' is 'raw' and option 'sink.multiple.format' "
+                                        + "and 'sink.multiple.partition-pattern' is specified.");

Review Comment:
   The necessity of adding a variable?



-- 
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@inlong.apache.org

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


[GitHub] [inlong] yunqingmoswu commented on a diff in pull request #6165: [INLONG-6160][Sort] Support dynamic partition for KafkaLoadNode

Posted by GitBox <gi...@apache.org>.
yunqingmoswu commented on code in PR #6165:
URL: https://github.com/apache/inlong/pull/6165#discussion_r996444979


##########
inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/node/load/KafkaLoadNode.java:
##########
@@ -157,6 +173,12 @@ public Map<String, String> tableOptions() {
                 if (StringUtils.isNotBlank(topicPattern)) {
                     options.put("topic-pattern", topicPattern);
                 }
+                if (StringUtils.isNotBlank(sinkPartitioner)) {
+                    options.put("sink.partitioner", sinkPartitioner);
+                }
+                if (StringUtils.isNotBlank(partitionPattern)) {
+                    options.put("sink.multiple.partition-pattern", partitionPattern);

Review Comment:
   Mainly to facilitate api integration calls, and for compatibility, a new constructor has been added.



-- 
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@inlong.apache.org

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


[GitHub] [inlong] thesumery commented on a diff in pull request #6165: [INLONG-6160][Sort] Support dynamic partition for KafkaLoadNode

Posted by GitBox <gi...@apache.org>.
thesumery commented on code in PR #6165:
URL: https://github.com/apache/inlong/pull/6165#discussion_r996557503


##########
inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/node/load/KafkaLoadNode.java:
##########
@@ -112,14 +119,23 @@ public KafkaLoadNode(@JsonProperty("id") String id,
             @JsonProperty("properties") Map<String, String> properties,
             @JsonProperty("primaryKey") String primaryKey,
             @Nullable @JsonProperty("sinkMultipleFormat") Format sinkMultipleFormat,
-            @Nullable @JsonProperty("topicPattern") String topicPattern) {
+            @Nullable @JsonProperty("topicPattern") String topicPattern,
+            @Nullable @JsonProperty("sinkPartitioner") String sinkPartitioner,
+            @Nullable @JsonProperty("partitionPattern") String partitionPattern) {
         super(id, name, fields, fieldRelations, filters, filterStrategy, sinkParallelism, properties);
         this.topic = Preconditions.checkNotNull(topic, "topic is null");
         this.bootstrapServers = Preconditions.checkNotNull(bootstrapServers, "bootstrapServers is null");
         this.format = Preconditions.checkNotNull(format, "format is null");
         this.primaryKey = primaryKey;
         this.sinkMultipleFormat = sinkMultipleFormat;
         this.topicPattern = topicPattern;
+        this.sinkPartitioner = sinkPartitioner;
+        if ("raw-hash".equals(sinkPartitioner)) {

Review Comment:
   extract a constant



-- 
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@inlong.apache.org

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


[GitHub] [inlong] healchow commented on a diff in pull request #6165: [INLONG-6160][Sort] Support dynamic partition for KafkaLoadNode

Posted by GitBox <gi...@apache.org>.
healchow commented on code in PR #6165:
URL: https://github.com/apache/inlong/pull/6165#discussion_r997683390


##########
inlong-sort/sort-connectors/base/src/main/java/org/apache/inlong/sort/base/format/CanalJsonDynamicSchemaFormat.java:
##########
@@ -46,6 +49,18 @@ protected JsonNode getPhysicalData(JsonNode root) {
         return null;
     }
 
+    @Override
+    public List<String> extractPrimaryKeyNames(JsonNode data) {
+        JsonNode pkNamesNode = data.get("pkNames");

Review Comment:
   Suggest extracting a constant String for `pkNames`.



##########
inlong-sort/sort-connectors/base/src/main/java/org/apache/inlong/sort/base/format/DebeziumJsonDynamicSchemaFormat.java:
##########
@@ -46,6 +49,22 @@ protected JsonNode getPhysicalData(JsonNode root) {
         return physicalData;
     }
 
+    @Override
+    public List<String> extractPrimaryKeyNames(JsonNode data) {
+        List<String> pkNames = new ArrayList<>();
+        JsonNode sourceNode = data.get("source");

Review Comment:
   Suggest extracting a constant String for `source`.



-- 
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@inlong.apache.org

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