Skip to content

Conversation

@hanyuzheng7
Copy link
Contributor

What is the purpose of the change

Implement the array_sort function to extract a subset of elements from an array.

Returns the array in sorted order. Sorts the input array in ascending or descending order according to the natural ordering of the array elements. NULL elements are placed at the beginning of the returned array in ascending order or at the end of the returned array in descending order. If the array itself is null, the function will return null. The optional ascendingOrder argument defaults to true if not specified.

Brief change log

ARRAY_SORT for Table API and SQL

Syntax:

ARRAY_SORT(array, [ascendingOrder])

Arguments:
array: The array we want to sort.
ascendingOrder: this is an option, default and true stand for ascending order, false stand for descending order.

Returns:
if the array is null or ascendingOrder is null return null. if array is empty return empty.

Examples:

SELECT ARRAY_SORT([5, 3, 2, 1, 0, null])
Output: [null, 0, 1, 2, 3, 5]
SELECT ARRAY_SORT([5, 3, 2, 1, 0, null], true)
Output: [null, 0, 1, 2, 3, 5]
SELECT ARRAY_SORT([null, 1, 2, 3, 5], false)
Output: [5, 3, 2, 1, null]
SELECT ARRAY_SORT(null)
null
SELECT ARRAY_SLICE(['a', 'b', 'c', 'd', 'e'], null)
null

see also:
spark: https://spark.apache.org/docs/latest/api/sql/index.html#array_sort
databrick:https://docs.databricks.com/sql/language-manual/functions/array_sort.html

Verifying this change

  • This change added tests in CollectionFunctionsITCase.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (yes / no)
  • The serializers: (yes / no / don't know)
  • The runtime per-record code paths (performance sensitive): (yes / no / don't know)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / no / don't know)
  • The S3 file system connector: (yes / no / don't know)

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

[BP-1.17] [FLINK-26948][table] Add-ARRAY_SORT-function.
@flinkbot
Copy link
Collaborator

flinkbot commented Aug 8, 2023

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@MartijnVisser
Copy link
Contributor

Closing this PR since we don't backport new features into existing releases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants