From 7845da55c0697e1448b350ea927b3cb0d3a84416 Mon Sep 17 00:00:00 2001 From: Zkplo <87751516+Zkplo@users.noreply.github.com> Date: Thu, 10 Oct 2024 11:04:38 +0800 Subject: [PATCH] [INLONG-11233][SDK] Transform SQL supports mid function (#11234) Co-authored-by: ZKpLo <14148880+zkplo@user.noreply.gitee.com> --- .../process/function/SubstringFunction.java | 2 +- .../string/TestSubstringFunction.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/SubstringFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/SubstringFunction.java index 3504faf624..d9de2d7bf5 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/SubstringFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/SubstringFunction.java @@ -33,7 +33,7 @@ * description: * return a substring of STRING starting from position INT1 with length INT2 (to the end by default) */ -@TransformFunction(names = {"substring", "substr"}) +@TransformFunction(names = {"substring", "substr", "mid"}) public class SubstringFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestSubstringFunction.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestSubstringFunction.java index 7d6c03983b..7cdd4fb49f 100644 --- a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestSubstringFunction.java +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestSubstringFunction.java @@ -93,5 +93,25 @@ public void testSubstringFunction() throws Exception { output = processor.transform(data, new HashMap<>()); Assert.assertEquals(1, output.size()); Assert.assertEquals("result=", output.get(0)); + + String transformSql3 = "select mid(string2, numeric1) from source"; + TransformConfig config3 = new TransformConfig(transformSql3); + TransformProcessor processor3 = TransformProcessor + .create(config3, SourceDecoderFactory.createCsvDecoder(csvSource), + SinkEncoderFactory.createKvEncoder(kvSink)); + // case7: mid('banana', 2) + List output4 = processor3.transform("apple|banana|cloud|2|1|3", new HashMap<>()); + Assert.assertEquals(1, output4.size()); + Assert.assertEquals(output4.get(0), "result=anana"); + + String transformSql4 = "select mid(string1, numeric1, numeric3) from source"; + TransformConfig config4 = new TransformConfig(transformSql4); + TransformProcessor processor4 = TransformProcessor + .create(config4, SourceDecoderFactory.createCsvDecoder(csvSource), + SinkEncoderFactory.createKvEncoder(kvSink)); + // case8: mid('apple', 2, 3) + List output5 = processor4.transform("apple|banana|cloud|2|1|3", new HashMap<>()); + Assert.assertEquals(1, output5.size()); + Assert.assertEquals(output5.get(0), "result=ppl"); } }