cshuo commented on code in PR #4164:
URL: https://github.com/apache/flink-cdc/pull/4164#discussion_r2472938618


##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-hudi/src/main/java/org/apache/flink/cdc/connectors/hudi/sink/v2/HudiSink.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.cdc.connectors.hudi.sink.v2;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.connector.sink2.Sink;
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.api.connector.sink2.WriterInitContext;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.cdc.common.event.Event;
+import org.apache.flink.cdc.connectors.hudi.sink.bucket.BucketAssignOperator;
+import org.apache.flink.cdc.connectors.hudi.sink.bucket.BucketWrapper;
+import 
org.apache.flink.cdc.connectors.hudi.sink.bucket.FlushEventAlignmentOperator;
+import 
org.apache.flink.cdc.connectors.hudi.sink.operator.MultiTableWriteOperator;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.connector.sink2.WithPreWriteTopology;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.util.Collector;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.time.ZoneId;
+
+/** A {@link Sink} implementation for Apache Hudi. */
+public class HudiSink implements Sink<Event>, WithPreWriteTopology<Event> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(HudiSink.class);
+
+    private final Configuration conf;
+
+    private final String schemaOperatorUid;
+
+    public HudiSink(Configuration conf, String schemaOperatorUid, ZoneId 
zoneId) {
+        LOG.info("Creating Hoodie sink with conf: {}", conf);
+        this.conf = conf;
+        this.schemaOperatorUid = schemaOperatorUid;
+    }
+
+    @Override
+    public SinkWriter<Event> createWriter(InitContext context) throws 
IOException {
+        return DummySinkWriter.INSTANCE;
+    }
+
+    @Override
+    public SinkWriter<Event> createWriter(WriterInitContext context) throws 
IOException {
+        return DummySinkWriter.INSTANCE;
+    }
+
+    @Override
+    public DataStream<Event> addPreWriteTopology(DataStream<Event> dataStream) 
{
+        LOG.info("Building Hudi pre-write topology with bucket assignment and 
partitioning");
+
+        // Step 1: Bucket assignment operator
+        // - Calculates bucket for DataChangeEvents
+        // - Broadcasts schema events to all tasks
+        // - Wraps events in BucketWrapper for downstream partitioning
+        DataStream<BucketWrapper> bucketAssignedStream =
+                dataStream
+                        .transform(
+                                "bucket_assign",
+                                TypeInformation.of(BucketWrapper.class),
+                                new BucketAssignOperator(conf, 
schemaOperatorUid))
+                        .uid("bucket_assign");
+
+        // Step 2: Partition by bucket index
+        // - Routes events to tasks based on bucket index
+        // - Schema events are broadcast (sent to all bucket indices)
+        // - Data events go to their specific bucket's task
+        DataStream<BucketWrapper> partitionedStream =
+                bucketAssignedStream.partitionCustom(
+                        (key, numPartitions) -> key % numPartitions,

Review Comment:
   Maybe we should also consider data skew problem since there are records from 
multiple table & partitions. You can refer to 
BucketIndexUtil#getPartitionIndexFunc.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to