[ 
https://issues.apache.org/jira/browse/FLINK-32260?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17737329#comment-17737329
 ] 

Sergey Nuyanzin commented on FLINK-32260:
-----------------------------------------

I would suggest to change behavior of the function a bit to be consistent with 
lots of other vendors.

1. Rename args. IMHO Google Spanner[1] has the best naming 
{{ARRAY_SLICE(array_to_slice, start_offset, end_offset)}}.
2. Return {{NULL}} *+only+* if one of the input args is {{NULL}}. Otherwise 
return sliced array or empty array. This is the behavior of Google Spanner[1], 
Cosmos DB[2], ClickHouse[3], DuckDB[4], Snowflake[5].
3. Clickhouse[3] and Cosmos DB[2] have the third arg as optional meaning that 
if it is not specified the array will be sliced till the end (similar to 
{{substring}}) 


[1] 
https://cloud.google.com/spanner/docs/reference/standard-sql/array_functions#array_slice
[2] https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/query/array-slice
[3] 
https://clickhouse.com/docs/en/sql-reference/functions/array-functions#arrayslice
[4] https://duckdb.org/docs/sql/functions/nested#list-functions
[5] https://docs.snowflake.com/en/sql-reference/functions/array_slice

P.S. for some of vendors this behavior is not specified explicitly in doc 
however it could be double checked against latest versions (I did it myself)

> Add SLICE support in SQL & Table API
> ------------------------------------
>
>                 Key: FLINK-32260
>                 URL: https://issues.apache.org/jira/browse/FLINK-32260
>             Project: Flink
>          Issue Type: Improvement
>          Components: Table SQL / Planner
>    Affects Versions: 1.18.0
>            Reporter: Bonnie Varghese
>            Assignee: Hanyu Zheng
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.18.0
>
>
> Implement the {{array_slice}} function to extract a subset of elements from 
> an array.
> Description: The {{array_slice}} function in the ETL pipeline allows you to 
> extract a subset of elements from an array based on the specified starting 
> index and length. It supports both positive and negative indices, where 
> positive indices start from 1 (the first element) and negative indices start 
> from the end of the array (-1 being the last element).
> Syntax:
>  
> code
> {code:java}
> array_slice[x: array, start: int, length: int] -> array{code}
> {{ }}
> Arguments:
>  * {{{}x{}}}: The input array from which to extract the subset of elements.
>  * {{{}start{}}}: The starting index of the subset. If positive, it 
> represents the index from the beginning of the array. If negative, it 
> represents the index from the end of the array (-1 being the last element).
>  * {{{}length{}}}: The length of the subset to be extracted.
> Returns: An array containing the subset of elements extracted from the input 
> array {{{}x{}}}. The subset starts from the specified {{start}} index and has 
> the specified {{{}length{}}}.
> Examples:
>  # Extracting a subset from an array starting from index 2 with length 2:
>  
> {code:java}
> array_slice[array[1, 2, 3, 4], 2, 2]  Output: [2, 3]{code}
>      2. Extracting a subset from an array starting from the second-to-last 
> element with length 
>  
> {code:java}
> array_slice[array[1, 2, 3, 4], -2, 2]
> Output: [3, 4]{code}
> see also:
> spark:[https://spark.apache.org/docs/latest/api/sql/index.html#slice]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to