From 175763e85aea64a9ddc073c7f0d6ad0391f0208d Mon Sep 17 00:00:00 2001 From: vernedeng Date: Tue, 24 Sep 2024 12:04:04 +0800 Subject: [PATCH] [INLONG-11190][SDK] Optimize Transform SDK Translate Function (#11191) --- .../sdk/transform/process/function/TranslateFunction.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TranslateFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TranslateFunction.java index a51cbad7e4b..4953ac9b630 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TranslateFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TranslateFunction.java @@ -48,7 +48,7 @@ * find_chars: A string containing the characters to be replaced. * replace_chars: A string containing the characters to substitute. * examples: - * case1: translate(email, '@', '.') -> original_expression: harry@inlong.com target_expression: harry.inlong.com + * case1: translate(harry@inlong.com, '@', '.') -> original_expression: harry@inlong.com target_expression: harry.inlong.com * case2: translate(hello WorD, 'WD', 'wd') -> original_expression: hello WorD target_expression: hello word */ @TransformFunction(names = {"translate"}) @@ -108,9 +108,7 @@ private Map parseReplacementMap(String findChars, String r return ImmutableMap.of(); } - final int findSize = findChars == null ? 0 : findChars.length(); - final int replaceSize = replaceChars == null ? 0 : replaceChars.length(); - final int commonSize = Math.min(findSize, replaceSize); + final int commonSize = Math.min(findChars.length(), replaceChars.length()); // Create a map to store character replacements Map replacementMap = new HashMap<>(); for (int i = 0; i < commonSize; i++) {