Skip to content

Commit

Permalink
[hotfix-859][core] Fix NPE when NameMapping is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
shitou authored and FlechazoW committed May 23, 2022
1 parent f2eb609 commit 0fda02e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ public DorisSinkFactory(SyncConf syncConf) {
.setLoadProperties(
parameter.getProperties(LOAD_PROPERTIES_KEY, new Properties()))
.setPassword(parameter.getStringVal(PASSWORD_KEY, ""))
.setNameMapped(syncConf.getNameMappingConf() != null)
.setNameMapped(
syncConf.getNameMappingConf() != null
&& !syncConf.getNameMappingConf().isEmpty())
.setWriteMode(
parameter.getStringVal(WRITE_MODE_KEY, DORIS_WRITE_MODE_DEFAULT))
.setUsername(parameter.getStringVal(USER_NAME_KEY))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package com.dtstack.chunjun.mapping;

import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -83,6 +85,14 @@ public void setSqlConevnt(Boolean sqlConevnt) {
this.sqlConevnt = sqlConevnt;
}

public boolean isEmpty() {
return tableMappings.isEmpty()
&& schemaMappings.isEmpty()
&& fieldMappings.isEmpty()
&& StringUtils.isEmpty(pattern)
&& null == sqlConevnt;
}

@Override
public String toString() {
return new StringJoiner(", ", NameMappingConf.class.getSimpleName() + "[", "]")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ public class NameMappingFlatMap extends RichFlatMapFunction<RowData, RowData> {
private final MappingClient client;
private final DdlConvent source;
private final DdlConvent sink;
private final boolean turnOff;
private final ConventExceptionProcessHandler conventExceptionProcessHandler;

public NameMappingFlatMap(
NameMappingConf conf,
DdlConvent source,
DdlConvent sink,
ConventExceptionProcessHandler conventExceptionProcessHandler) {
this.turnOff = conf == null || conf.isEmpty();
this.client = new MappingClient(conf);
this.source = source;
this.sink = sink;
Expand All @@ -59,6 +61,10 @@ public NameMappingFlatMap(

@Override
public void flatMap(RowData value, Collector<RowData> collector) {
if (turnOff) {
collector.collect(value);
return;
}
RowData rowData = client.map(value);
if (rowData instanceof ColumnRowData) {
collector.collect(rowData);
Expand Down

0 comments on commit 0fda02e

Please sign in to comment.