From 0dd5d4d185008221b85120dc43fa082fccf9b674 Mon Sep 17 00:00:00 2001 From: Moon <2267016840@qq.com> Date: Fri, 6 Sep 2024 16:44:24 +0800 Subject: [PATCH 1/7] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions --- .../process/function/UrlDecodeFunction.java | 45 ++++++++++++++++ .../process/function/UrlEncodeFunction.java | 53 +++++++++++++++++++ .../string/TestUrlDecodeFunction.java | 38 +++++++++++++ .../string/TestUrlEncodeFunction.java | 38 +++++++++++++ 4 files changed, 174 insertions(+) create mode 100644 inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java create mode 100644 inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java create mode 100644 inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java create mode 100644 inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlEncodeFunction.java diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java new file mode 100644 index 00000000000..6802e0d7280 --- /dev/null +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java @@ -0,0 +1,45 @@ +package org.apache.inlong.sdk.transform.process.function; + +import org.apache.inlong.sdk.transform.decode.SourceData; +import org.apache.inlong.sdk.transform.process.Context; +import org.apache.inlong.sdk.transform.process.operator.OperatorTools; +import org.apache.inlong.sdk.transform.process.parser.ValueParser; + +import net.sf.jsqlparser.expression.Function; + +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; + +/** + * UrlDecodeFunction + * description: Decodes a given string in ‘application/x-www-form-urlencoded’ format using the UTF-8 encoding scheme. + * If the input is NULL, or there is an issue with the decoding process(such as encountering an illegal escape pattern), + * or the encoding scheme is not supported, the function returns NULL. + */ +@TransformFunction(names = {"url_decode"}) +public class UrlDecodeFunction implements ValueParser { + + private final ValueParser stringParser; + + public UrlDecodeFunction(Function expr) { + stringParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); + } + + @Override + public Object parse(SourceData sourceData, int rowIndex, Context context) { + Object stringObj = stringParser.parse(sourceData, rowIndex, context); + if (stringObj == null) { + return null; + } + String string = OperatorTools.parseString(stringObj); + if (string == null) { + return null; + } + + try { + return URLDecoder.decode(string, StandardCharsets.UTF_8.toString()); + } catch (Exception e) { + return null; + } + } +} diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java new file mode 100644 index 00000000000..4dabaee8d4a --- /dev/null +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java @@ -0,0 +1,53 @@ +package org.apache.inlong.sdk.transform.process.function; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import org.apache.inlong.sdk.transform.decode.SourceData; +import org.apache.inlong.sdk.transform.process.Context; +import org.apache.inlong.sdk.transform.process.operator.OperatorTools; +import org.apache.inlong.sdk.transform.process.parser.ValueParser; + +import net.sf.jsqlparser.expression.Function; + +/** + * UrlEncodeFunction + * description: Translates a string into ‘application/x-www-form-urlencoded’ format using the UTF-8 encoding scheme. + * If the input is NULL, or there is an issue with the encoding process, + * or the encoding scheme is not supported, will return NULL. + */ +@TransformFunction(names = {"url_encode"}) +public class UrlEncodeFunction implements ValueParser { + + private final ValueParser stringParser; + + public UrlEncodeFunction(Function expr) { + stringParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); + } + + @Override + public Object parse(SourceData sourceData, int rowIndex, Context context) { + Object stringObj = stringParser.parse(sourceData, rowIndex, context); + if (stringObj == null) { + return null; + } + + String string = OperatorTools.parseString(stringObj); + if (string == null) { + return null; + } + + try { + return URLEncoder.encode(string, StandardCharsets.UTF_8.toString()); + } catch (Exception e) { + return null; + } + } + + public static void main(String[] args) throws UnsupportedEncodingException { + String string = "https://www.google.com/search?q=java url encode"; + String s = "bat apache"; + System.out.println(URLEncoder.encode(string, StandardCharsets.UTF_8.toString())); + System.out.println(URLEncoder.encode(s, StandardCharsets.UTF_8.toString())); + } +} + diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java new file mode 100644 index 00000000000..1bec2fdc48a --- /dev/null +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java @@ -0,0 +1,38 @@ +package org.apache.inlong.sdk.transform.process.function.string; + +import org.apache.inlong.sdk.transform.decode.SourceDecoderFactory; +import org.apache.inlong.sdk.transform.encode.SinkEncoderFactory; +import org.apache.inlong.sdk.transform.pojo.TransformConfig; +import org.apache.inlong.sdk.transform.process.TransformProcessor; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.List; + +public class TestUrlDecodeFunction extends AbstractFunctionStringTestBase { + + @Test + public void testUrlDecodeFunction() throws Exception { + String transformSql = "select url_decode(string1) from source"; + TransformConfig config = new TransformConfig(transformSql); + TransformProcessor processor = TransformProcessor + .create(config, SourceDecoderFactory.createCsvDecoder(csvSource), + SinkEncoderFactory.createKvEncoder(kvSink)); + + // case1: url_decode('https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Djava+url+encode') + List output1 = processor.transform("https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Djava+url+encode|banana|cloud|1", new HashMap<>()); + Assert.assertEquals(1, output1.size()); + Assert.assertEquals(output1.get(0), "result=https://www.google.com/search?q=java url encode"); + + String transformSql2 = "select url_decode(stringX) from source"; + TransformConfig config2 = new TransformConfig(transformSql2); + TransformProcessor processor2 = TransformProcessor + .create(config2, SourceDecoderFactory.createCsvDecoder(csvSource), + SinkEncoderFactory.createKvEncoder(kvSink)); + // case2: url_decode(null) -> null + List output2 = processor2.transform("|apple|banana|cloud|1", new HashMap<>()); + Assert.assertEquals(1, output2.size()); + Assert.assertEquals(output2.get(0), "result=null"); + } +} diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlEncodeFunction.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlEncodeFunction.java new file mode 100644 index 00000000000..236b0975d2d --- /dev/null +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlEncodeFunction.java @@ -0,0 +1,38 @@ +package org.apache.inlong.sdk.transform.process.function.string; + +import org.apache.inlong.sdk.transform.decode.SourceDecoderFactory; +import org.apache.inlong.sdk.transform.encode.SinkEncoderFactory; +import org.apache.inlong.sdk.transform.pojo.TransformConfig; +import org.apache.inlong.sdk.transform.process.TransformProcessor; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.List; + +public class TestUrlEncodeFunction extends AbstractFunctionStringTestBase { + + @Test + public void testUrlEncodeFunction() throws Exception { + String transformSql = "select url_encode(string1) from source"; + TransformConfig config = new TransformConfig(transformSql); + TransformProcessor processor = TransformProcessor + .create(config, SourceDecoderFactory.createCsvDecoder(csvSource), + SinkEncoderFactory.createKvEncoder(kvSink)); + + // case1: url_encode('https://www.google.com/search?q=java url encode') + List output1 = processor.transform("https://www.google.com/search?q=java url encode|banana|cloud|1", new HashMap<>()); + Assert.assertEquals(1, output1.size()); + Assert.assertEquals(output1.get(0), "result=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Djava+url+encode"); + + String transformSql2 = "select url_encode(stringX) from source"; + TransformConfig config2 = new TransformConfig(transformSql2); + TransformProcessor processor2 = TransformProcessor + .create(config2, SourceDecoderFactory.createCsvDecoder(csvSource), + SinkEncoderFactory.createKvEncoder(kvSink)); + // case2: url_encode(null) -> null + List output2 = processor2.transform("apple|banana|cloud|1", new HashMap<>()); + Assert.assertEquals(1, output2.size()); + Assert.assertEquals(output2.get(0), "result=null"); + } +} From ad02a878b6e90122b8108cc59c3bcf93348397b9 Mon Sep 17 00:00:00 2001 From: Moon <2267016840@qq.com> Date: Fri, 6 Sep 2024 17:12:55 +0800 Subject: [PATCH 2/7] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions Add license --- .../process/function/UrlDecodeFunction.java | 17 ++++++++++++ .../process/function/UrlEncodeFunction.java | 26 ++++++++++++++++--- .../string/TestUrlDecodeFunction.java | 21 ++++++++++++++- .../string/TestUrlEncodeFunction.java | 21 ++++++++++++++- 4 files changed, 79 insertions(+), 6 deletions(-) diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java index 6802e0d7280..4c34b06d741 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java @@ -1,3 +1,20 @@ +/* + * 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.inlong.sdk.transform.process.function; import org.apache.inlong.sdk.transform.decode.SourceData; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java index 4dabaee8d4a..82bf080dd8a 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java @@ -1,7 +1,22 @@ +/* + * 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.inlong.sdk.transform.process.function; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; + import org.apache.inlong.sdk.transform.decode.SourceData; import org.apache.inlong.sdk.transform.process.Context; import org.apache.inlong.sdk.transform.process.operator.OperatorTools; @@ -9,6 +24,10 @@ import net.sf.jsqlparser.expression.Function; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + /** * UrlEncodeFunction * description: Translates a string into ‘application/x-www-form-urlencoded’ format using the UTF-8 encoding scheme. @@ -50,4 +69,3 @@ public static void main(String[] args) throws UnsupportedEncodingException { System.out.println(URLEncoder.encode(s, StandardCharsets.UTF_8.toString())); } } - diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java index 1bec2fdc48a..9057f7c2ce1 100644 --- a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java @@ -1,9 +1,27 @@ +/* + * 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.inlong.sdk.transform.process.function.string; import org.apache.inlong.sdk.transform.decode.SourceDecoderFactory; import org.apache.inlong.sdk.transform.encode.SinkEncoderFactory; import org.apache.inlong.sdk.transform.pojo.TransformConfig; import org.apache.inlong.sdk.transform.process.TransformProcessor; + import org.junit.Assert; import org.junit.Test; @@ -21,7 +39,8 @@ public void testUrlDecodeFunction() throws Exception { SinkEncoderFactory.createKvEncoder(kvSink)); // case1: url_decode('https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Djava+url+encode') - List output1 = processor.transform("https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Djava+url+encode|banana|cloud|1", new HashMap<>()); + List output1 = processor.transform( + "https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Djava+url+encode|banana|cloud|1", new HashMap<>()); Assert.assertEquals(1, output1.size()); Assert.assertEquals(output1.get(0), "result=https://www.google.com/search?q=java url encode"); diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlEncodeFunction.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlEncodeFunction.java index 236b0975d2d..712454a315b 100644 --- a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlEncodeFunction.java +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlEncodeFunction.java @@ -1,9 +1,27 @@ +/* + * 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.inlong.sdk.transform.process.function.string; import org.apache.inlong.sdk.transform.decode.SourceDecoderFactory; import org.apache.inlong.sdk.transform.encode.SinkEncoderFactory; import org.apache.inlong.sdk.transform.pojo.TransformConfig; import org.apache.inlong.sdk.transform.process.TransformProcessor; + import org.junit.Assert; import org.junit.Test; @@ -21,7 +39,8 @@ public void testUrlEncodeFunction() throws Exception { SinkEncoderFactory.createKvEncoder(kvSink)); // case1: url_encode('https://www.google.com/search?q=java url encode') - List output1 = processor.transform("https://www.google.com/search?q=java url encode|banana|cloud|1", new HashMap<>()); + List output1 = + processor.transform("https://www.google.com/search?q=java url encode|banana|cloud|1", new HashMap<>()); Assert.assertEquals(1, output1.size()); Assert.assertEquals(output1.get(0), "result=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Djava+url+encode"); From e12b9754a857ced6080a2c0e9ed904599e3e2481 Mon Sep 17 00:00:00 2001 From: MOONSakura0614 <151456101+MOONSakura0614@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:51:53 +0800 Subject: [PATCH 3/7] Transform SQL support UrlEncode & UrlDecode functions delete test code in Function class Co-authored-by: AloysZhang --- .../sdk/transform/process/function/UrlEncodeFunction.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java index 82bf080dd8a..6ff988fcbce 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java @@ -62,10 +62,4 @@ public Object parse(SourceData sourceData, int rowIndex, Context context) { } } - public static void main(String[] args) throws UnsupportedEncodingException { - String string = "https://www.google.com/search?q=java url encode"; - String s = "bat apache"; - System.out.println(URLEncoder.encode(string, StandardCharsets.UTF_8.toString())); - System.out.println(URLEncoder.encode(s, StandardCharsets.UTF_8.toString())); - } } From 7215a47248772c16eb15a3561ee1d72df78ecd12 Mon Sep 17 00:00:00 2001 From: Moon <2267016840@qq.com> Date: Tue, 10 Sep 2024 16:59:26 +0800 Subject: [PATCH 4/7] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit renew:Spotless apply for style check --- .../inlong/sdk/transform/process/function/UrlEncodeFunction.java | 1 - 1 file changed, 1 deletion(-) diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java index 6ff988fcbce..8eefce8b388 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java @@ -24,7 +24,6 @@ import net.sf.jsqlparser.expression.Function; -import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; From 03130829aeb1734d5e7d138a380f2dcda5e91e11 Mon Sep 17 00:00:00 2001 From: MOONSakura0614 <151456101+MOONSakura0614@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:33:16 +0800 Subject: [PATCH 5/7] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions Update TestUrlDecodeFunction.java for return "" if pass null --- .../process/function/string/TestUrlDecodeFunction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java index 9057f7c2ce1..5c3485d8041 100644 --- a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java @@ -52,6 +52,6 @@ public void testUrlDecodeFunction() throws Exception { // case2: url_decode(null) -> null List output2 = processor2.transform("|apple|banana|cloud|1", new HashMap<>()); Assert.assertEquals(1, output2.size()); - Assert.assertEquals(output2.get(0), "result=null"); + Assert.assertEquals(output2.get(0), "result="); } } From 70b29556c8e9fd2b9cc764d22837bde5901f72b5 Mon Sep 17 00:00:00 2001 From: Moon <2267016840@qq.com> Date: Fri, 11 Oct 2024 16:52:31 +0800 Subject: [PATCH 6/7] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions fixed UT null bug --- .../process/function/string/TestUrlDecodeFunction.java | 2 +- .../process/function/string/TestUrlEncodeFunction.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java index 5c3485d8041..c4a7aac3852 100644 --- a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlDecodeFunction.java @@ -49,7 +49,7 @@ public void testUrlDecodeFunction() throws Exception { TransformProcessor processor2 = TransformProcessor .create(config2, SourceDecoderFactory.createCsvDecoder(csvSource), SinkEncoderFactory.createKvEncoder(kvSink)); - // case2: url_decode(null) -> null + // case2: url_decode(null) List output2 = processor2.transform("|apple|banana|cloud|1", new HashMap<>()); Assert.assertEquals(1, output2.size()); Assert.assertEquals(output2.get(0), "result="); diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlEncodeFunction.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlEncodeFunction.java index 712454a315b..8a12800a642 100644 --- a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlEncodeFunction.java +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestUrlEncodeFunction.java @@ -49,9 +49,9 @@ public void testUrlEncodeFunction() throws Exception { TransformProcessor processor2 = TransformProcessor .create(config2, SourceDecoderFactory.createCsvDecoder(csvSource), SinkEncoderFactory.createKvEncoder(kvSink)); - // case2: url_encode(null) -> null + // case2: url_encode(null) List output2 = processor2.transform("apple|banana|cloud|1", new HashMap<>()); Assert.assertEquals(1, output2.size()); - Assert.assertEquals(output2.get(0), "result=null"); + Assert.assertEquals(output2.get(0), "result="); } } From 7873a689f705554158f4829f772e70b740d904da Mon Sep 17 00:00:00 2001 From: Moon <2267016840@qq.com> Date: Fri, 11 Oct 2024 16:52:48 +0800 Subject: [PATCH 7/7] [INLONG-11028][SDK] Transform SQL support UrlEncode & UrlDecode functions --- .../process/function/{ => string}/UrlDecodeFunction.java | 3 ++- .../process/function/{ => string}/UrlEncodeFunction.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) rename inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/{ => string}/UrlDecodeFunction.java (94%) rename inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/{ => string}/UrlEncodeFunction.java (94%) diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlDecodeFunction.java similarity index 94% rename from inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java rename to inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlDecodeFunction.java index 4c34b06d741..d39beedef98 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlDecodeFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlDecodeFunction.java @@ -15,10 +15,11 @@ * limitations under the License. */ -package org.apache.inlong.sdk.transform.process.function; +package org.apache.inlong.sdk.transform.process.function.string; import org.apache.inlong.sdk.transform.decode.SourceData; import org.apache.inlong.sdk.transform.process.Context; +import org.apache.inlong.sdk.transform.process.function.TransformFunction; import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlEncodeFunction.java similarity index 94% rename from inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java rename to inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlEncodeFunction.java index 8eefce8b388..a165129e948 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UrlEncodeFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlEncodeFunction.java @@ -15,10 +15,11 @@ * limitations under the License. */ -package org.apache.inlong.sdk.transform.process.function; +package org.apache.inlong.sdk.transform.process.function.string; import org.apache.inlong.sdk.transform.decode.SourceData; import org.apache.inlong.sdk.transform.process.Context; +import org.apache.inlong.sdk.transform.process.function.TransformFunction; import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser;