-
Notifications
You must be signed in to change notification settings - Fork 265
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
[Enhancement](docs) Sql function compress and uncompress #1955
Open
lzyy2024
wants to merge
3
commits into
apache:master
Choose a base branch
from
lzyy2024:FunctionCompress
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+555
−0
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
docs/sql-manual/sql-functions/scalar-functions/string-functions/compress.md
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,72 @@ | ||
--- | ||
{ | ||
"title": "COMPRESS", | ||
"language": "en" | ||
} | ||
--- | ||
|
||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
## Description | ||
The COMPRESS function is used to compress strings or values into binary data. The compressed data can be decompressed using the UNCOMPRESS function. | ||
|
||
## Syntax | ||
|
||
```sql | ||
COMPRESS(<uncompressed_str>) | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameters | Description | | ||
|--------------------|---------------| | ||
| `<uncompressed_str>` | Uncompressed raw string | | ||
|
||
The parameter type is varchar or string | ||
|
||
## Return Value | ||
The return string is the same as the input <uncompressed_str> type | ||
The first ten digits of the returned string are the hexadecimal length of the original string, for example, 0x01000000. Followed by the compressed value. | ||
|
||
Special case: | ||
- <uncompressed_str> Return '0x' when input is '' | ||
|
||
## Example | ||
|
||
``` sql | ||
select compress('abc'); | ||
``` | ||
```text | ||
+----------------------------------+ | ||
| compress('abc') | | ||
+----------------------------------+ | ||
| 0x03000000789C4B4C4A0600024D0127 | | ||
+----------------------------------+ | ||
``` | ||
```sql | ||
select compress(''); | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
```text | ||
+--------------+ | ||
| compress('') | | ||
+--------------+ | ||
| 0x | | ||
+--------------+ | ||
``` |
83 changes: 83 additions & 0 deletions
83
docs/sql-manual/sql-functions/scalar-functions/string-functions/uncompressed.md
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,83 @@ | ||
--- | ||
{ | ||
"title": "UNCOMPRESS", | ||
"language": "en" | ||
} | ||
--- | ||
|
||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
## Description | ||
The UNCOMPRESS function is used to extract binary data into a string or value, and the binary data needs to be the result of 'COMPRESS' | ||
|
||
## Syntax | ||
|
||
```sql | ||
UNCOMPRESS(<compressed_str>) | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameters | Description | | ||
|--------------------|---------------| | ||
| `<compressed_str>` | Compressed binary data | | ||
|
||
The parameter type is varchar or string | ||
|
||
## Return Value | ||
The return value is the same as the input <compressed_str> type | ||
|
||
Special cases: | ||
- <compressed_str> Returns NULL if the binary data is not compressed. | ||
|
||
|
||
## Example | ||
|
||
``` sql | ||
select uncompress(compress('abc')); | ||
``` | ||
```text | ||
+-----------------------------+ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add more cases which got NULL, or empty |
||
| uncompress(compress('abc')) | | ||
+-----------------------------+ | ||
| abc | | ||
+-----------------------------+ | ||
``` | ||
```sql | ||
select uncompress('0x03000000789C4B4C4A0600024D019'); | ||
``` | ||
```text | ||
+-----------------------------------------------+ | ||
| uncompress('0x03000000789C4B4C4A0600024D019') | | ||
+-----------------------------------------------+ | ||
| NULL | | ||
+-----------------------------------------------+ | ||
``` | ||
`0x03000000789c4b4c4a0600024d019` is `compress('abc')` has carried on the tiny changes, it is illegal. | ||
```sqp | ||
select uncompress(compress('')); | ||
``` | ||
```text | ||
+--------------------------+ | ||
| uncompress(compress('')) | | ||
+--------------------------+ | ||
| | | ||
+--------------------------+ | ||
``` |
71 changes: 71 additions & 0 deletions
71
.../current/sql-manual/sql-functions/scalar-functions/string-functions/compress.md
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,71 @@ | ||
--- | ||
{ | ||
"title": "COMPRESS", | ||
"language": "zh-CN" | ||
} | ||
--- | ||
|
||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
## 描述 | ||
COMPRESS 函数用于将字符串或值压缩成二进制数据,压缩后的数据可通过 `UNCOMPRESS` 函数解压还原。 | ||
|
||
## 语法 | ||
|
||
```sql | ||
COMPRESS(<uncompresse_str>) | ||
``` | ||
|
||
## 参数 | ||
|
||
| 参数 | 说明 | | ||
|--------------------|---------------| | ||
| `<uncompressed_str>` | 未压缩的原串 | | ||
|
||
参数类型是varchar或者string | ||
|
||
## 返回值 | ||
返回串与输入的 <uncompressed_str> 类型一致 | ||
返回串的前十位是原串长度的十六进制形式, 例如: 0x01000000。后面的是压缩值。 | ||
特殊情况: | ||
- <uncompressed_str> 输入为 ‘’ 时,返回 '0x' | ||
|
||
## 举例 | ||
|
||
``` sql | ||
select compress('abc'); | ||
``` | ||
```text | ||
+----------------------------------+ | ||
| compress('abc') | | ||
+----------------------------------+ | ||
| 0x03000000789C4B4C4A0600024D0127 | | ||
+----------------------------------+ | ||
``` | ||
```sql | ||
select compress(''); | ||
``` | ||
```text | ||
+--------------+ | ||
| compress('') | | ||
+--------------+ | ||
| 0x | | ||
+--------------+ | ||
``` |
82 changes: 82 additions & 0 deletions
82
...rent/sql-manual/sql-functions/scalar-functions/string-functions/uncompressed.md
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,82 @@ | ||
--- | ||
{ | ||
"title": "UNCOMPRESS", | ||
"language": "zh-CN" | ||
} | ||
--- | ||
|
||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
## 描述 | ||
UNCOMPRESS 函数用于将二进制数据解压缩成字符串或值,二进制数据需要是`COMPRESS`的结果 | ||
|
||
## 语法 | ||
|
||
```sql | ||
UNCOMPRESS(<compressed_str>) | ||
``` | ||
|
||
## 参数 | ||
|
||
| 参数 | 说明 | | ||
|--------------------|---------------| | ||
| `<compressed_str>` | 压缩得到的二进制数据 | | ||
|
||
参数类型是varchar或者string | ||
|
||
## 返回值 | ||
返回值与输入的 <compressed_str> 类型一致 | ||
特殊情况: | ||
- <compressed_str> 输入不是`COMPRESS`得到的二进制数据时, 返回 NULL. | ||
|
||
|
||
## 举例 | ||
|
||
``` sql | ||
select uncompress(compress('abc')); | ||
``` | ||
```text | ||
+-----------------------------+ | ||
| uncompress(compress('abc')) | | ||
+-----------------------------+ | ||
| abc | | ||
+-----------------------------+ | ||
``` | ||
```sql | ||
select uncompress('0x03000000789C4B4C4A0600024D019'); | ||
``` | ||
```text | ||
+-----------------------------------------------+ | ||
| uncompress('0x03000000789C4B4C4A0600024D019') | | ||
+-----------------------------------------------+ | ||
| NULL | | ||
+-----------------------------------------------+ | ||
``` | ||
`0x03000000789C4B4C4A0600024D019`是compress('abc')进行了微小的修改,它是非法的。 | ||
```sql | ||
select uncompress(compress('')); | ||
``` | ||
```text | ||
+--------------------------+ | ||
| uncompress(compress('')) | | ||
+--------------------------+ | ||
| | | ||
+--------------------------+ | ||
``` |
71 changes: 71 additions & 0 deletions
71
...sion-3.0/sql-manual/sql-functions/scalar-functions/string-functions/compress.md
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,71 @@ | ||
--- | ||
{ | ||
"title": "COMPRESS", | ||
"language": "zh-CN" | ||
} | ||
--- | ||
|
||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
## 描述 | ||
COMPRESS 函数用于将字符串或值压缩成二进制数据,压缩后的数据可通过 `UNCOMPRESS` 函数解压还原。 | ||
|
||
## 语法 | ||
|
||
```sql | ||
COMPRESS(<uncompressed_str>) | ||
``` | ||
|
||
## 参数 | ||
|
||
| 参数 | 说明 | | ||
|--------------------|---------------| | ||
| `<uncompressed_str>` | 未压缩的原串 | | ||
|
||
参数类型是varchar或者string | ||
|
||
## 返回值 | ||
返回串与输入的 <uncompressed_str> 类型一致 | ||
返回串的前十位是原串长度的十六进制形式, 例如: 0x01000000。后面的是压缩值。 | ||
特殊情况: | ||
- <uncompressed_str> 输入为 ‘’ 时,返回 '0x' | ||
|
||
## 举例 | ||
|
||
``` sql | ||
select compress('abc'); | ||
``` | ||
```text | ||
+----------------------------------+ | ||
| compress('abc') | | ||
+----------------------------------+ | ||
| 0x03000000789C4B4C4A0600024D0127 | | ||
+----------------------------------+ | ||
``` | ||
```sql | ||
select compress(''); | ||
``` | ||
```text | ||
+--------------+ | ||
| compress('') | | ||
+--------------+ | ||
| 0x | | ||
+--------------+ | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add case about empty string input