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.
[fix]Fix multi-table sink, schema change result is incorrect (apache#313
- Loading branch information
1 parent
0566b92
commit 99f2da9
Showing
9 changed files
with
284 additions
and
109 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
65 changes: 65 additions & 0 deletions
65
...a/org/apache/doris/flink/sink/writer/serializer/jsondebezium/JsonDebeziumChangeUtils.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,65 @@ | ||
// 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 org.apache.flink.util.CollectionUtil; | ||
import org.apache.flink.util.StringUtils; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.NullNode; | ||
import org.apache.doris.flink.cfg.DorisOptions; | ||
import org.apache.doris.flink.tools.cdc.SourceSchema; | ||
|
||
import java.util.Map; | ||
|
||
public class JsonDebeziumChangeUtils { | ||
|
||
public static String getDorisTableIdentifier( | ||
JsonNode record, DorisOptions dorisOptions, Map<String, String> tableMapping) { | ||
String identifier = getCdcTableIdentifier(record); | ||
return getDorisTableIdentifier(identifier, dorisOptions, tableMapping); | ||
} | ||
|
||
public static String getDorisTableIdentifier( | ||
String cdcTableIdentifier, | ||
DorisOptions dorisOptions, | ||
Map<String, String> tableMapping) { | ||
if (!StringUtils.isNullOrWhitespaceOnly(dorisOptions.getTableIdentifier())) { | ||
return dorisOptions.getTableIdentifier(); | ||
} | ||
if (!CollectionUtil.isNullOrEmpty(tableMapping) | ||
&& !StringUtils.isNullOrWhitespaceOnly(cdcTableIdentifier) | ||
&& tableMapping.get(cdcTableIdentifier) != null) { | ||
return tableMapping.get(cdcTableIdentifier); | ||
} | ||
return null; | ||
} | ||
|
||
public static String getCdcTableIdentifier(JsonNode record) { | ||
String db = extractJsonNode(record.get("source"), "db"); | ||
String schema = extractJsonNode(record.get("source"), "schema"); | ||
String table = extractJsonNode(record.get("source"), "table"); | ||
return SourceSchema.getString(db, schema, table); | ||
} | ||
|
||
public static String extractJsonNode(JsonNode record, String key) { | ||
return record != null && record.get(key) != null && !(record.get(key) instanceof NullNode) | ||
? record.get(key).asText() | ||
: null; | ||
} | ||
} |
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
Oops, something went wrong.