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

[doc]Fix string function documentation docs #1842

Merged
merged 6 commits into from
Jan 23, 2025
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 @@ -22,86 +22,89 @@ specific language governing permissions and limitations
under the License.
-->

## count_substrings
## Description

### description
The COUNT_SUBSTRINGS function counts the number of occurrences of a specified substring within a string. Note: The current implementation continues searching after shifting by the length of the substring when a match is found. For example, when str='ccc' and pattern='cc', the result returned is 1.

#### Syntax
## Syntax

`int count_substrings(STRING str, STRING pattern)`
Returns the total number of occurrences of the substring pattern in the string str.
Note: The current implementation shifts by the length of the pattern after each match in the string.
Therefore, when str: ccc and pattern: cc, the result returned is 1.

#### Arguments
```sql
COUNT_SUBSTRINGS(<str>, <pattern>)
```

`str` — The string to be checked. Type: `String`
`pattern` — The substring to be matched. Type: `String`
## Parameters
| Parameter | Description |
| --------- | --------------------------------------- |
| `<str>` | The string to be searched. Type: STRING |
| `<pattern>` | The substring to match. Type: STRING |

## Return Value

#### Returned value(s)
Returns an INT type, representing the number of times the substring appears in the string.

Returns the total number of occurrences of the substring.
Special cases:
- If str is NULL, returns NULL
- If pattern is an empty string, returns 0
- If str is an empty string, returns 0

### example
## Examples

1. Basic usage
```sql
SELECT count_substrings('a1b1c1d', '1');
```
mysql [(none)]>select count_substrings('a1b1c1d','1');
```text
+----------------------------------+
| count_substrings('a1b1c1d', '1') |
+----------------------------------+
| 3 |
+----------------------------------+
```

mysql [(none)]>select count_substrings(',,a,b,c,',',');
2. Case with consecutive commas
```sql
SELECT count_substrings(',,a,b,c,', ',');
```
```text
+-----------------------------------+
| count_substrings(',,a,b,c,', ',') |
+-----------------------------------+
| 5 |
+-----------------------------------+
```

mysql [(none)]>select count_substrings('ccc','cc');
3. Case with overlapping substrings
```sql
SELECT count_substrings('ccc', 'cc');
```
```text
+--------------------------------+
| count_substrings('ccc', 'cc') |
+--------------------------------+
| 1 |
+--------------------------------+
```

mysql [(none)]>SELECT count_substrings(NULL,',');
4. NULL value handling
```sql
SELECT count_substrings(NULL, ',');
```
```text
+-----------------------------+
| count_substrings(NULL, ',') |
+-----------------------------+
| NULL |
+-----------------------------+
```

mysql [(none)]>select count_substrings('a,b,c,abcde','');
5. Empty string handling
```sql
SELECT count_substrings('a,b,c,abcde', '');
```
```text
+-------------------------------------+
| count_substrings('a,b,c,abcde', '') |
+-------------------------------------+
| 0 |
+-------------------------------------+

mysql [(none)]>select count_substrings(NULL, 'a');
+-----------------------------+
| count_substrings(NULL, 'a') |
+-----------------------------+
| NULL |
+-----------------------------+

mysql [(none)]>select count_substrings('','asd');
+-----------------------------+
| count_substrings('', 'asd') |
+-----------------------------+
| 0 |
+-----------------------------+

mysql [(none)]>select count_substrings('abccbaacb','c');
+------------------------------------+
| count_substrings('abccbaacb', 'c') |
+------------------------------------+
| 3 |
+------------------------------------+
```
### keywords

COUNT_SUBSTRINGS,SUBSTRINGS
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,63 @@ specific language governing permissions and limitations
under the License.
-->


## Description

The CUT_TO_FIRST_SIGNIFICANT_SUBDOMAIN function extracts the effective part of a domain from a URL, including the top-level domain up to the "first significant subdomain". If the input URL is invalid, it returns an empty string.

## Syntax

`VARCHAR cut_to_first_significant_subdomain(VARCHAR url)`
```sql
CUT_TO_FIRST_SIGNIFICANT_SUBDOMAIN(<url>)
```

## Parameters
| Parameter | Description |
| --------- | --------------------------------------------- |
| `<url>` | The URL string to be processed. Type: VARCHAR |

Extract the part of the domain in the URL from the top-level subdomain down to the "first valid subdomain." If invalid, return an empty string.
## Return Value

Returns VARCHAR type, representing the extracted domain part.

Special cases:
- If url is NULL, returns NULL
- If url is not a valid domain format, returns an empty string

## Examples

1. Basic domain processing
```sql
mysql [(none)]>select cut_to_first_significant_subdomain("www.baidu.com");
SELECT cut_to_first_significant_subdomain('www.baidu.com');
```
```text
+-----------------------------------------------------+
| cut_to_first_significant_subdomain('www.baidu.com') |
+-----------------------------------------------------+
| baidu.com |
+-----------------------------------------------------+
```

mysql [(none)]>select cut_to_first_significant_subdomain("www.google.com.cn");
2. Multi-level domain processing
```sql
SELECT cut_to_first_significant_subdomain('www.google.com.cn');
```
```text
+---------------------------------------------------------+
| cut_to_first_significant_subdomain('www.google.com.cn') |
+---------------------------------------------------------+
| google.com.cn |
+---------------------------------------------------------+
```

mysql [(none)]>select cut_to_first_significant_subdomain("wwwwwwww");
3. Invalid domain processing
```sql
SELECT cut_to_first_significant_subdomain('wwwwwwww');
```
```text
+------------------------------------------------+
| cut_to_first_significant_subdomain('wwwwwwww') |
+------------------------------------------------+
| |
+------------------------------------------------+
```

### Keywords

CUT_TO_FIRST_SIGNIFICANT_SUBDOMAIN
```
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,64 @@ under the License.

## Description

The LTRIM_IN function removes specified characters from the left side of a string. When no character set is specified, it removes leading spaces by default. When a character set is specified, it removes all specified characters from the left side (regardless of their order in the set).
The key feature of LTRIM_IN is that it removes any combination of characters from the specified set, while the LTRIM function removes characters based on exact string matching.

## Syntax

`VARCHAR ltrim_in(VARCHAR str[, VARCHAR rhs])`
```sql
LTRIM_IN(<str> [, <rhs>])
```

## Parameters
| Parameter | Description |
| --------- | ---------------------------------------------------------------------- |
| `<str>` | The string to be processed. Type: VARCHAR |
| `<rhs>` | Optional parameter, the set of characters to be removed. Type: VARCHAR |

When there is no rhs parameter, remove the spaces that appear consecutively in the parameter str starting from the left part; when there is an rhs parameter, search and remove any characters in the rhs character set at the left end of the string (regardless of order)
## Return Value

Returns VARCHAR type, representing the processed string.

Special cases:
- If str is NULL, returns NULL
- If rhs is not specified, removes all leading spaces
- If rhs is specified, removes all characters from the left side that appear in rhs until encountering the first character not in rhs

## Examples

1. Remove leading spaces
```sql
mysql> SELECT ltrim_in(' ab d') str;
SELECT ltrim_in(' ab d') str;
```
```text
+------+
| str |
+------+
| ab d |
+------+
```

mysql> SELECT ltrim_in('ababccaab','ab') str;
2. Remove specified character set
```sql
SELECT ltrim_in('ababccaab', 'ab') str;
```
```text
+-------+
| str |
+-------+
| ccaab |
+-------+
```

## Keywords

LTRIM_IN
3. Comparison with LTRIM function
```sql
SELECT ltrim_in('abcd', 'ae'),ltrim('abcd', 'abe');
```
```text
+------------------------+----------------------+
| ltrim_in('abcd', 'ae') | ltrim('abcd', 'abe') |
+------------------------+----------------------+
| bcd | abcd |
+------------------------+----------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,65 @@ under the License.

## Description

The RTRIM_IN function removes specified characters from the right side of a string. When no character set is specified, it removes trailing spaces by default. When a character set is specified, it removes all specified characters from the right side (regardless of their order in the set).
The key feature of RTRIM_IN is that it removes any combination of characters from the specified set, while the RTRIM function removes characters based on exact string matching.

## Syntax

`VARCHAR rtrim_in(VARCHAR str[, VARCHAR rhs])`
```sql
RTRIM_IN(<str>[, <rhs>])
```

## Parameters
| Parameter | Description |
| --------- | ---------------------------------------------------------------------- |
| `<str>` | The string to be processed. Type: VARCHAR |
| `<rhs>` | Optional parameter, the set of characters to be removed. Type: VARCHAR |

When there is no rhs parameter, remove the spaces that appear consecutively in the parameter str starting from the right part; when there is an rhs parameter, search and remove any characters in the rhs character set at the right end of the string (regardless of order)
## Return Value

Returns VARCHAR type, representing the processed string.

Special cases:
- If str is NULL, returns NULL
- If rhs is not specified, removes all trailing spaces
- If rhs is specified, removes all characters from the right side that appear in rhs until encountering the first character not in rhs

## Example
## Examples

1. Remove trailing spaces
```sql
mysql> SELECT rtrim_in('ab d ') str;
SELECT rtrim_in('ab d ') str;
```
```text
+------+
| str |
+------+
| ab d |
+------+

mysql> SELECT rtrim_in('ababccaab','ab') str;
+--------+
| str |
+--------+
| ababcc |
+--------+
```

## Keywords
2. Remove specified character set
```sql
-- RTRIM_IN removes any 'a' and 'b' characters from the right end
SELECT rtrim_in('ababccaab', 'ab') str;
```
```text
+---------+
| str |
+---------+
| ababcc |
+---------+
```

RTRIM_IN
3. Comparison with RTRIM function
```sql
SELECT rtrim_in('ababccaab', 'ab'),rtrim('ababccaab', 'ab');
```
```text
+-----------------------------+--------------------------+
| rtrim_in('ababccaab', 'ab') | rtrim('ababccaab', 'ab') |
+-----------------------------+--------------------------+
| ababcc | ababcca |
+-----------------------------+--------------------------+
```
Loading
Loading