nsivabalan commented on code in PR #19110:
URL: https://github.com/apache/hudi/pull/19110#discussion_r3670043774


##########
hudi-utilities/src/main/java/org/apache/hudi/utilities/transform/debezium/MysqlDebeziumTransformer.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.hudi.utilities.transform.debezium;
+
+import org.apache.hudi.common.model.debezium.DebeziumConstants;
+import org.apache.hudi.common.util.Option;
+
+import org.apache.spark.sql.Column;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.functions;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * {@link AbstractDebeziumTransformer} for MySQL Debezium change events.
+ *
+ * <p>Surfaces the MySQL binlog coordinates ({@code file}, {@code pos}, {@code 
row}) as the flattened
+ * {@code _event_bin_file}, {@code _event_pos} and {@code _event_row} columns, 
and derives the
+ * {@code _event_seq} ordering column as {@code "<binlog-file-suffix>.<pos>"} 
(e.g. {@code "000001.100"}
+ * for a binlog file {@code "mysql-bin.000001"} at position {@code 100}). 
{@code _event_seq} is the
+ * precombine/ordering field consumed by {@code MySqlDebeziumAvroPayload}.
+ *
+ * <p>Metadata is flattened to the root level by default; set
+ * {@code hoodie.streamer.transformer.debezium.nested.fields.enable=true} to 
group it under a
+ * {@code _debezium_metadata} struct instead.
+ */
+public class MysqlDebeziumTransformer extends AbstractDebeziumTransformer {
+
+  // Nestable MySQL metadata (grouped under _debezium_metadata when nesting is 
enabled).
+  private static final List<Column> MYSQL_METADATA = Arrays.asList(
+      new 
Column(DebeziumConstants.INCOMING_SOURCE_ROW_FIELD).alias(DebeziumConstants.FLATTENED_ROW_COL_NAME));
+
+  // The binlog coordinates are the payload's ordering fields, so they are 
kept at the root level in
+  // every layout (flat or nested), matching how the Postgres transformer 
keeps the LSN at the root.
+  private static final List<Column> MYSQL_ORDERING_COLUMNS = Arrays.asList(
+      new 
Column(DebeziumConstants.INCOMING_SOURCE_FILE_FIELD).alias(DebeziumConstants.FLATTENED_FILE_COL_NAME),
+      new 
Column(DebeziumConstants.INCOMING_SOURCE_POS_FIELD).alias(DebeziumConstants.FLATTENED_POS_COL_NAME));
+
+  public MysqlDebeziumTransformer() {
+    super(MYSQL_METADATA, MYSQL_ORDERING_COLUMNS, 
Option.of(MysqlDebeziumTransformer::applySeqNo));
+  }
+
+  /**
+   * Builds the {@code _event_seq} ordering column from the binlog file and 
position. The file column
+   * holds a name like {@code "mysql-bin.000001"}; only the numeric suffix 
after the last dot is used,
+   * yielding a sequence such as {@code "000001.100"}. The binlog file and 
position are kept at the root
+   * level in both the flat and nested layouts, so they are read directly.
+   *
+   * @param dataset flattened MySQL Debezium dataset.
+   * @return dataset with the {@code _event_seq} column added.
+   */
+  private static Dataset<Row> applySeqNo(Dataset<Row> dataset) {
+    return dataset.withColumn(DebeziumConstants.ADDED_SEQ_COL_NAME, 
functions.concat(
+        
functions.substring_index(dataset.col(DebeziumConstants.FLATTENED_FILE_COL_NAME),
 ".", -1),
+        functions.lit("."),
+        dataset.col(DebeziumConstants.FLATTENED_POS_COL_NAME)));

Review Comment:
   One clarification that I think explains our disagreement on "pre-existing" — 
and sharpens why I'd still like this addressed.
   
   I suspect the version this was ported from also had no guard here, in which 
case your "pre-existing" read is entirely reasonable *from that vantage point*. 
But those are two different claims:
   
   1. "unchanged relative to the code this was ported from" — likely true
   2. "no regression in OSS" — not true, because the validation exists **only** 
in OSS, in `MysqlDebeziumSource.generateUniqueSequence`, and this transformer 
is what OSS users would adopt instead of that source
   
   So upstreaming a variant that never had the guard into a codebase that does 
have it is a net loss of validation for OSS users, even though the diff 
faithfully reflects its origin. That's the regression I'm pointing at — not 
authorship.
   
   The consequence I'd weigh most is still the second bullet in my original 
comment: a null `_event_seq` on the *stored* record lands in the `// handle 
bootstrap case` branch of `shouldPickCurrentRecord` and returns `false`, so 
ordering is silently skipped rather than failing. That's the one that seems 
worth not carrying forward.
   
   Happy for this to be a follow-up if you'd rather keep the PR tight — just 
would like it tracked rather than closed as not-applicable.



-- 
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