diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestTransformStringFunctionsProcessor.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestTransformStringFunctionsProcessor.java deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestRegexpMatchesFunction.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestRegexpMatchesFunction.java new file mode 100644 index 00000000000..fc717857eae --- /dev/null +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestRegexpMatchesFunction.java @@ -0,0 +1,75 @@ +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 TestRegexpMatchesFunction extends AbstractFunctionStringTestBase{ + @Test + public void testRegexpMatchesFunction() throws Exception { + String transformSql1 = "select regexp_matches(string1,string2) from source"; + TransformConfig config1 = new TransformConfig(transformSql1); + TransformProcessor processor1 = TransformProcessor + .create(config1, SourceDecoderFactory.createCsvDecoder(csvSource), + SinkEncoderFactory.createKvEncoder(kvSink)); + // case1: regexp_matches("The quick brown fox", "quick") + List output1 = processor1.transform("The quick brown fox|quick|5|2|1|3", new HashMap<>()); + Assert.assertEquals(1, output1.size()); + Assert.assertEquals(output1.get(0), "result=[{\"quick\"}]"); + String transformSql2 = "select regexp_matches(string1,string2) from source"; + TransformConfig config2 = new TransformConfig(transformSql2); + TransformProcessor processor2 = TransformProcessor + .create(config2, SourceDecoderFactory.createCsvDecoder(csvSource), + SinkEncoderFactory.createKvEncoder(kvSink)); + // case2: regexp_matches("User: Alice, ID: 12345", "User: (\\w+), ID: (\\d+)") + List output2 = + processor2.transform("User: Alice, ID: 12345|User: (\\\\w+), ID: (\\\\d+)|5|2|1|3", new HashMap<>()); + Assert.assertEquals(1, output2.size()); + Assert.assertEquals(output2.get(0), "result=[{\"Alice\",\"12345\"}]"); + // case3: regexp_matches("User: Alice, ID: 12345User: Alice, ID: 12345; + // User: Bob, ID: 67890", "User: (\\w+), ID: (\\d+)") + List output3 = + processor2.transform("User: Alice, ID: 12345|User: (\\\\w+), ID: (\\\\d+)|5|2|1|3", new HashMap<>()); + Assert.assertEquals(1, output3.size()); + Assert.assertEquals(output3.get(0), "result=[{\"Alice\",\"12345\"}]"); + String transformSql3 = "select regexp_matches(string1,string2,string3) from source"; + TransformConfig config3 = new TransformConfig(transformSql3); + TransformProcessor processor3 = TransformProcessor + .create(config3, SourceDecoderFactory.createCsvDecoder(csvSource), + SinkEncoderFactory.createKvEncoder(kvSink)); + // case4: regexp_matches("foo 123 bar 456", "\\d+", "g") + List output4 = processor3.transform("foo 123 bar 456|\\\\d+|g|2|1|3", new HashMap<>()); + Assert.assertEquals(1, output4.size()); + Assert.assertEquals(output4.get(0), "result=[{\"123\"},{\"456\"}]"); + // case5: regexp_matches("User: Alice, ID: 12345User: Alice, ID: 12345; + // User: Bob, ID: 67890", "User: (\\w+),ID: (\\d+)", "g") + List output5 = processor3.transform( + "User: Alice, ID: 12345; User: Bob, ID: 67890|User: (\\\\w+), ID: (\\\\d+)|g|2|1|3", new HashMap<>()); + Assert.assertEquals(1, output5.size()); + Assert.assertEquals(output5.get(0), "result=[{\"Alice\",\"12345\"},{\"Bob\",\"67890\"}]"); + String transformSql4 = "select regexp_matches(string1,string2,string3) from source"; + TransformConfig config4 = new TransformConfig(transformSql4); + TransformProcessor processor4 = TransformProcessor + .create(config4, SourceDecoderFactory.createCsvDecoder(csvSource), + SinkEncoderFactory.createKvEncoder(kvSink)); + // case6: regexp_matches("Hello! hello World", "hello", "ig") + List output6 = processor4.transform("Hello! hello World|hello|ig|2|1|3", new HashMap<>()); + Assert.assertEquals(1, output6.size()); + Assert.assertEquals(output6.get(0), "result=[{\"Hello\"},{\"hello\"}]"); + String transformSql5 = "select regexp_matches(string1,string2,string3) from source"; + TransformConfig config5 = new TransformConfig(transformSql5); + TransformProcessor processor5 = TransformProcessor + .create(config5, SourceDecoderFactory.createCsvDecoder(csvSource), + SinkEncoderFactory.createKvEncoder(kvSink)); + // case7: regexp_matches("First line\nSecond line", "^Second", "m") + List output7 = processor5.transform("First line\\\nSecond line|^Second|m|2|1|3", new HashMap<>()); + Assert.assertEquals(1, output7.size()); + Assert.assertEquals(output7.get(0), "result=[{\"Second\"}]"); + } +}