-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52555 from bigo-sg/starts_ends_with_utf8
Add new function startsWithUTF8 and endsWithUTF8
- Loading branch information
Showing
7 changed files
with
203 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <DataTypes/DataTypeString.h> | ||
#include <Functions/FunctionFactory.h> | ||
#include <Functions/FunctionStartsEndsWith.h> | ||
|
||
|
||
namespace DB | ||
{ | ||
|
||
using FunctionEndsWithUTF8 = FunctionStartsEndsWith<NameEndsWithUTF8>; | ||
|
||
REGISTER_FUNCTION(EndsWithUTF8) | ||
{ | ||
factory.registerFunction<FunctionEndsWithUTF8>(FunctionDocumentation{ | ||
.description = R"( | ||
Returns whether string `str` ends with `suffix`, the difference between `endsWithUTF8` and `endsWith` is that `endsWithUTF8` match `str` and `suffix` by UTF-8 characters. | ||
)", | ||
.examples{{"endsWithUTF8", "select endsWithUTF8('富强民主文明和谐', '富强');", ""}}, | ||
.categories{"String"}}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <DataTypes/DataTypeString.h> | ||
#include <Functions/FunctionFactory.h> | ||
#include <Functions/FunctionStartsEndsWith.h> | ||
|
||
|
||
namespace DB | ||
{ | ||
|
||
using FunctionStartsWithUTF8 = FunctionStartsEndsWith<NameStartsWithUTF8>; | ||
|
||
REGISTER_FUNCTION(StartsWithUTF8) | ||
{ | ||
factory.registerFunction<FunctionStartsWithUTF8>(FunctionDocumentation{ | ||
.description = R"( | ||
Returns whether string `str` starts with `prefix`, the difference between `startsWithUTF8` and `startsWith` is that `startsWithUTF8` match `str` and `suffix` by UTF-8 characters. | ||
)", | ||
.examples{{"startsWithUTF8", "select startsWithUTF8('富强民主文明和谐', '富强');", ""}}, | ||
.categories{"String"}}); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
tests/queries/0_stateless/02833_starts_ends_with_utf8.reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-- { echoOn } | ||
select startsWithUTF8('富强民主文明和谐', '富强'); | ||
1 | ||
select startsWithUTF8('富强民主文明和谐', '\xe5'); | ||
0 | ||
select startsWithUTF8('富强民主文明和谐', ''); | ||
1 | ||
SELECT startsWithUTF8('123', '123'); | ||
1 | ||
SELECT startsWithUTF8('123', '12'); | ||
1 | ||
SELECT startsWithUTF8('123', '1234'); | ||
0 | ||
SELECT startsWithUTF8('123', ''); | ||
1 | ||
select endsWithUTF8('富强民主文明和谐', '和谐'); | ||
1 | ||
select endsWithUTF8('富强民主文明和谐', '\x90'); | ||
0 | ||
select endsWithUTF8('富强民主文明和谐', ''); | ||
1 | ||
SELECT endsWithUTF8('123', '3'); | ||
1 | ||
SELECT endsWithUTF8('123', '23'); | ||
1 | ||
SELECT endsWithUTF8('123', '32'); | ||
0 | ||
SELECT endsWithUTF8('123', ''); | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- { echoOn } | ||
select startsWithUTF8('富强民主文明和谐', '富强'); | ||
select startsWithUTF8('富强民主文明和谐', '\xe5'); | ||
select startsWithUTF8('富强民主文明和谐', ''); | ||
|
||
SELECT startsWithUTF8('123', '123'); | ||
SELECT startsWithUTF8('123', '12'); | ||
SELECT startsWithUTF8('123', '1234'); | ||
SELECT startsWithUTF8('123', ''); | ||
|
||
select endsWithUTF8('富强民主文明和谐', '和谐'); | ||
select endsWithUTF8('富强民主文明和谐', '\x90'); | ||
select endsWithUTF8('富强民主文明和谐', ''); | ||
|
||
SELECT endsWithUTF8('123', '3'); | ||
SELECT endsWithUTF8('123', '23'); | ||
SELECT endsWithUTF8('123', '32'); | ||
SELECT endsWithUTF8('123', ''); | ||
-- { echoOff } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters