Skip to content

Commit

Permalink
[INLONG-11233][SDK] Transform SQL supports mid function (#11234)
Browse files Browse the repository at this point in the history
Co-authored-by: ZKpLo <[email protected]>
  • Loading branch information
Zkplo and ZKpLo authored Oct 10, 2024
1 parent 4ba289d commit 7845da5
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 @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> processor3 = TransformProcessor
.create(config3, SourceDecoderFactory.createCsvDecoder(csvSource),
SinkEncoderFactory.createKvEncoder(kvSink));
// case7: 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));
// case8: 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 7845da5

Please sign in to comment.