Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INLONG-11233][SDK] Transform SQL supports mid function #11234

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
Loading