forked from apache/doris-flink-connector
-
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.
[improve] adjust the code framework related to CDC. (apache#319)
- Loading branch information
1 parent
54c94a9
commit 64fe57a
Showing
12 changed files
with
208 additions
and
76 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...c/main/java/org/apache/doris/flink/sink/writer/serializer/jsondebezium/CdcDataChange.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,40 @@ | ||
// 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.doris.flink.sink.writer.serializer.jsondebezium; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.apache.doris.flink.sink.writer.ChangeEvent; | ||
import org.apache.doris.flink.sink.writer.serializer.DorisRecord; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* When cdc connector captures data changes from the source database you need to inherit this class | ||
* to complete the synchronized data changes to Doris schema. Supports data messages serialized to | ||
* json | ||
*/ | ||
public abstract class CdcDataChange implements ChangeEvent { | ||
|
||
protected abstract DorisRecord serialize(String record, JsonNode recordRoot, String op) | ||
throws IOException; | ||
|
||
protected abstract Map<String, Object> extractBeforeRow(JsonNode record); | ||
|
||
protected abstract Map<String, Object> extractAfterRow(JsonNode record); | ||
} |
39 changes: 39 additions & 0 deletions
39
...main/java/org/apache/doris/flink/sink/writer/serializer/jsondebezium/CdcSchemaChange.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,39 @@ | ||
// 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.doris.flink.sink.writer.serializer.jsondebezium; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.apache.doris.flink.sink.writer.ChangeEvent; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* When cdc connector captures data changes about source database schema changes, you need to | ||
* inherit this class to complete the synchronized changes to Doris schema. Supports data messages | ||
* serialized to json | ||
*/ | ||
public abstract class CdcSchemaChange implements ChangeEvent { | ||
|
||
protected abstract String extractDatabase(JsonNode record); | ||
|
||
protected abstract String extractTable(JsonNode record); | ||
|
||
public abstract boolean schemaChange(JsonNode recordRoot) throws IOException; | ||
|
||
protected abstract String getCdcTableIdentifier(JsonNode record); | ||
} |
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
71 changes: 71 additions & 0 deletions
71
flink-doris-connector/src/main/java/org/apache/doris/flink/tools/cdc/JdbcSourceSchema.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,71 @@ | ||
// 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.doris.flink.tools.cdc; | ||
|
||
import org.apache.doris.flink.catalog.doris.FieldSchema; | ||
|
||
import java.sql.DatabaseMetaData; | ||
import java.sql.ResultSet; | ||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
|
||
/** | ||
* JdbcSourceSchema is a subclass of SourceSchema, used to build metadata about jdbc-related | ||
* databases. | ||
*/ | ||
public abstract class JdbcSourceSchema extends SourceSchema { | ||
|
||
public JdbcSourceSchema( | ||
DatabaseMetaData metaData, | ||
String databaseName, | ||
String schemaName, | ||
String tableName, | ||
String tableComment) | ||
throws Exception { | ||
super(databaseName, schemaName, tableName, tableComment); | ||
fields = new LinkedHashMap<>(); | ||
try (ResultSet rs = metaData.getColumns(databaseName, schemaName, tableName, null)) { | ||
while (rs.next()) { | ||
String fieldName = rs.getString("COLUMN_NAME"); | ||
String comment = rs.getString("REMARKS"); | ||
String fieldType = rs.getString("TYPE_NAME"); | ||
Integer precision = rs.getInt("COLUMN_SIZE"); | ||
|
||
if (rs.wasNull()) { | ||
precision = null; | ||
} | ||
Integer scale = rs.getInt("DECIMAL_DIGITS"); | ||
if (rs.wasNull()) { | ||
scale = null; | ||
} | ||
String dorisTypeStr = convertToDorisType(fieldType, precision, scale); | ||
fields.put(fieldName, new FieldSchema(fieldName, dorisTypeStr, comment)); | ||
} | ||
} | ||
|
||
primaryKeys = new ArrayList<>(); | ||
try (ResultSet rs = metaData.getPrimaryKeys(databaseName, schemaName, tableName)) { | ||
while (rs.next()) { | ||
String fieldName = rs.getString("COLUMN_NAME"); | ||
primaryKeys.add(fieldName); | ||
} | ||
} | ||
} | ||
|
||
public abstract String convertToDorisType(String fieldType, Integer precision, Integer scale); | ||
} |
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.