Skip to content

Refactor & optimize ProjectionExpression, TranslatedQuery (#40)#181

Merged
alex-kulakov merged 9 commits intoDataObjects-NET:masterfrom
servicetitan:upstream/optimize_ProjectionExpression
Nov 24, 2021
Merged

Refactor & optimize ProjectionExpression, TranslatedQuery (#40)#181
alex-kulakov merged 9 commits intoDataObjects-NET:masterfrom
servicetitan:upstream/optimize_ProjectionExpression

Conversation

@SergeiPavlov
Copy link
Copy Markdown
Contributor

@SergeiPavlov SergeiPavlov commented Oct 26, 2021

  • Refactor & optimize ProjectionExpression, TranslatedQuery
  • ProjectExpression.Apply() method
  • Avoid list allocation when calling Translator.Translate()

* Refactor & optimize ProjectionExpression, TranslatedQuery

* EOL at EOF

* Fix Translator.TranslateMethod

* Get rid of Translator.TranslateMethod because we need not it for non-generic method

* Rename ProjectionExpression.Select() -> .Apply()

* Avoid list allocation when calling Translator.Translate()
Comment on lines +24 to +26
// Creates new ItemProjectorExpression, based on this but with new ItemProjectorExpression
public ProjectionExpression Apply(ItemProjectorExpression itemProjectorExpression) =>
new ProjectionExpression(Type, itemProjectorExpression, TupleParameterBindings, ResultAccessMethod);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Within translation we have ApplyProvider (also CompilableProviderExtensions.Apply), ApplyParameter, so I worry that this new Apply might be misunderstood while reading. Can we think of another name, like ApplyItemProjector or something else but kind of more specific?

What's the point of the comment if we can see it only when we look at the method itself and what the method does is pretty clear, btw it's misleading because it creates new ProjectionExpression with new item projector.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We had a discussion about this naming with @AlexUstinov
Here is his argument:

What do you think about renaming this to Apply?

 
@SergeiPavlov SergeiPavlov 26 days ago Author Member
The better name by Category theory would be Project(). We are projecting, applying projecter.
In LINQ .Select() makes a projection, that is why I named it Select

Apply seems to be very general word, any operation is application some function to arguments.

 
@AlexUstinov AlexUstinov 23 days ago Member
Select on the other hand is firmly associated with LINQ, so it adds a considerable level of confusion.
When I suggested Apply I thought about the typical use case

var newProjectionExpression = ProjectionExpression.Select(newItemProjector);
when one expression is being transformed to a new one by the instance of a Projector.
So there are two options here if we want to replace the select with something.
We either Apply (or it can be another synonym name like TransformWith) a Projector to the current expression instance as I suggested.

var newProjectionExpression = ProjectionExpression.Apply(newItemProjector);
or alternatively we can use a Projector to transform the expression and in that case the Project name you mentioned works just fine.

var newProjectionExpression = newItemProjector.Project(ProjectionExpression);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What's the point of the comment if we can see it only when we look at the method itself and what the method does is pretty clear, btw it's misleading because it creates new ProjectionExpression with new item projector.

Removed the comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Basically, @AlexUstinov brought the same reason for Select - it misleads the reader. I don't know whether he knows that 'Apply' has certain meaning during translation as well as 'Select' in LINQ.

In general, I agree with .Apply() because it fits the action, we have a lot of .Apply() methods outside translation, you can find them easily. But in translation we have dataSource.Apply(...) to wrap current datasouce with ApplyProvider and projection.Apply(...) that substitutes ItemProjector, which could be misleading

Comment thread Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs Outdated
Comment thread Orm/Xtensive.Orm/Orm/Linq/Translator.Materialization.cs Outdated
Comment thread Orm/Xtensive.Orm/Orm/Linq/Translator.Materialization.cs
Comment thread Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs Outdated
alex-kulakov
alex-kulakov previously approved these changes Nov 22, 2021
@alex-kulakov
Copy link
Copy Markdown
Contributor

@SergeiPavlov , please resolve merge conflicts and will merge the PR.

@SergeiPavlov
Copy link
Copy Markdown
Contributor Author

Resolved

@alex-kulakov
Copy link
Copy Markdown
Contributor

Thank you

@alex-kulakov alex-kulakov merged commit 5056f62 into DataObjects-NET:master Nov 24, 2021
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.

3 participants