yuxiqian commented on code in PR #2968:
URL: https://github.com/apache/flink-cdc/pull/2968#discussion_r1675421946
##########
flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/main/java/org/apache/flink/cdc/connectors/mysql/source/utils/ObjectUtils.java:
##########
@@ -89,6 +95,48 @@ public static int compare(Object obj1, Object obj2) {
}
}
+ /**
+ * Compares two comparable objects. When the compared objects are not
instance of {@link
+ * Comparable} or instace of String, we will compare them in db, ignore
the charset of table
+ * effects the table-split result exmaple: primaryKey:
+ * ['0000','1111','2222','3333','4444','aaaa','bbbb','cccc','ZZZZ']
collate: utf8mb4_general_ci
+ * when chunkSize = 3 we want : split1: ['0000','1111'] split2:
['3333','4444'] split3:
+ * ['aaaa','bbbb'] split3: ['cccc','ZZZZ'] but if we use a table with
+ * COLLATE='utf8mb4_general_ci' and compare them with {@link
ObjectUtils#compare(Object,
+ * Object)}, we whill get: split1: ['0000','1111'] split2: ['3333','4444']
split3:
+ * ['aaaa','bbbb','cccc','ZZZZ'....] the split3 whill contains all of the
remain rows
+ *
+ * @return The value {@code 0} if {@code num1} is equal to the {@code
num2}; a value less than
+ * {@code 0} if the {@code num1} is numerically less than the {@code
num2}; and a value
+ * greater than {@code 0} if the {@code num1} is numerically greater
than the {@code num2}.
+ * @throws ClassCastException if the compared objects are not instance of
{@link Comparable} or
+ * not <i>mutually comparable</i> (for example, strings and integers).
+ */
+ @SuppressWarnings("unchecked")
+ public static int dbCompare(
+ Object obj1,
+ Object obj2,
+ JdbcConnection jdbcConnection,
+ TableId tableId,
+ String splitColumn)
+ throws SQLException {
+ if (Objects.equals(obj1, obj2)) {
+ return 0;
+ }
+ if (obj1 instanceof String && obj2 instanceof String) {
+ // if instance of String, we will compare them in db, to ignore
effects of the charset
+ // and collation of the column
+ String columnCollation =
+ StatementUtils.queryColumnCollation(jdbcConnection,
tableId, splitColumn);
Review Comment:
Got it, this solution looks reasonable.
--
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]