forked from apache/flink-cdc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cdc-connector][mysql] Support metadata 'operation' virtual column fo…
…r MySql Connector. (apache#2913)
- Loading branch information
1 parent
6b6d9fc
commit 8eba910
Showing
6 changed files
with
87 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...debezium/src/main/java/com/ververica/cdc/debezium/table/MetadataWithRowDataConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2023 Ververica Inc. | ||
* | ||
* Licensed 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 com.ververica.cdc.debezium.table; | ||
|
||
import org.apache.flink.table.data.RowData; | ||
|
||
import org.apache.kafka.connect.source.SourceRecord; | ||
|
||
/** | ||
* A converter converts {@link SourceRecord} metadata and {@link RowData} into Flink internal data | ||
* structures. | ||
*/ | ||
public interface MetadataWithRowDataConverter extends MetadataConverter { | ||
Object read(SourceRecord record, RowData rowData); | ||
|
||
default Object read(SourceRecord record) { | ||
throw new UnsupportedOperationException( | ||
"This method should never be called, please call the read(SourceRecord, RowData) method instead."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -933,6 +933,7 @@ public void testMetadataColumns() throws Exception { | |
"CREATE TABLE mysql_users (" | ||
+ " db_name STRING METADATA FROM 'database_name' VIRTUAL," | ||
+ " table_name STRING METADATA VIRTUAL," | ||
+ " op STRING METADATA FROM 'op' VIRTUAL," | ||
+ " `id` DECIMAL(20, 0) NOT NULL," | ||
+ " name STRING," | ||
+ " address STRING," | ||
|
@@ -967,6 +968,7 @@ public void testMetadataColumns() throws Exception { | |
"CREATE TABLE sink (" | ||
+ " database_name STRING," | ||
+ " table_name STRING," | ||
+ " op STRING," | ||
+ " `id` DECIMAL(20, 0) NOT NULL," | ||
+ " name STRING," | ||
+ " address STRING," | ||
|
@@ -1004,15 +1006,15 @@ public void testMetadataColumns() throws Exception { | |
|
||
List<String> expected = | ||
Stream.of( | ||
"+I[%s, user_table_1_1, 111, user_111, Shanghai, 123567891234, [email protected], null]", | ||
"+I[%s, user_table_1_2, 121, user_121, Shanghai, 123567891234, null, null]", | ||
"+I[%s, user_table_1_2, 200, user_200, Wuhan, 123567891234, null, null]", | ||
"+I[%s, user_table_1_1, 300, user_300, Hangzhou, 123567891234, [email protected], null]", | ||
"+U[%s, user_table_1_1, 300, user_300, Beijing, 123567891234, [email protected], null]", | ||
"+U[%s, user_table_1_2, 121, user_121, Shanghai, 88888888, null, null]", | ||
"-D[%s, user_table_1_1, 111, user_111, Shanghai, 123567891234, [email protected], null]", | ||
"-U[%s, user_table_1_1, 300, user_300, Hangzhou, 123567891234, [email protected], null]", | ||
"-U[%s, user_table_1_2, 121, user_121, Shanghai, 123567891234, null, null]") | ||
"+I[%s, user_table_1_1, +I, 111, user_111, Shanghai, 123567891234, [email protected], null]", | ||
"+I[%s, user_table_1_2, +I, 121, user_121, Shanghai, 123567891234, null, null]", | ||
"+I[%s, user_table_1_2, +I, 200, user_200, Wuhan, 123567891234, null, null]", | ||
"+I[%s, user_table_1_1, +I, 300, user_300, Hangzhou, 123567891234, [email protected], null]", | ||
"+U[%s, user_table_1_1, +U, 300, user_300, Beijing, 123567891234, [email protected], null]", | ||
"+U[%s, user_table_1_2, +U, 121, user_121, Shanghai, 88888888, null, null]", | ||
"-D[%s, user_table_1_1, -D, 111, user_111, Shanghai, 123567891234, [email protected], null]", | ||
"-U[%s, user_table_1_1, -U, 300, user_300, Hangzhou, 123567891234, [email protected], null]", | ||
"-U[%s, user_table_1_2, -U, 121, user_121, Shanghai, 123567891234, null, null]") | ||
.map(s -> String.format(s, userDatabase1.getDatabaseName())) | ||
.sorted() | ||
.collect(Collectors.toList()); | ||
|