Skip to content

Added support for compute() transformation in $apply - #1877

Merged
mikepizzo merged 17 commits into
OData:masterfrom
kosinsky:features/ComputeTransform
Feb 26, 2020
Merged

Added support for compute() transformation in $apply#1877
mikepizzo merged 17 commits into
OData:masterfrom
kosinsky:features/ComputeTransform

Conversation

@kosinsky

@kosinsky kosinsky commented Aug 2, 2019

Copy link
Copy Markdown
Contributor

Description

Known limitation: compute() transformation must be used with groupby or aggregate. So we couldn't do $apply=compute(1 as Test) that is the same as $compute=1 as Test. Limitation caused by the same problem as not supporting $select after $apply.

Issues

Fixes scenario from issue #793

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

@kosinsky
kosinsky force-pushed the features/ComputeTransform branch from c15808b to b38ea6c Compare August 2, 2019 21:34
@madansr7 madansr7 added the Ready for review Use this label if a pull request is ready to be reviewed label Aug 21, 2019
@madansr7 madansr7 added this to the 7.3 milestone Aug 21, 2019
Comment thread src/Microsoft.AspNet.OData.Shared/Query/Expressions/ComputeBinder.cs Outdated
@xuzhg

xuzhg commented Oct 3, 2019

Copy link
Copy Markdown
Member

@kosinsky i re-based the PR on the latest master. It seems some test cases are failing. Would you please take a look if you think it's better to release in 7.2.2 release. #Closed

@SenyaMur

SenyaMur commented Nov 14, 2019

Copy link
Copy Markdown

When it will be merged and when available for getting from nuget?
It will be available in Net Core 3.0 (#1748 ) ? #Closed

@kosinsky

kosinsky commented Nov 14, 2019

Copy link
Copy Markdown
Contributor Author

These features (compute() and Core 3.0) aren't related. And compute() implementation doesn't do anything that could affect Core 3.0 #Closed

@KanishManuja-MS

KanishManuja-MS commented Nov 15, 2019

Copy link
Copy Markdown
Contributor

@SenyaMur It should be available with the next release. .Net Core support may come after the next release. As @kosinsky pointed out, this feature will carry forward to the .Net Core support release. #Closed

@SenyaMur

SenyaMur commented Nov 15, 2019

Copy link
Copy Markdown

@KanishManuja-MS When will be available next release or pre-release? #Closed

@VenuMadhavPerumalla

VenuMadhavPerumalla commented Jan 4, 2020

Copy link
Copy Markdown

@KanishManuja-MS - I see that issue is still open. Can you please let me know when this will be available #Closed

@KanishManuja-MS

KanishManuja-MS commented Jan 6, 2020

Copy link
Copy Markdown
Contributor

@VenuMadhavPerumalla We will try to get this in our next WebAPI release. Thanks! #Closed

@GitMonkey007

GitMonkey007 commented Jan 6, 2020

Copy link
Copy Markdown

@KanishManuja-MS - could you advise when the next WebAPI release will be? We’d also find this functionality useful... #Closed

@KanishManuja-MS

KanishManuja-MS commented Jan 7, 2020

Copy link
Copy Markdown
Contributor

@GitMonkey007 We don't have date put down as of now but I would imagine towards the end of the month or early February. In the meanwhile, I encourage you to review this PR to see if it meets all your needs. #Closed

@kosinsky
kosinsky force-pushed the features/ComputeTransform branch from bcffaee to 18460a0 Compare January 14, 2020 18:20
@kosinsky
kosinsky force-pushed the features/ComputeTransform branch from 18460a0 to d952eac Compare January 14, 2020 20:41
case Linq2ObjectsQueryProviderNamespace:
// EF Core before 3.0 does a lot of client evaluations and has InMemory support which is the same as Linq2Objects
case ObjectContextQueryProviderNamespaceEFCore2:

@mikepizzo mikepizzo Jan 21, 2020

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.

Isn't this a breaking change? #Resolved

@kosinsky kosinsky Jan 27, 2020

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.

Potentially. However, if you try to create expressions like $filter=length(Field) gt 10 when backed by EF InMemory it will throw with version of code that in master now. That's a bug.

When we generate IQueryable provided by EF and we have something like

x => x.Field.Length > 10

we assumed that EF will pass that operation to the SQL in a form

LEN(Field) > 10

If Field is null it will; work in SQL, but executed directly C# expression throw exception and we have to convert if to

x => x.Field == null ? false : x.Field.Length > 10

We are doing it for linq to objects, but not EF InMemory #Resolved

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.

@mikepizzo Looks like we don't have tests for $filter and EF Core. Do you want me to:

  • Create separate PR to add these tests
  • Add these test to this PR
  • Create an issue to work on extra EF Core tests after this PR is megred

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.

I'm fine with a separate PR for EF Core tests so that we don't hold up this PR any longer -- thanks!

@mikepizzo mikepizzo modified the milestones: 7.3, 7.4 Beta Feb 11, 2020
Comment thread src/Microsoft.AspNet.OData.Shared/Query/Expressions/DynamicTypeWrapper.cs Outdated
Comment thread src/Microsoft.AspNet.OData.Shared/Query/Expressions/TransformationBinderBase.cs Outdated
Comment thread src/Microsoft.AspNet.OData.Shared/Query/Expressions/DynamicTypeWrapper.cs Outdated
Comment thread src/Microsoft.AspNet.OData.Shared/Query/Expressions/DynamicTypeWrapper.cs Outdated
{
// Add real OData properties to the collection
// We need to use injected Model to real proeprty names
var edmType = GetEdmType() as IEdmEntityTypeReference;

@mikepizzo mikepizzo Feb 23, 2020

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.

IEdmEntityTypeReference [](start = 50, length = 23)

Will this cast always succeed, or might GetEdmType return something besides an IEdmEntityTypeReference?
What about complex types? #Resolved

@kosinsky kosinsky Feb 25, 2020

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.

For this PR (adding compute() to $apply), it should be true all the time, because we are using only EntitySet?$apply=....

When we will work on $apply inside $expand (I have that feature in my fork). For queries like:
EntitySet?$expand=ComplexTypeCollection($apply=...) it will change. I think it will be really difficult to validate that ComputeWrapper works for complex types new before implementing $expand($apply) and/or $expand($compute) #Resolved

Comment thread src/Microsoft.AspNet.OData.Shared/Query/Expressions/ExpressionBinderBase.cs Outdated
@mikepizzo

Copy link
Copy Markdown
Contributor

Hoping to get a beta release out next week, with RTM a couple of weeks after, depending on feedback.


In reply to: 571371458 [](ancestors = 571371458)

@mikepizzo mikepizzo left a 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.

A few minor comments, mostly regarding:

  1. Ability to apply Compute() to a complex type
  2. Would prefer to provide a cleaner mechanism for mutating state than exposing fields from base types

Also a few minor spelling issues, but other than that it looks good -- thanks, and apologies for taking so long to get this reviewed!

Comment thread src/Microsoft.AspNet.OData.Shared/Query/Expressions/TransformationBinderBase.cs Outdated

@mikepizzo mikepizzo left a 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.

:shipit:

Changes look good to me; thanks for the quick follow-up @kosinsky. Let me know if you are planning any additional changes or if this is ready to merge once CI completes.

@kosinsky

Copy link
Copy Markdown
Contributor Author

I'm not planning any additional changes. It's good to go as soon as CI completes. However, CI stuck in "waiting for status to be reported". Looks like build wasn't even started.

@mikepizzo

Copy link
Copy Markdown
Contributor

Was able to run CI and verify, although pipeline was unable to post results back to GitHub.

@mikepizzo
mikepizzo merged commit 279f60d into OData:master Feb 26, 2020
@computrengineer

Copy link
Copy Markdown

Working great for us so far! Thanks everyone!! :)

@SenyaMur

SenyaMur commented Mar 6, 2020

Copy link
Copy Markdown

How to get this feature ?

xuzhg added a commit that referenced this pull request May 29, 2026
* Added support for functions and constants in aggregate expression

* Tests for more cannonical functions

* Time tests

* Support for compute transformation in $apply

* Support sorting for columns introduced in compute

* Remove redundant code

* Fix flakyness in AggregateNavigationPropertyWorks

* Fix the ToInt16 overflow during build

* Fix typos

* Make _values field private

* Explicit way to mutate element type and lambda param

* Test to demonstrate that we could run compute on complex entity properties

* Support for complex types

* Simplify keepoing ElementType and LambdaParameter in sync

Co-authored-by: Sam Xu <saxu@microsoft.com>
pull Bot pushed a commit to ehtick/WebApi that referenced this pull request May 29, 2026
* Added support for functions and constants in aggregate expression

* Tests for more cannonical functions

* Time tests

* Support for compute transformation in $apply

* Support sorting for columns introduced in compute

* Remove redundant code

* Fix flakyness in AggregateNavigationPropertyWorks

* Fix the ToInt16 overflow during build

* Fix typos

* Make _values field private

* Explicit way to mutate element type and lambda param

* Test to demonstrate that we could run compute on complex entity properties

* Support for complex types

* Simplify keepoing ElementType and LambdaParameter in sync

Co-authored-by: Sam Xu <saxu@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Use this label if a pull request is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OData Core Throws null reference exception when trying to execute

9 participants