Skip to content

Commit 39ef0c1

Browse files
fix TranslateProcessorConfig to load target.type property correct (Fix#5961) (#5969)
**What?** This commit update TranslateProcessorConfig to load the target.type property from pipeline config with Jackson's support. The cause is that converter parameter is not updated while Jackson parsing the target.type properly. The fix removes the unncessary private field converter and instead return targetType. It also make secondar contstructor protected for unit test only. **Why?** Make target.type property in translate processor to take effect. Signed-off-by: Wenjie Yao <wjyao@amazon.com> Co-authored-by: Wenjie Yao <wjyao@amazon.com>
1 parent 986a246 commit 39ef0c1

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

data-prepper-plugins/translate-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/translate/TargetsParameterConfig.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.opensearch.dataprepper.model.annotations.AlsoRequired;
1010
import org.opensearch.dataprepper.plugins.processor.mutateevent.TargetType;
1111
import org.opensearch.dataprepper.typeconverter.TypeConverter;
12+
import com.google.common.annotations.VisibleForTesting;
1213

1314
import java.util.HashMap;
1415
import java.util.LinkedHashMap;
@@ -21,7 +22,6 @@
2122
public class TargetsParameterConfig {
2223
static final String MAP_KEY = "map";
2324
static final String REGEX_KEY = "regex";
24-
private final TypeConverter converter;
2525
private final LinkedHashMap<Range<Float>, Object> rangeMappings = new LinkedHashMap<>();
2626
private final Map<String, Object> individualMappings = new HashMap<>();
2727
private final Map<Pattern, Object> compiledPatterns = new HashMap<>();
@@ -57,18 +57,17 @@ public class TargetsParameterConfig {
5757
@JsonPropertyDescription("Specifies the data type for the target value.")
5858
private TargetType targetType = TargetType.STRING;
5959

60-
public TargetsParameterConfig(){
61-
converter = TargetType.STRING.getTargetConverter();
62-
}
63-
public TargetsParameterConfig(Map<String, Object> map, String target, RegexParameterConfiguration regexParameterConfig, String translateWhen, String defaultValue, TargetType targetType) {
60+
public TargetsParameterConfig(){}
61+
62+
@VisibleForTesting
63+
TargetsParameterConfig(Map<String, Object> map, String target, RegexParameterConfiguration regexParameterConfig, String translateWhen, String defaultValue, TargetType targetType) {
6464
this.targetType = Optional
6565
.ofNullable(targetType)
6666
.orElse(TargetType.STRING);
6767
this.target = target;
6868
this.map = map;
6969
this.defaultValue = defaultValue;
7070
this.regexParameterConfig = regexParameterConfig;
71-
this.converter = this.targetType.getTargetConverter();
7271
this.translateWhen = translateWhen;
7372
parseMappings();
7473
}
@@ -109,11 +108,6 @@ public Map<Pattern, Object> fetchCompiledPatterns() {
109108
return compiledPatterns;
110109
}
111110

112-
public TypeConverter getConverter() {
113-
return converter;
114-
}
115-
116-
117111
@AssertTrue(message = "pattern option is mandatory while configuring regex option")
118112
public boolean isPatternPresent() {
119113
return regexParameterConfig == null || regexParameterConfig.getPatterns() != null;

data-prepper-plugins/translate-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/translate/TranslateProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private String getSourceValue(Object recordObject, String sourceKey) {
134134
}
135135

136136
private Object getTargetValue(Object sourceObject, List<Object> targetValues, TargetsParameterConfig targetConfig) {
137-
TypeConverter converter = targetConfig.getConverter();
137+
TypeConverter converter = targetConfig.getTargetType().getTargetConverter();
138138
if(sourceObject instanceof String) {
139139
return converter.convert(targetValues.get(0));
140140
}

0 commit comments

Comments
 (0)