Skip to content
Open
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 @@ -1813,14 +1813,16 @@ private Stream<TestSetSpec> splitTestCases() {
",123,123,",
123,
"12345",
",123,,,123,")
",123,,,123,",
"123😊笑脸")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just harden the test with two SMP chars?

Suggested change
"123😊笑脸")
"123😊👍🏽笑脸")

.andDataTypes(
DataTypes.STRING().notNull(),
DataTypes.STRING(),
DataTypes.STRING().notNull(),
DataTypes.STRING().notNull(),
DataTypes.INT().notNull(),
DataTypes.STRING().notNull(),
DataTypes.STRING().notNull(),
DataTypes.STRING().notNull())
.testResult(
$("f0").split(","),
Expand Down Expand Up @@ -1867,6 +1869,11 @@ private Stream<TestSetSpec> splitTestCases() {
"SPLIT(f6, ',')",
new String[] {"", "123", "", "", "123", ""},
DataTypes.ARRAY(DataTypes.STRING()).notNull())
.testResult(
$("f7").split(""),
"SPLIT(f7, '')",
new String[] {"1", "2", "3", "😊", "笑", "脸"},
DataTypes.ARRAY(DataTypes.STRING()).notNull())
.testTableApiValidationError(
$("f4").split(","),
"Invalid input arguments. Expected signatures are:\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ public SplitFunction(SpecializedFunction.SpecializedContext context) {
if (delimiter.toString().isEmpty()) {
String str = string.toString();
List<StringData> res = new ArrayList<>();
for (int i = 0; i < str.length(); i++) {
res.add(StringData.fromString(String.valueOf(str.charAt(i))));
int i = 0;
while (i < str.length()) {
int codePoint = str.codePointAt(i);
int charCount = Character.charCount(codePoint);
res.add(StringData.fromString(str.substring(i, i + charCount)));
i += charCount;
}
Comment on lines +53 to 58
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this reads better

Suggested change
while (i < str.length()) {
int codePoint = str.codePointAt(i);
int charCount = Character.charCount(codePoint);
res.add(StringData.fromString(str.substring(i, i + charCount)));
i += charCount;
}
while (i < str.length()) {
int codePoint = str.codePointAt(i);
int nextIndex = i + Character.charCount(codePoint);
res.add(StringData.fromString(str.substring(i, nextIndex)));
i = nextIndex;
}

return new GenericArrayData(res.toArray());
}
Expand Down