-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Generate Unique alias for table names #4537
Conversation
var counter = 0; | ||
|
||
int _; | ||
if (int.TryParse(currentAlias.Substring(1), out _)) |
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.
we could change this to work the same for one letter aliases as well as multi letter aliases, i.e.
currently we have:
a -> a0, a1, a2
bb -> bb0, bb00, bb000
we should aim for
bb -> bb0, bb1, bb2, bb3
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.
updated.
20cec83
to
6801a7c
Compare
@@ -179,7 +179,7 @@ var materializer | |||
|
|||
selectExpression.Predicate = oldPredicate; | |||
selectExpression.RemoveTable(joinExpression); | |||
selectExpression.AddTable(newJoinExpression); | |||
selectExpression.AddTable(newJoinExpression, false); |
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.
Use named parameter to clarify false here.
e1ea21d
to
3394fba
Compare
@anpete - Updated with different approach. I checked few tests to verify that we are preserving user-defined names. |
6dcef4a
to
e1a7e5c
Compare
@@ -165,7 +165,7 @@ var predicate | |||
|
|||
if (predicate != null) | |||
{ | |||
var innerSelectExpression = handlerContext.SelectExpressionFactory.Create(); | |||
var innerSelectExpression = handlerContext.SelectExpressionFactory.Create(handlerContext.QueryModelVisitor.QueryCompilationContext); |
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.
break those long lines into 2 separate ones, we usually do something like:
var innerSelectExpression
= handlerContext.SelectExpressionFactory.Create(handlerContext.QueryModelVisitor...)
e1a7e5c
to
0890842
Compare
SELECT TOP(1) [subQuery0].[Id] | ||
FROM [Level2] AS [subQuery0] | ||
WHERE [subQuery0].[Level1_Optional_Id] = [e1].[Id] | ||
SELECT TOP(1) [subQuery00].[Id] |
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.
we can probably change the base generated name from "subquery0" to "subquery", since it's being uniquefied anyway
0890842
to
288db50
Compare
Updated with feedback. Added some tests. |
{ | ||
Check.NotNull(currentAlias, nameof(currentAlias)); | ||
|
||
if (string.Equals(currentAlias, "")) |
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.
Or, currentAlias.Length == 0
@smitpatel Is it just that not all test changes have been reverted from the earlier approach? Because, if not, it looks like we are still unique-fying too much. |
ef15f26
to
dbf2b98
Compare
Updated with 1 more change which reduced changes required.
Most changes in tests look to be consequence of one of the above. If there is any particular test which seems to be unique-fy extra then point me to it and I will investigate it. |
dbf2b98
to
074ef69
Compare
Update to above: |
@smitpatel Thanks for the clear explanation. 1,2 & 4 are OK. Can you see if there is any easy fix to 3? Otherwise |
074ef69
to
d307bc4
Compare
For point 3 I tried looking into avoiding it. But we traverse the queryModel 2 times and both generate different |
resolves #3826
Presently it is code change only. If approaches looks right then I will update SQL generated for tests and add more test to verify this scenario.