-
Notifications
You must be signed in to change notification settings - Fork 293
feat: support sort_array expression #3706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
grorge123
wants to merge
2
commits into
apache:main
Choose a base branch
from
grorge123:sort_array
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,7 +105,7 @@ | |
| - [ ] sequence | ||
| - [ ] shuffle | ||
| - [ ] slice | ||
| - [ ] sort_array | ||
| - [x] sort_array | ||
|
|
||
| ### bitwise_funcs | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
spark/src/test/resources/sql-tests/expressions/array/sort_array.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| -- Licensed to the Apache Software Foundation (ASF) under one | ||
| -- or more contributor license agreements. See the NOTICE file | ||
| -- distributed with this work for additional information | ||
| -- regarding copyright ownership. The ASF licenses this file | ||
| -- to you under the Apache License, Version 2.0 (the | ||
| -- "License"); you may not use this file except in compliance | ||
| -- with the License. You may obtain a copy of the License at | ||
| -- | ||
| -- http://www.apache.org/licenses/LICENSE-2.0 | ||
| -- | ||
| -- Unless required by applicable law or agreed to in writing, | ||
| -- software distributed under the License is distributed on an | ||
| -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| -- KIND, either express or implied. See the License for the | ||
| -- specific language governing permissions and limitations | ||
| -- under the License. | ||
|
|
||
| -- ConfigMatrix: parquet.enable.dictionary=false,true | ||
|
|
||
| statement | ||
| CREATE TABLE test_sort_array_int(arr array<int>) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_sort_array_int VALUES | ||
| (array(3, 1, 4, 1, 5)), | ||
| (array(3, NULL, 1, NULL, 2)), | ||
| (array()), | ||
| (NULL) | ||
|
|
||
| query | ||
| SELECT sort_array(arr) FROM test_sort_array_int | ||
|
|
||
| query | ||
| SELECT sort_array(arr, true) FROM test_sort_array_int | ||
|
|
||
| query | ||
| SELECT sort_array(arr, false) FROM test_sort_array_int | ||
|
|
||
| statement | ||
| CREATE TABLE test_sort_array_string(arr array<string>) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_sort_array_string VALUES | ||
| (array('d', 'c', 'b', 'a')), | ||
| (array('b', NULL, 'a')), | ||
| (array()), | ||
| (NULL) | ||
|
|
||
| query | ||
| SELECT sort_array(arr) FROM test_sort_array_string | ||
|
|
||
| query | ||
| SELECT sort_array(arr, true) FROM test_sort_array_string | ||
|
|
||
| query | ||
| SELECT sort_array(arr, false) FROM test_sort_array_string | ||
|
|
||
| statement | ||
| CREATE TABLE test_sort_array_float(arr array<double>) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_sort_array_float VALUES | ||
| (array(CAST('NaN' AS DOUBLE), 3.0, 1.0, NULL, -0.0, 0.0)), | ||
| (array(CAST('NaN' AS DOUBLE), CAST('NaN' AS DOUBLE), -5.0, 2.0)), | ||
| (array()), | ||
| (NULL) | ||
|
|
||
| query | ||
| SELECT sort_array(arr) FROM test_sort_array_float | ||
|
|
||
| query | ||
| SELECT sort_array(arr, true) FROM test_sort_array_float | ||
|
|
||
| query | ||
| SELECT sort_array(arr, false) FROM test_sort_array_float | ||
|
|
||
| statement | ||
| CREATE TABLE test_sort_array_decimal(arr array<decimal(10, 0)>) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_sort_array_decimal VALUES | ||
| (array(CAST(100 AS DECIMAL(10, 0)), CAST(10 AS DECIMAL(10, 0)))), | ||
| (array()), | ||
| (NULL) | ||
|
|
||
| query | ||
| SELECT sort_array(arr) FROM test_sort_array_decimal | ||
|
|
||
| query | ||
| SELECT sort_array(arr, true) FROM test_sort_array_decimal | ||
|
|
||
| query | ||
| SELECT sort_array(arr, false) FROM test_sort_array_decimal | ||
|
|
||
| statement | ||
| CREATE TABLE test_sort_array_boolean(arr array<boolean>) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_sort_array_boolean VALUES | ||
| (array(true, false, true, false)), | ||
| (array(true, false, true, NULL, false)), | ||
| (array()), | ||
| (NULL) | ||
|
|
||
| query | ||
| SELECT sort_array(arr) FROM test_sort_array_boolean | ||
|
|
||
| query | ||
| SELECT sort_array(arr, true) FROM test_sort_array_boolean | ||
|
|
||
| query | ||
| SELECT sort_array(arr, false) FROM test_sort_array_boolean | ||
|
|
||
| statement | ||
| CREATE TABLE test_sort_array_struct(arr array<struct<a:int,b:string>>) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_sort_array_struct VALUES | ||
| (array( | ||
| named_struct('a', 2, 'b', 'b'), | ||
| named_struct('a', 1, 'b', 'c'), | ||
| named_struct('a', 1, 'b', 'a'))), | ||
| (array( | ||
| named_struct('a', 2, 'b', NULL), | ||
| named_struct('a', 1, 'b', 'z'), | ||
| named_struct('a', 1, 'b', NULL))), | ||
| (array()), | ||
| (NULL) | ||
|
|
||
| query | ||
| SELECT sort_array(arr) FROM test_sort_array_struct | ||
|
|
||
| query | ||
| SELECT sort_array(arr, false) FROM test_sort_array_struct | ||
|
|
||
| statement | ||
| CREATE TABLE test_sort_array_nested(arr array<array<int>>) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_sort_array_nested VALUES | ||
| (array(array(2, 3), array(1), array(2, 1))), | ||
| (array(array(1, NULL), array(1), NULL)), | ||
| (array()), | ||
| (NULL) | ||
|
|
||
| query | ||
| SELECT sort_array(arr) FROM test_sort_array_nested | ||
|
|
||
| query | ||
| SELECT sort_array(arr, false) FROM test_sort_array_nested | ||
|
|
||
| statement | ||
| CREATE TABLE test_sort_array_nested_struct(arr array<array<struct<a:int>>>) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_sort_array_nested_struct VALUES | ||
| (array( | ||
| array(named_struct('a', 2)), | ||
| array(named_struct('a', 1)))), | ||
| (array()), | ||
| (NULL) | ||
|
|
||
| query expect_fallback(Sort on array element type ArrayType(StructType(StructField(a,IntegerType) | ||
| SELECT sort_array(arr) FROM test_sort_array_nested_struct | ||
|
|
||
| query expect_fallback(Sort on array element type ArrayType(StructType(StructField(a,IntegerType) | ||
| SELECT sort_array(arr, false) FROM test_sort_array_nested_struct | ||
|
|
||
| -- literal arguments | ||
| query | ||
| SELECT | ||
| sort_array(array(3, 1, 4, 1, 5)), | ||
| sort_array(array(3, 1, 4, 1, 5), true), | ||
| sort_array(array(3, NULL, 1, NULL, 2)), | ||
| sort_array(array(3, NULL, 1, NULL, 2), false), | ||
| sort_array(array(CAST('NaN' AS DOUBLE), 1.0, NULL, -0.0, 0.0)), | ||
| sort_array(array(CAST('NaN' AS DOUBLE), 1.0, NULL, -0.0, 0.0), false), | ||
| sort_array(array(CAST(100 AS DECIMAL(10, 0)), CAST(10 AS DECIMAL(10, 0)))), | ||
| sort_array( | ||
| array(CAST(100 AS DECIMAL(10, 0)), CAST(10 AS DECIMAL(10, 0))), | ||
| false), | ||
| sort_array(array(true, false, true, false)), | ||
| sort_array(array(true, false, true, NULL, false)), | ||
| sort_array(array(true, false, true, NULL, false), false), | ||
| sort_array( | ||
| array( | ||
| named_struct('a', 2, 'b', 'b'), | ||
| named_struct('a', 1, 'b', 'c'), | ||
| named_struct('a', 1, 'b', 'a'))), | ||
| sort_array(array(array(2, 3), array(1), array(2, 1))), | ||
| sort_array(array(array(1, NULL), array(1), NULL)), | ||
| sort_array(array(NULL, NULL)), | ||
| sort_array(cast(NULL as array<int>)) | ||
|
|
||
| query expect_fallback(Sort on array element type ArrayType(StructType(StructField(a,IntegerType) | ||
| SELECT sort_array( | ||
| array( | ||
| array(named_struct('a', 2)), | ||
| array(named_struct('a', 1)))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a comment explaining why there is a restriction around structs in arrays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I have added it. Besides, I found nulltype has a similar problem, I have fixed it.