hanyuzheng7 opened a new pull request, #23161:
URL: https://github.com/apache/flink/pull/23161
## What is the purpose of the change
Implement the array_slice function to extract a subset of elements from an
array.
Returns a subarray of the input array between 'start_offset' and
'end_offset' inclusive.
The offsets are 1-based however 0 is also treated as the beginning of the
array.
Positive values are counted from the beginning of the array while negative
from the end.
If 'end_offset' is omitted then this offset is treated as the length of the
array.
If 'start_offset' is after 'end_offset' or both are out of array bounds an
empty array will be returned.
Returns null if any input is null.
## Brief change log
ARRAY_SLICE for Table API and SQL
Syntax:
`ARRAY_SLICE(array, start_offset[, end_offset])`
Arguments:
array: The array that contains the elements you want to slice.
start_offset: The inclusive starting offset.
end_offset: The inclusive ending offset, this is an optional argument.
Returns:
If 'start_offset' is after 'end_offset' or both are out of array bounds an
empty array will be returned.
Returns null if any input is null.
Examples:
```
SELECT ARRAY_SLICE(['a', 'b', 'c', 'd', 'e'], 1, 3)
Output: [a, b, c]
```
```
SELECT ARRAY_SLICE(['a', 'b', 'c', 'd', 'e'], -1, -3)
Output: []
```
```
SELECT ARRAY_SLICE(['a', 'b', 'c', 'd', 'e'], -3, -1)
Output[c, d, e]
```
```
SELECT ARRAY_SLICE(['a', 'b', 'c', 'd', 'e'], 3, 3)
Output[c]
```
```
SELECT ARRAY_SLICE(['a', 'b', 'c', 'd', 'e'], 1, 30)
Output[a, b,c,d,e]
```
```
SELECT ARRAY_SLICE(['a', 'b', 'c', 'd', 'e'], 1, -30)
Output[]
```
```
SELECT ARRAY_SLICE(['a', 'b', 'c', 'd', 'e'], -30, 30)
Output[a, b, c, d, e]
```
```
SELECT ARRAY_SLICE(['a', 'b', 'c', 'd', 'e'], -30, -5)
Output[a]
```
```
SELECT ARRAY_SLICE(['a', 'b', 'c', 'd', 'e'], 5, 30)
Output[e]
```
```
SELECT ARRAY_SLICE(['a', 'b', NULL, 'd', 'e'], 1, 3)
Output[a, b, null]
```
```
SELECT ARRAY_SLICE(['a', 'b', NULL, 'd', 'e'], 1)
Output[a, b, null, 'd', 'e']
```
```
SELECT ARRAY_SLICE(['a', 'b', NULL, 'd', 'e'], -1)
Output['e']
```
```
SELECT ARRAY_SLICE(['a', 'b', NULL, 'd', 'e'], 0, 0)
Output[a]
```
see also:
spark: https://spark.apache.org/docs/latest/api/sql/index.html#slice
google cloud:
https://cloud.google.com/spanner/docs/reference/standard-sql/array_functions#array_slice
ClickHouse:
https://clickhouse.com/docs/en/sql-reference/functions/array-functions#arrayslice
DockDb: https://duckdb.org/docs/sql/functions/nested#list-functions
## Verifying this change
- This change added tests in CollectionFunctionsITCase.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (yes / no)
- The public API, i.e., is any changed class annotated with
`@Public(Evolving)`: (yes / no)
- The serializers: (yes / no / don't know)
- The runtime per-record code paths (performance sensitive): (yes / no /
don't know)
- Anything that affects deployment or recovery: JobManager (and its
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / no / don't know)
- The S3 file system connector: (yes / no / don't know)
## Documentation
- Does this pull request introduce a new feature? (yes / no)
- If yes, how is the feature documented? (not applicable / docs / JavaDocs
/ not documented)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]