From 080a75fc7743488a52c810dcd224ff3d9f474b51 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Thu, 27 Apr 2023 11:01:37 +0200 Subject: [PATCH 1/4] fix: Aggregation function in LINQ expressions --- Client.Linq.Test/InfluxDBQueryVisitorTest.cs | 16 ++++++++++++++++ .../Internal/QueryExpressionTreeVisitor.cs | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Client.Linq.Test/InfluxDBQueryVisitorTest.cs b/Client.Linq.Test/InfluxDBQueryVisitorTest.cs index 93a5ccf1c..3b5da9a7c 100644 --- a/Client.Linq.Test/InfluxDBQueryVisitorTest.cs +++ b/Client.Linq.Test/InfluxDBQueryVisitorTest.cs @@ -1038,6 +1038,22 @@ where s.Timestamp.AggregateWindow(TimeSpan.FromSeconds(20), TimeSpan.FromSeconds Assert.AreEqual("p5", fnAssignment?.Id.Name); Assert.AreEqual("mean", (fnAssignment.Init as Identifier)?.Name); } + + [Test] + public void AggregateWindowCustomFunction() + { + var query = from s in InfluxDBQueryable.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() diff --git a/Client.Linq/Internal/QueryExpressionTreeVisitor.cs b/Client.Linq/Internal/QueryExpressionTreeVisitor.cs index d1f7816b4..f3a4a65ca 100644 --- a/Client.Linq/Internal/QueryExpressionTreeVisitor.cs +++ b/Client.Linq/Internal/QueryExpressionTreeVisitor.cs @@ -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); From 8e02b76f82385934d0da92b9ab7995ca3008ba7d Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Thu, 27 Apr 2023 11:06:11 +0200 Subject: [PATCH 2/4] docs: update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f5a24419..9cc935bf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: From 98fdd7b4babd7de882be9473e4e7e228216b72d3 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Thu, 27 Apr 2023 11:14:17 +0200 Subject: [PATCH 3/4] fix: warnings --- .circleci/config.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index d2cc971c9..925d13c90 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -146,6 +146,12 @@ jobs: - image: *default-dotnet-image steps: - checkout + - run: | + sed -i '/netcoreapp3.1;net5.0;net6.0;net7.0<\/TargetFrameworks>/c\'net7.0'<\/TargetFramework>' Client.Core.Test/Client.Core.Test.csproj + sed -i '/netcoreapp3.1;net5.0;net6.0;net7.0<\/TargetFrameworks>/c\'net7.0'<\/TargetFramework>' Client.Test/Client.Test.csproj + sed -i '/netcoreapp3.1;net5.0;net6.0;net7.0<\/TargetFrameworks>/c\'net7.0'<\/TargetFramework>' Client.Legacy.Test/Client.Legacy.Test.csproj + sed -i '/netcoreapp3.1;net5.0;net6.0;net7.0<\/TargetFrameworks>/c\'net7.0'<\/TargetFramework>' Client.Linq.Test/Client.Linq.Test.csproj + sed -i '/netcoreapp3.1;net5.0;net6.0;net7.0<\/TargetFrameworks>/c\'net7.0'<\/TargetFramework>' Examples/Examples.csproj - run: name: Check compilation warnings command: | From 8672b9033d80a3558a48c19c8530abc1b266b884 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Thu, 27 Apr 2023 11:23:53 +0200 Subject: [PATCH 4/4] fix: code style --- Client.Linq.Test/InfluxDBQueryVisitorTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client.Linq.Test/InfluxDBQueryVisitorTest.cs b/Client.Linq.Test/InfluxDBQueryVisitorTest.cs index 3b5da9a7c..12ca8160e 100644 --- a/Client.Linq.Test/InfluxDBQueryVisitorTest.cs +++ b/Client.Linq.Test/InfluxDBQueryVisitorTest.cs @@ -1038,7 +1038,7 @@ where s.Timestamp.AggregateWindow(TimeSpan.FromSeconds(20), TimeSpan.FromSeconds Assert.AreEqual("p5", fnAssignment?.Id.Name); Assert.AreEqual("mean", (fnAssignment.Init as Identifier)?.Name); } - + [Test] public void AggregateWindowCustomFunction() { 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