-
Notifications
You must be signed in to change notification settings - Fork 297
fix: audit array_insert expression for correctness and test coverage #3890
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
andygrove
wants to merge
3
commits into
apache:main
Choose a base branch
from
andygrove:audit-array-insert
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
3 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
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,32 @@ | ||
| <!-- | ||
| 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. | ||
| --> | ||
|
|
||
| # Expression Audit Log | ||
|
|
||
| This document tracks which Comet expressions have been audited against their Spark | ||
| implementations for correctness and test coverage. | ||
|
|
||
| Each audit compares the Comet implementation against the Spark source code for the listed | ||
| versions, reviews existing test coverage, identifies gaps, and adds missing tests where needed. | ||
|
|
||
| ## Audited Expressions | ||
|
|
||
| | Expression | Spark Versions Checked | Date | Findings | | ||
| | -------------- | ---------------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | `array_insert` | 3.4.3, 3.5.8, 4.0.1 | 2026-04-02 | No behavioral differences across Spark versions. Fixed `nullable()` metadata bug (did not account for `pos_expr`). Added SQL tests for multiple types (string, boolean, double, float, long, short, byte), literal arguments, null handling, negative indices, out-of-bounds padding, special float values (NaN, Infinity), multibyte UTF-8, and legacy negative index mode. Known incompatibility: pos=0 error message differs from Spark's `INVALID_INDEX_OF_ZERO`. | | ||
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
57 changes: 57 additions & 0 deletions
57
spark/src/test/resources/sql-tests/expressions/array/array_insert_legacy.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,57 @@ | ||
| -- 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. | ||
|
|
||
| -- Tests for array_insert with legacy negative index mode enabled. | ||
| -- In legacy mode, -1 inserts BEFORE the last element (not after). | ||
|
|
||
| -- ConfigMatrix: parquet.enable.dictionary=false,true | ||
| -- Config: spark.comet.expression.ArrayInsert.allowIncompatible=true | ||
| -- Config: spark.sql.legacy.negativeIndexInArrayInsert=true | ||
|
|
||
| -- -1 inserts before last element in legacy mode | ||
| query | ||
| SELECT array_insert(array(1, 2, 3), -1, 10) | ||
|
|
||
| -- -2 inserts before second-to-last | ||
| query | ||
| SELECT array_insert(array(1, 2, 3), -2, 10) | ||
|
|
||
| -- -3 inserts before first element | ||
| query | ||
| SELECT array_insert(array(1, 2, 3), -3, 10) | ||
|
|
||
| -- negative beyond start with null padding (legacy mode pads differently) | ||
| query | ||
| SELECT array_insert(array(1, 2, 3), -5, 10) | ||
|
|
||
| -- far negative beyond start | ||
| query | ||
| SELECT array_insert(array(1, 3, 4), -2, 2) | ||
|
|
||
| -- column-based test | ||
| statement | ||
| CREATE TABLE test_ai_legacy(arr array<int>, pos int, val int) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_ai_legacy VALUES | ||
| (array(1, 2, 3), -1, 10), | ||
| (array(4, 5), -1, 20), | ||
| (array(1, 2, 3), -4, 10), | ||
| (NULL, -1, 10) | ||
|
|
||
| query | ||
| SELECT array_insert(arr, pos, val) FROM test_ai_legacy |
Oops, something went wrong.
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.
I think it is important to keep track of which expressions have been audited and against which Spark versions. Maintaining a markdown doc is one approach. Another approach could be to add comments and/or annotations directly in the code in the serde handlers.