You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Jiajun Xie (Jira)" <ji...@apache.org> on 2023/06/21 13:07:00 UTC

[jira] [Commented] (CALCITE-5751) Add ARRAY_APPEND, ARRAY_POSITION, ARRAY_REMOVE ARRAY_PREPEND for Spark dialect

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

Jiajun Xie commented on CALCITE-5751:
-------------------------------------

Fixed in [a2d2a31|https://github.com/apache/calcite/commit/a2d2a31a70be3b20f3f2b8f311bf580dd9ae1e24]

[~jackylau] Thanks for your PR!

[~jhyde] Thanks for your review!

> Add ARRAY_APPEND, ARRAY_POSITION, ARRAY_REMOVE ARRAY_PREPEND for Spark dialect
> ------------------------------------------------------------------------------
>
>                 Key: CALCITE-5751
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5751
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.35.0
>            Reporter: jackylau
>            Assignee: jackylau
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.35.0
>
>
> h3. [array_append|https://spark.apache.org/docs/latest/api/sql/index.html#array_append]
> array_append(array, element) - Add the element at the end of the array passed as first argument. Type of element should be similar to type of the elements of the array. Null element is also appended into the array. But if the array passed, is NULL output is NULL
> *Examples:*
>  
> {code:java}
> {code}
> *> SELECT array_append(array('b', 'd', 'c', 'a'), 'd');
>  ["b","d","c","a","d"]
> > SELECT array_append(array(1, 2, 3, null), null);
>  [1,2,3,null,null]
> > SELECT array_append(CAST(null as Array<Int>), 2);
>  NULL* 
>  
> array_prepend is not in the docs, but in the code
> https://issues.apache.org/jira/browse/SPARK-41233
> {code:java}
> usage = """ _FUNC_(array, element) - Add the element at the beginning of the array passed as first argument. Type of element should be the same as the type of the elements of the array. Null element is also prepended to the array. But if the array passed is NULL output is NULL """, examples = """ Examples: > SELECT _FUNC_(array('b', 'd', 'c', 'a'), 'd'); ["d","b","d","c","a"] > SELECT _FUNC_(array(1, 2, 3, null), null); [null,1,2,3,null] > SELECT _FUNC_(CAST(null as Array<Int>), 2); NULL
> case class ArrayPrepend(left: Expression, right: Expression) extends RuntimeReplaceable {code}
> h3. [array_position|https://spark.apache.org/docs/latest/api/sql/index.html#array_position]
> array_position(array, element) - Returns the (1-based) index of the first element of the array as long.
> *Examples:*
>  
> {code:java}
> > SELECT array_position(array(3, 2, 1), 1);
>  3 {code}
>  
> h3. [array_remove|https://spark.apache.org/docs/latest/api/sql/index.html#array_remove]
> array_remove(array, element) - Remove all elements that equal to element from array.
> *Examples:*
>  
> {code:java}
> > SELECT array_remove(array(1, 2, 3, null, 3), 3);
>  [1,2,null] {code}
>  
>  



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