-
Notifications
You must be signed in to change notification settings - Fork 373
test: restore ANSI array access error coverage #5798
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
Changes from all commits
dae9a08
c1fd270
f25e014
a4b81b7
91cc1b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,34 +25,39 @@ | |
| -- ============================================================================ | ||
|
|
||
| statement | ||
| CREATE TABLE ansi_array_oob(arr array<int>) USING parquet | ||
| CREATE TABLE ansi_array_oob(arr array<int>, positive_idx int, negative_idx int) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO ansi_array_oob VALUES (array(1, 2, 3)) | ||
| INSERT INTO ansi_array_oob VALUES (array(1, 2, 3), 5, -1) | ||
|
|
||
| -- Valid boundary indices must run natively as well as match Spark. | ||
| query | ||
| SELECT arr[0], arr[2] FROM ansi_array_oob | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding these valid boundary queries is the right instinct given Since you are pinning boundaries anyway, would it be worth pairing them with the first invalid index too?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok , I will address it |
||
|
|
||
| -- ============================================================================ | ||
| -- Array index out of bounds (positive index) | ||
| -- Spark throws: [INVALID_ARRAY_INDEX] The index X is out of bounds | ||
| -- Comet throws: Index out of bounds for array | ||
| -- See https://github.com/apache/datafusion-comet/issues/3375 | ||
| -- Spark and Comet throw INVALID_ARRAY_INDEX in ANSI mode. | ||
| -- ============================================================================ | ||
|
|
||
| -- index beyond array length should throw (0-based indexing) | ||
| query ignore(https://github.com/apache/datafusion-comet/issues/3375) | ||
| query expect_error([INVALID_ARRAY_INDEX]) | ||
| SELECT arr[3] FROM ansi_array_oob | ||
|
|
||
| query expect_error([INVALID_ARRAY_INDEX]) | ||
| SELECT arr[10] FROM ansi_array_oob | ||
|
|
||
| -- literal array with out of bounds access | ||
| query ignore(https://github.com/apache/datafusion-comet/issues/3375) | ||
| SELECT array(1, 2, 3)[5] | ||
| -- Use a column index so SimplifyExtractValueOps cannot replace the lookup with NULL. | ||
| query expect_error([INVALID_ARRAY_INDEX]) | ||
| SELECT array(1, 2, 3)[positive_idx] FROM ansi_array_oob | ||
|
|
||
| -- ============================================================================ | ||
| -- Array index out of bounds (negative index) | ||
| -- ============================================================================ | ||
|
|
||
| -- negative index should throw | ||
| query ignore(https://github.com/apache/datafusion-comet/issues/3375) | ||
| query expect_error([INVALID_ARRAY_INDEX]) | ||
| SELECT arr[-1] FROM ansi_array_oob | ||
|
|
||
| -- literal with negative index | ||
| query ignore(https://github.com/apache/datafusion-comet/issues/3375) | ||
| SELECT array(1, 2, 3)[-1] | ||
| -- literal array with a negative column index | ||
| query expect_error([INVALID_ARRAY_INDEX]) | ||
| SELECT array(1, 2, 3)[negative_idx] FROM ansi_array_oob | ||
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.
Same thought as on the
get_array_itemfile. Would it be worth pairing the valid boundaries with the first invalid index rather than only 10 and -10?element_at(arr, 4)andelement_at(arr, -4)are where an off-by-one inone_based_indexinnative/spark-expr/src/array_funcs/list_extract.rswould actually surface, and the far out of range values would not catch it. Both behave correctly today, so this is just locking in what already works.One more line while you are in here would be useful.
SELECT element_at(arr, CAST(NULL AS INT)) FROM ansi_element_at_oobreturns NULL rather than throwing even under ANSI, and nothing in this file guards that branch.