Skip to content

fix: Aggregation function in LINQ expressions #510

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

Merged
merged 4 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ jobs:
- image: *default-dotnet-image
steps:
- checkout
- run: |
sed -i '/<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0<\/TargetFrameworks>/c\<TargetFramework>'net7.0'<\/TargetFramework>' Client.Core.Test/Client.Core.Test.csproj
sed -i '/<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0<\/TargetFrameworks>/c\<TargetFramework>'net7.0'<\/TargetFramework>' Client.Test/Client.Test.csproj
sed -i '/<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0<\/TargetFrameworks>/c\<TargetFramework>'net7.0'<\/TargetFramework>' Client.Legacy.Test/Client.Legacy.Test.csproj
sed -i '/<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0<\/TargetFrameworks>/c\<TargetFramework>'net7.0'<\/TargetFramework>' Client.Linq.Test/Client.Linq.Test.csproj
sed -i '/<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0<\/TargetFrameworks>/c\<TargetFramework>'net7.0'<\/TargetFramework>' Examples/Examples.csproj
- run:
name: Check compilation warnings
command: |
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 4.12.0 [unreleased]

### Bug Fixes
- [#510](https://github.com/influxdata/influxdb-client-csharp/pull/510): Passing aggregation function to AggregateWindow for LINQ queries

### Dependencies
Update dependencies:

Expand Down
16 changes: 16 additions & 0 deletions Client.Linq.Test/InfluxDBQueryVisitorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,22 @@ where s.Timestamp.AggregateWindow(TimeSpan.FromSeconds(20), TimeSpan.FromSeconds
Assert.AreEqual("mean", (fnAssignment.Init as Identifier)?.Name);
}

[Test]
public void AggregateWindowCustomFunction()
{
var query = from s in InfluxDBQueryable<Sensor>.Queryable("my-bucket", "my-org", _queryApi)
where s.Timestamp.AggregateWindow(TimeSpan.FromSeconds(20), TimeSpan.FromSeconds(40), "min")
where s.Value == 5
select s;

var visitor = BuildQueryVisitor(query);
var ast = visitor.BuildFluxAST();

var fnAssignment = ((OptionStatement)ast.Body[4]).Assignment as VariableAssignment;
Assert.AreEqual("p5", fnAssignment?.Id.Name);
Assert.AreEqual("min", (fnAssignment.Init as Identifier)?.Name);
}

[Test]
public void AggregateWindowFluxQuery()
{
Expand Down
2 changes: 1 addition & 1 deletion Client.Linq/Internal/QueryExpressionTreeVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected override Expression VisitMethodCall(MethodCallExpression expression)
//
var fn = ((ConstantExpression)expression.Arguments[3]).Value as string;
Arguments.CheckNonEmptyString(fn, "fn");
var fnVariable = _context.Variables.AddNamedVariable(new Identifier("Identifier", "mean"));
var fnVariable = _context.Variables.AddNamedVariable(new Identifier("Identifier", fn));

_context.QueryAggregator.AddAggregateWindow(everyVariable, periodVariable, fnVariable);

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy