[
https://issues.apache.org/jira/browse/FLINK-32260?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17738152#comment-17738152
]
Sergey Nuyanzin commented on FLINK-32260:
-----------------------------------------
There is also no consensus between vendors
DuckDB treats 0 and 1 as same so (could be checked online via
https://shell.duckdb.org/)
{noformat}
duckdb> select array_slice(array[1, 2, 3], 0, 2);
┌─────────────────────────────────────┐
│ array_slice((ARRAY[1, 2, 3]), 0, 2) │
╞═════════════════════════════════════╡
│ [1, 2] │
└─────────────────────────────────────┘
Elapsed: 5 ms
duckdb> select array_slice(array[1, 2, 3], 1, 2);
┌─────────────────────────────────────┐
│ array_slice((ARRAY[1, 2, 3]), 1, 2) │
╞═════════════════════════════════════╡
│ [1, 2] │
└─────────────────────────────────────┘
Elapsed: 4 ms
duckdb> select array_slice(array[1, 2, 3], 0, 2);
┌─────────────────────────────────────┐
│ array_slice((ARRAY[1, 2, 3]), 0, 2) │
╞═════════════════════════════════════╡
│ [1, 2] │
└─────────────────────────────────────┘
Elapsed: 10 ms
duckdb> select array_slice(array[1, 2, 3], 0, -2);
┌──────────────────────────────────────┐
│ array_slice((ARRAY[1, 2, 3]), 0, -2) │
╞══════════════════════════════════════╡
│ [1] │
└──────────────────────────────────────┘
Elapsed: 3 ms
duckdb> select array_slice(array[1, 2, 3], 1, -2);
┌──────────────────────────────────────┐
│ array_slice((ARRAY[1, 2, 3]), 1, -2) │
╞══════════════════════════════════════╡
│ [1] │
└──────────────────────────────────────┘
Elapsed: 3 ms
{noformat}
for ClickHouse it's different: for any query with start_offset 0 it returns
empty array+
> Add ARRAY_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)