Repository: ignite
Updated Branches:
  refs/heads/master a11bcf597 -> 64d920bf5


IGNITE-7889: .NET: LINQ: Fix GroupBy with Where

This closes #3608


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/64d920bf
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/64d920bf
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/64d920bf

Branch: refs/heads/master
Commit: 64d920bf59e18b383f7e2f230f8f4087406e38fe
Parents: a11bcf5
Author: Alexey Popov <tank2.a...@gmail.com>
Authored: Tue Mar 6 20:47:18 2018 +0300
Committer: Pavel Tupitsyn <ptupit...@apache.org>
Committed: Tue Mar 6 20:47:18 2018 +0300

----------------------------------------------------------------------
 .../Cache/Query/Linq/CacheLinqTest.Functions.cs | 48 ++++++++++++++++++++
 .../Impl/CacheQueryModelVisitor.cs              |  4 ++
 2 files changed, 52 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/64d920bf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Functions.cs
----------------------------------------------------------------------
diff --git 
a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Functions.cs
 
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Functions.cs
index a672d5a..a6632d9 100644
--- 
a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Functions.cs
+++ 
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Functions.cs
@@ -110,6 +110,54 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Linq
         }
 
         /// <summary>
+        /// Tests the GroupBy with Where subquery.
+        /// </summary>
+        [Test]
+        public void TestGroupBySubquery()
+        {
+            var persons = GetPersonCache().AsCacheQueryable().Where(p => 
p.Value.OrganizationId == 1000);
+            var orgs = GetOrgCache().AsCacheQueryable();
+
+            // Simple, unordered
+            CollectionAssert.AreEquivalent(new[] { 1000 },
+                persons.GroupBy(x => x.Value.OrganizationId).Select(x => 
x.Key).ToArray());
+
+            // Aggregate
+            Assert.AreEqual(1000,
+                persons.GroupBy(x => x.Value.OrganizationId).Select(x => 
x.Key).OrderBy(x => x).First());
+
+            // Ordering and count
+            var res1 =
+                from p in persons
+                orderby p.Value.Name
+                group p by p.Value.OrganizationId
+                into gs
+                orderby gs.Key
+                where gs.Count() > 10
+                select new { Count = gs.Count(), OrgId = gs.Key, AvgAge = 
gs.Average(x => x.Value.Age) };
+
+            var resArr = res1.ToArray();
+
+            Assert.AreEqual(new[]
+            {
+                new {Count = PersonCount/2, OrgId = 1000, AvgAge = (double) 
PersonCount/2 - 1},
+            }, resArr);
+
+            // Join and sum
+            var res2 = persons.Join(orgs.Where(o => o.Key > 10), p => 
p.Value.OrganizationId, o => o.Key,
+                    (p, o) => new { p, o })
+                .GroupBy(x => x.o.Value.Name)
+                .Select(g => new { Org = g.Key, AgeSum = g.Select(x => 
x.p.Value.Age).Sum() });
+
+            var resArr2 = res2.ToArray();
+
+            Assert.AreEqual(new[]
+            {
+                new {Org = "Org_0", AgeSum = persons.Where(x => 
x.Value.OrganizationId == 1000).Sum(x => x.Value.Age)},
+            }, resArr2);
+        }
+
+        /// <summary>
         /// Tests the union.
         /// </summary>
         [Test]

http://git-wip-us.apache.org/repos/asf/ignite/blob/64d920bf/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs
----------------------------------------------------------------------
diff --git 
a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs 
b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs
index 56c3ff5..223eea6 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs
@@ -374,6 +374,10 @@ namespace Apache.Ignite.Linq.Impl
             foreach (var join in 
subQuery.QueryModel.BodyClauses.OfType<JoinClause>())
                 VisitJoinClause(join, queryModel, i++);
 
+            i = 0;
+            foreach (var where in 
subQuery.QueryModel.BodyClauses.OfType<WhereClause>())
+                VisitWhereClause(where, i++, false);
+
             // Append grouping
             _builder.Append("group by (");
 

Reply via email to