Skip to content

SQL-3387: Implement support for ARRAY_REMOVE with proper semantics - #194

Open
mattChiaravalloti wants to merge 2 commits into
mongodb:mainfrom
mattChiaravalloti:SQL-3387
Open

SQL-3387: Implement support for ARRAY_REMOVE with proper semantics#194
mattChiaravalloti wants to merge 2 commits into
mongodb:mainfrom
mattChiaravalloti:SQL-3387

Conversation

@mattChiaravalloti

Copy link
Copy Markdown
Collaborator

This PR concludes the array functions work for the Dialect Improvement project. It implements support for ARRAY_REMOVE with the intended semantics; that is, it supports ARRAY_REMOVE such that null elements are not removed from the array unless the specified value to remove is itself null. See the spec/query tests for details.

The ticket proposed indicating the FilterExpr include a flag to force MQL semantics (as opposed to SQL 3-value null semantics) but I ultimately decided to push that lower, to the expression nested within the FilterExpr. The reason I did this is because it is really the Neq expression within the rewrite that needs to force MQL semantics, not the FilterExpr itself. That flag would be too powerful and ambiguous if it was available at the FilterExpr level.

I documented at the ast and mir levels why the flag exists so that future implementors could avoid misusing it.

Apologies for the size of the PR. It is mostly a consequence of adding a new flag to two pretty popular structs. For the most part, the only relevant files are parsers/mongosql.lalrpop, ast/definitions.rs, ast/rewrites/higher_order_functions.rs, algebrizer/definitions.rs, mir/definitions.rs, translator/{expression.rs, util.rs}, and tests/spec_tests/query_tests/array_functions.yml. All other files are incidental updates that simply introduce the new flag with the default value (false). I did add unit testing for relevant functions, if you are interested in those.

@mattChiaravalloti
mattChiaravalloti requested a review from a team as a code owner August 26, 2026 15:28

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are looking in GitHub order, this is the first file you'll see. This is pretty much what you'll see in all test files! The flag is introduced with the false value wherever necessary. In some files my IDE also made local edits removing extraneous commas and newlines. It looks like none of those types of edits are in this file but that's the only other type of change you'll see in test files.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thile includes a mod force_mql_semantics at the bottom with new unit test coverage.

function,
is_nullable,
args,
force_mql_semantics,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only ast struct that defines force_mql_semantics is ast::BinaryExpr. That is why this is the only spot where we set the value. All other locations use false.

is_nullable: sf.is_nullable,
args: vec![arg.clone(), top],
force_mql_semantics: sf.force_mql_semantics,
is_nullable: arg_is_nullable || top_is_nullable,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚗 drive-by minor correctness improvement here. It's actually inconsequential given the way this entire module is implemented but it's better to be correct here in case other changes are made around this later.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains unit tests for relevant functions.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant