-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95d9545
commit 19420de
Showing
5 changed files
with
355 additions
and
26 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
...tor-db2-cdc/src/main/java/com/ververica/cdc/connectors/db2/table/Db2ReadableMetaData.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,122 @@ | ||
/* | ||
* Copyright 2022 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.connectors.db2.table; | ||
|
||
import org.apache.flink.table.api.DataTypes; | ||
import org.apache.flink.table.data.StringData; | ||
import org.apache.flink.table.data.TimestampData; | ||
import org.apache.flink.table.types.DataType; | ||
|
||
import com.ververica.cdc.debezium.table.MetadataConverter; | ||
import io.debezium.connector.AbstractSourceInfo; | ||
import io.debezium.data.Envelope; | ||
import org.apache.kafka.connect.data.Struct; | ||
import org.apache.kafka.connect.source.SourceRecord; | ||
|
||
/** Defines the supported metadata columns for {@link Db2TableSource}. */ | ||
public enum Db2ReadableMetaData { | ||
|
||
/** Name of the table that contain the row. */ | ||
TABLE_NAME( | ||
"table_name", | ||
DataTypes.STRING().notNull(), | ||
new MetadataConverter() { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public Object read(SourceRecord record) { | ||
Struct messageStruct = (Struct) record.value(); | ||
Struct sourceStruct = messageStruct.getStruct(Envelope.FieldName.SOURCE); | ||
return StringData.fromString( | ||
sourceStruct.getString(AbstractSourceInfo.TABLE_NAME_KEY)); | ||
} | ||
}), | ||
/** Name of the schema that contain the row. */ | ||
SCHEMA_NAME( | ||
"schema_name", | ||
DataTypes.STRING().notNull(), | ||
new MetadataConverter() { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public Object read(SourceRecord record) { | ||
Struct messageStruct = (Struct) record.value(); | ||
Struct sourceStruct = messageStruct.getStruct(Envelope.FieldName.SOURCE); | ||
return StringData.fromString( | ||
sourceStruct.getString(AbstractSourceInfo.SCHEMA_NAME_KEY)); | ||
} | ||
}), | ||
|
||
/** Name of the database that contain the row. */ | ||
DATABASE_NAME( | ||
"database_name", | ||
DataTypes.STRING().notNull(), | ||
new MetadataConverter() { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public Object read(SourceRecord record) { | ||
Struct messageStruct = (Struct) record.value(); | ||
Struct sourceStruct = messageStruct.getStruct(Envelope.FieldName.SOURCE); | ||
return StringData.fromString( | ||
sourceStruct.getString(AbstractSourceInfo.DATABASE_NAME_KEY)); | ||
} | ||
}), | ||
|
||
/** | ||
* It indicates the time that the change was made in the database. If the record is read from | ||
* snapshot of the table instead of the change stream, the value is always 0. | ||
*/ | ||
OP_TS( | ||
"op_ts", | ||
DataTypes.TIMESTAMP_LTZ(3).notNull(), | ||
new MetadataConverter() { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public Object read(SourceRecord record) { | ||
Struct messageStruct = (Struct) record.value(); | ||
Struct sourceStruct = messageStruct.getStruct(Envelope.FieldName.SOURCE); | ||
return TimestampData.fromEpochMillis( | ||
(Long) sourceStruct.get(AbstractSourceInfo.TIMESTAMP_KEY)); | ||
} | ||
}); | ||
|
||
private final String key; | ||
|
||
private final DataType dataType; | ||
|
||
private final MetadataConverter converter; | ||
|
||
Db2ReadableMetaData(String key, DataType dataType, MetadataConverter converter) { | ||
this.key = key; | ||
this.dataType = dataType; | ||
this.converter = converter; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public DataType getDataType() { | ||
return dataType; | ||
} | ||
|
||
public MetadataConverter getConverter() { | ||
return converter; | ||
} | ||
} |
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
Oops, something went wrong.