Skip to content

Make TableExpressionBase.Alias immutable #32815

Merged
roji merged 1 commit intodotnet:mainfrom
roji:ImmutableTableAliases
Jan 19, 2024
Merged

Make TableExpressionBase.Alias immutable #32815
roji merged 1 commit intodotnet:mainfrom
roji:ImmutableTableAliases

Conversation

@roji
Copy link
Copy Markdown
Member

@roji roji commented Jan 14, 2024

NOTE: THIS IS BASED ON TOP OF #32812, REVIEW ONLY THE LAST COMMIT ONLY

This completes the immutability work done in #32812; that PR got rid of the mutable TableReferenceExpression, and this one makes TableExpressionBase.TableAlias immutable. After this, the only mutability we have in our SQL query tree is SelectExpression itself being in temporary mutable mode during translation.

Also did some cleanup around table annotations.

Note: as an alternative design, I considered extracting Alias out of TableExpressionBase altogether, and moving it out to a TableAliasExpression (or AsExpression) which would wrap the table, adding the AS x part; this is very similar to what we do in the prjection with ProjectionExpression. However, this would make it considerably harder to work with tables when not caring about their aliases - which is the majority of the time.

@roji roji requested a review from a team January 14, 2024 14:39
@roji roji force-pushed the ImmutableTableAliases branch from c2b8510 to 341241f Compare January 14, 2024 17:37
@roji roji changed the title Make TableAliasExpression.Base immutable Make TableExpressionBase.Alias immutable Jan 14, 2024
@roji roji force-pushed the ImmutableTableAliases branch from 341241f to 02f0a42 Compare January 18, 2024 09:35
Copy link
Copy Markdown
Member Author

@roji roji left a comment

Choose a reason for hiding this comment

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

@maumar @dotnet/efteam here's the next PR in the query architecture stack, rebased on latest main and ready for review. This is a really simple one.

IEntityType entityType,
IReadOnlyList<SelectExpression> subSelectExpressions,
IEnumerable<IAnnotation>? annotations)
IReadOnlyDictionary<string, IAnnotation>? annotations)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@maumar the changes around annotations are to stop duplicating/copying them every time we copy/clone the table expression node; since they're immutable we just reuse the existing dictionary, as is standard with expressions.

// TODO: Either add a mandatory, abstract non-destructive ChangeAlias to TableExpressionBase, or ideally,
// TODO: refactor things to split the alias out of TableExpressionBase altogether.
table.Alias = newAlias;
table = table.WithAlias(newAlias);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was the one point left actually mutating aliases - an immutable copy of the table is now produced instead.

@roji roji force-pushed the ImmutableTableAliases branch from 02f0a42 to 4973e9b Compare January 18, 2024 09:54
And do some cleanup around table annotations

Continues work from dotnet#32558
@roji roji force-pushed the ImmutableTableAliases branch from 4973e9b to 078b677 Compare January 18, 2024 11:58
Copy link
Copy Markdown
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

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

Make sure that the TODO comments you added earlier have a tracking issue

@roji roji merged commit 19c30d6 into dotnet:main Jan 19, 2024
@roji roji deleted the ImmutableTableAliases branch January 19, 2024 00:09
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.

2 participants