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

Jacky Lau edited comment on FLINK-32257 at 6/30/23 8:38 AM:
------------------------------------------------------------

hi guys [~hanyuzheng] [~dwysakowicz] [~Sergey Nuyanzin] [~mapohl] 

sorry for late review, the pr looks good. but it also exists bug.
 i supports these spark collection function recently. i am familiar with it.
because do not have people help review , i supports these in calcite 
[https://github.com/apache/calcite/commits?author=liuyongvs]

the return type is not right. it should always return nullable.

because we don't know the value whether is null in compile procedure, only can 
know in the runtime.
for example:
{code:java}
-- ddl : 
CREATE TABLE data_source (
  a array<int not null> not null
) WITH (
  'connector'='xxx',
); 

// the element is array(), that is to say, empty array. the result is null.
// if the return type is int not null, how to save null value.
select array_max(a) from data_source;{code}
 
{code:java}
-- spark 
case class ArrayMax(child: Expression)
  extends UnaryExpression with ImplicitCastInputTypes with NullIntolerant {
  
  override def nullable: Boolean = true
  
@transient override lazy val dataType: DataType = child.dataType match
{     case ArrayType(dt, _) => dt     case _ => throw new 
IllegalStateException(s"$prettyName accepts only arrays.")   } {code}


was (Author: jackylau):
hi guys [~hanyuzheng] [~dwysakowicz] [~Sergey Nuyanzin] [~mapohl] 

sorry for late review, the pr looks good. but it also exists bug.
 i supports these spark collection function recently. i am familiar with it.
because do not have people help review , i supports these in calcite 
https://github.com/apache/calcite/commits?author=liuyongvs

the return type is not right. it should always return nullable.

because we don't know the value whether is null in compile procedure, only can 
know in the runtime.
for example:
{code:java}
-- ddl : 
CREATE TABLE data_source (
  a array<int not null> not null
) WITH (
  'connector'='xxx',
); 

// the element is array(), that is to say, empty array. the result is null.
// if the return type is int not null, how to save null value.
select array_max(a) from data_source;{code}
 

```
spark 
case class ArrayMax(child: Expression)
  extends UnaryExpression with ImplicitCastInputTypes with NullIntolerant {

  override def nullable: Boolean = true
  @transient override lazy val dataType: DataType = child.dataType match {
    case ArrayType(dt, _) => dt
    case _ => throw new IllegalStateException(s"$prettyName accepts only 
arrays.")
  }

```

> Add ARRAY_MAX support in SQL & Table API
> ----------------------------------------
>
>                 Key: FLINK-32257
>                 URL: https://issues.apache.org/jira/browse/FLINK-32257
>             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
>
>
> This is an implementation of ARRAY_MAX
> The array_max() function concatenates get the maximum element from input 
> array.
> The result matches the type of the elements. NULL elements are skipped. If 
> array is empty, or contains only NULL elements, NULL is returned.
>  
> Syntax
> array_max(array)
> Arguments
> array: Any ARRAY with elements for which order is supported.
>  
> Returns
> The result matches the type of the elements. NULL elements are skipped. If 
> array is empty, or contains only NULL elements, NULL is returned.
>  
> Examples
> SQL
>  
> > SELECT array_max(array(1, 20, NULL, 3)); 20
>  
> {code:java}
> // Fink SQL-> select array_max(array[1, 20, null, 3])
> 20{code}
>  
> See also
> spark 
> [https://spark.apache.org/docs/latest/api/sql/index.html#array_max|https://spark.apache.org/docs/latest/api/sql/index.html#array_min]
> presto [https://prestodb.io/docs/current/functions/array.html]



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

Reply via email to