You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by "Till (JIRA)" <ji...@apache.org> on 2018/11/15 19:26:00 UTC

[jira] [Updated] (ASTERIXDB-2476) Support array slicing in SQL++

     [ https://issues.apache.org/jira/browse/ASTERIXDB-2476?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Till updated ASTERIXDB-2476:
----------------------------
    Description: 
Some programming languages support array slicing - the ability to extract sub arrays from array, which would be useful in SQL++. E.g. to retrieve the 2 elements in the middle of {{["a","b","c","d"]}} one could write {{["a","b","c","d"][1:3]}} and get {{["b","c"]}}.

To implement this, we should first add 2 functions {{array_slice}} with 2 and 3 parameters
 # {{array}},
 # {{start}}, and
 # {{(optionally) end}}.

The functions return {{NULL}} if
 * {{array}} is not an array,
 * {{start}} is not a number _or_ greater than the length of the array, or
 * {{end}} is not a number _or_ greater than the length of the array _or_ less than {{start}}.

Otherwise {{array_slice(array, start, end)}} returns a subset of the source array, containing the elements from position {{start}} to {{end-1}}. 
 The element at {{start}} is included, while the element at {{end}} is not. 
 The array index starts with 0. 
In the 2 arguments variant, all elements from start to the end of the source array are included. 
 Negative positions are counted backwards from the end of the array.

With that function we can extend the parser to support the slicing syntax {{array_expression [start_expression : [ end_expression ] ]}} and parse this syntax into to a call of the function {{array_slice}} where a missing {{end_expression}} in the syntax is rewritten to the 2 argument variant.

Standard semantics for {{NULL}} and {{MISSING}} parameters apply.

  was:
Some programming languages support array slicing - the ability to extract sub arrays from array, which would be useful in SQL++. E.g. to retrieve the 2 elements in the middle of {{["a","b","c","d"]}} one could write {{["a","b","c","d"][1:3]}} and get {{["b","c"]}}.

To implement this, we should first add a function {{array_slice}} with 3 parameters:
 # {{array}},
 # {{start}}, and
 # {{end}}.

The function returns {{NULL}} if
 * {{array}} is not an array,
 * {{start}} is not a number _or_ greater than the length of the array, or
 * {{end}} is not a number _or_ greater than the length of the array _or_ less than {{start}} _or_ {{MISSING}}.

Otherwise {{array_slice(array, start, end)}} returns a subset of the source array, containing the elements from position {{start}} to {{end-1}}. 
The element at {{start}} is included, while the element at {{end}} is not. 
The array index starts with 0. 
If {{end}} is {{MISSING}}, all elements from start to the end of the source array are included. 
Negative positions are counted backwards from the end of the array.

With that function we can extend the parser to support the slicing syntax {{array_expression [start_expression : [ end_expression ] ]}} and rewrite this syntax to a call of the function {{array_slice}} where a missing {{end_expression}} in the syntax is rewritten to passing a {{MISSING}} parameter as the 3rd argument.


> Support array slicing in SQL++
> ------------------------------
>
>                 Key: ASTERIXDB-2476
>                 URL: https://issues.apache.org/jira/browse/ASTERIXDB-2476
>             Project: Apache AsterixDB
>          Issue Type: Improvement
>          Components: COMP - Compiler, FUN - Functions
>    Affects Versions: 0.9.5
>            Reporter: Till
>            Assignee: Hussain Towaileb
>            Priority: Major
>
> Some programming languages support array slicing - the ability to extract sub arrays from array, which would be useful in SQL++. E.g. to retrieve the 2 elements in the middle of {{["a","b","c","d"]}} one could write {{["a","b","c","d"][1:3]}} and get {{["b","c"]}}.
> To implement this, we should first add 2 functions {{array_slice}} with 2 and 3 parameters
>  # {{array}},
>  # {{start}}, and
>  # {{(optionally) end}}.
> The functions return {{NULL}} if
>  * {{array}} is not an array,
>  * {{start}} is not a number _or_ greater than the length of the array, or
>  * {{end}} is not a number _or_ greater than the length of the array _or_ less than {{start}}.
> Otherwise {{array_slice(array, start, end)}} returns a subset of the source array, containing the elements from position {{start}} to {{end-1}}. 
>  The element at {{start}} is included, while the element at {{end}} is not. 
>  The array index starts with 0. 
> In the 2 arguments variant, all elements from start to the end of the source array are included. 
>  Negative positions are counted backwards from the end of the array.
> With that function we can extend the parser to support the slicing syntax {{array_expression [start_expression : [ end_expression ] ]}} and parse this syntax into to a call of the function {{array_slice}} where a missing {{end_expression}} in the syntax is rewritten to the 2 argument variant.
> Standard semantics for {{NULL}} and {{MISSING}} parameters apply.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)