Skip to content

Commit

Permalink
[INLONG-11233][SDK] Transform SQL supports mid function
Browse files Browse the repository at this point in the history
  • Loading branch information
ZKpLo committed Sep 28, 2024
1 parent e0d7f8d commit d2ed1b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* description: substring(string FROM INT1 [ FOR INT2 ])--returns 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,25 @@ public void testSubstringFunction() throws Exception {
List<String> output3 = processor2.transform("apple|banana|cloud|2|1|9", new HashMap<>());
Assert.assertEquals(1, output3.size());
Assert.assertEquals(output3.get(0), "result=pple");

String transformSql3 = "select mid(string2, numeric1) from source";
TransformConfig config3 = new TransformConfig(transformSql3);
TransformProcessor<String, String> processor3 = TransformProcessor
.create(config3, SourceDecoderFactory.createCsvDecoder(csvSource),
SinkEncoderFactory.createKvEncoder(kvSink));
// case4: mid('banana', 2)
List<String> 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<String, String> processor4 = TransformProcessor
.create(config4, SourceDecoderFactory.createCsvDecoder(csvSource),
SinkEncoderFactory.createKvEncoder(kvSink));
// case4: mid('apple', 2, 3)
List<String> output5 = processor4.transform("apple|banana|cloud|2|1|3", new HashMap<>());
Assert.assertEquals(1, output5.size());
Assert.assertEquals(output5.get(0), "result=ppl");
}
}

0 comments on commit d2ed1b9

Please sign in to comment.