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

Added some built-in functions for string operations #841

Merged
merged 3 commits into from Sep 2, 2019

Conversation

@darionyaphet
Copy link
Contributor

commented Aug 23, 2019

No description provided.

auto value = Expression::asString(args[0]);
auto start = Expression::asInt(args[1]);
auto length = Expression::asInt(args[2]);
return value.substr(start, length);

This comment has been minimized.

Copy link
@critical27

critical27 Aug 26, 2019

Contributor

Maybe need to handle exception if start > value.size()

This comment has been minimized.

Copy link
@darionyaphet

darionyaphet Aug 26, 2019

Author Contributor

Good catch.

According to MySQL , when the |start| is bigger than value's size or length is less than or equal to 0 . It will return a empty string.

mysql> select substr("123", 1, 1);
+---------------------+
| substr("123", 1, 1) |
+---------------------+
| 1                   |
+---------------------+
1 row in set (0.00 sec)

mysql> select substr("123", 1, 0);
+---------------------+
| substr("123", 1, 0) |
+---------------------+
|                     |
+---------------------+
1 row in set (0.00 sec)

mysql> select substr("123", 1, -1);
+----------------------+
| substr("123", 1, -1) |
+----------------------+
|                      |
+----------------------+
1 row in set (0.00 sec)

mysql> select substr("123", 5, 1);
+---------------------+
| substr("123", 5, 1) |
+---------------------+
|                     |
+---------------------+
1 row in set (0.00 sec)

mysql> select substr("123", -1, 1);
+----------------------+
| substr("123", -1, 1) |
+----------------------+
| 3                    |
+----------------------+
1 row in set (0.00 sec)

mysql> select substr("123", -1, 0);
+----------------------+
| substr("123", -1, 0) |
+----------------------+
|                      |
+----------------------+
1 row in set (0.00 sec)

mysql> select substr("123", -1, -1);
+-----------------------+
| substr("123", -1, -1) |
+-----------------------+
|                       |
+-----------------------+
1 row in set (0.00 sec)
mysql> select substr("123", -5, 1);
+----------------------+
| substr("123", -5, 1) |
+----------------------+
|                      |
+----------------------+
1 row in set (0.00 sec)

When

This comment has been minimized.

Copy link
@critical27

critical27 Aug 26, 2019

Contributor

Reasonable.

@darionyaphet darionyaphet force-pushed the darionyaphet:build-in-string-functions branch from 0c066f7 to 1fe0a74 Aug 26, 2019

@nebula-community-bot

This comment has been minimized.

Copy link
Member

commented Aug 29, 2019

Unit testing passed.

@dutor
dutor approved these changes Sep 2, 2019
Copy link
Member

left a comment

LGTM

@dutor dutor changed the title Support build-in String functions Added some built-in functions for string operations Sep 2, 2019

@nebula-community-bot

This comment has been minimized.

Copy link
Member

commented Sep 2, 2019

Unit testing failed.

@dutor

This comment has been minimized.

Copy link
Member

commented Sep 2, 2019

Jenkins,go!

@nebula-community-bot

This comment has been minimized.

Copy link
Member

commented Sep 2, 2019

Unit testing passed.

@dutor dutor merged commit 3c0b36f into vesoft-inc:master Sep 2, 2019

1 check passed

UnitTest All tests passed.
Details

@darionyaphet darionyaphet deleted the darionyaphet:build-in-string-functions branch Sep 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.