Skip to content

Commit

Permalink
feat: RegexpFunction add usage of similar(str1, str2)
Browse files Browse the repository at this point in the history
  • Loading branch information
emptyOVO committed Sep 19, 2024
1 parent 88ad3ce commit 79fa76c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
* RegexpFunction
* description: REGEX(string1, string2)--Returns TRUE if any (possibly empty) substring of string1 matches the Java
* regular expression string2, otherwise FALSE. Returns NULL if any of arguments is NULL.
* SIMILAR(string1, string2)--Same as above
*/
@TransformFunction(names = {"regex"})
@TransformFunction(names = {"regex", "similar"})
public class RegexpFunction implements ValueParser {

private ValueParser inputParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,21 @@ public void testRegexFunction() throws Exception {
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=");

String transformSql3 = "select similar(string1, string2) from source";
TransformConfig config3 = new TransformConfig(transformSql3);
TransformProcessor<String, String> processor3 = TransformProcessor
.create(config3, SourceDecoderFactory.createCsvDecoder(csvSource),
SinkEncoderFactory.createKvEncoder(kvSink));

// case4: similar("The quick brown fox", "quick")
List<String> output4 = processor3.transform("The quick brown fox|quick|5|2|1|3", new HashMap<>());
Assert.assertEquals(1, output4.size());
Assert.assertEquals(output4.get(0), "result=true");

// case5: similar("The quick brown fox", "cold")
List<String> output5 = processor3.transform("The quick brown fox|cold|5|2|1|3", new HashMap<>());
Assert.assertEquals(1, output5.size());
Assert.assertEquals(output5.get(0), "result=false");
}
}

0 comments on commit 79fa76c

Please sign in to comment.