Skip to content

Commit

Permalink
fix: add function name replicate
Browse files Browse the repository at this point in the history
  • Loading branch information
emptyOVO committed Sep 7, 2024
1 parent 8409765 commit ea4d0aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
/**
* RepeatFunction
* description: repeat(string, numeric)--Repeat the string numeric times and return a new string
* replicate(string, numeric)--Repeat the string numeric times and return a new string
*/
@TransformFunction(names = {"repeat"})
@TransformFunction(names = {"repeat", "replicate"})
public class RepeatFunction implements ValueParser {

private ValueParser stringParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void testRepeatFunction() throws Exception {
TransformProcessor<String, String> processor1 = TransformProcessor
.create(config1, SourceDecoderFactory.createCsvDecoder(csvSource),
SinkEncoderFactory.createKvEncoder(kvSink));
// case1: replicate('apple', 2)
// case1: repeat('apple', 2)
List<String> output1 = processor1.transform("apple|banana|cloud|2|1|3", new HashMap<>());
Assert.assertEquals(1, output1.size());
Assert.assertEquals(output1.get(0), "result=appleapple");
Expand All @@ -46,22 +46,26 @@ public void testRepeatFunction() throws Exception {
TransformProcessor<String, String> processor2 = TransformProcessor
.create(config2, SourceDecoderFactory.createCsvDecoder(csvSource),
SinkEncoderFactory.createKvEncoder(kvSink));
// case2: replicate('banana', 3)
// case2: repeat('banana', 3)
List<String> output2 = processor2.transform("apple|banana|cloud|1|3|3", new HashMap<>());
Assert.assertEquals(1, output2.size());
Assert.assertEquals(output2.get(0), "result=bananabananabanana");
// case3: replicate('banana', 1)
// case3: repeat('banana', 1)
List<String> output3 = processor2.transform("apple|banana|cloud|1|1|3", new HashMap<>());
Assert.assertEquals(1, output2.size());
Assert.assertEquals(output3.get(0), "result=banana");
// case3: replicate('cloud', 0)
String transformSql3 = "select repeat(string3, numeric3) from source";
String transformSql3 = "select replicate(string3, numeric3) from source";
TransformConfig config3 = new TransformConfig(transformSql3);
TransformProcessor<String, String> processor3 = TransformProcessor
.create(config3, SourceDecoderFactory.createCsvDecoder(csvSource),
SinkEncoderFactory.createKvEncoder(kvSink));
List<String> output4 = processor3.transform("apple|banana|cloud|2|1|0", new HashMap<>());
Assert.assertEquals(1, output4.size());
Assert.assertEquals(output4.get(0), "result=");
// case4: replicate('banana', 2)
List<String> output5 = processor2.transform("apple|cloud|banana|1|2|3", new HashMap<>());
Assert.assertEquals(1, output5.size());
Assert.assertEquals(output5.get(0), "result=cloudcloud");
}
}

0 comments on commit ea4d0aa

Please sign in to comment.