You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ignite.apache.org by Roman Guseinov <ro...@gromtech.ru> on 2018/06/21 03:26:16 UTC

.NET - Complex LINQ queries support

Hi Team,

Is there any plan to support LINQ queries like:

var result = cache.AsCacheQueryable
  .Where(entry => !entry.Value.Dirty.HasValue)
  .GroupBy(entry => entry.Value.ContractId)
  .Select(group => group.OrderByDescending(entry =>
entry.Value.Version).First().Key)
  .ToList();

It looks like such queries need be transformed to complex SQL like `SELECT
... FROM (SELECT ... FROM (SELECT ...) JOIN ...)`. And probably that's why
it's not easy to implement such functionality, but users quite often want to
use that.

Will it be implemented in the near future? Is there any ticket for that?

Thanks.

Best Regards,
Roman 



--
Sent from: http://apache-ignite-developers.2346864.n4.nabble.com/

Re: .NET - Complex LINQ queries support

Posted by Roman Guseinov <ro...@gromtech.ru>.
Hi Pavel, 

Thank you a lot for the response. 

Best Regards,
Roman



--
Sent from: http://apache-ignite-developers.2346864.n4.nabble.com/

Re: .NET - Complex LINQ queries support

Posted by Pavel Tupitsyn <pt...@apache.org>.
Roman,

Thanks for the reproducer. I needed that to better understand the issue.

And, I'm afraid, we won't have support for this kind of queries anytime
soon.
Even Entity Framework does not support this kind of grouping.

On Fri, Jun 22, 2018 at 1:18 PM Roman Guseinov <ro...@gromtech.ru> wrote:

> Hi Pavel,
>
> Thank you for the response. Yes, your LINQ example can be a workaround. And
> SQL query can be as well.
>
> The small project with LINQ query example can be found here
> https://github.com/gromtech/ignite-linq-issue-reproducer
>
> I just want to know if there any plans to support such LINQ queries in the
> future.
>
> It doesn't block anything (a lot of workarounds) but if this is going to be
> implemented someday, I think users will be happy.
>
> Thanks again.
>
> Best Regards,
> Roman
>
>
>
> --
> Sent from: http://apache-ignite-developers.2346864.n4.nabble.com/
>

Re: .NET - Complex LINQ queries support

Posted by Roman Guseinov <ro...@gromtech.ru>.
Hi Pavel,

Thank you for the response. Yes, your LINQ example can be a workaround. And
SQL query can be as well.

The small project with LINQ query example can be found here
https://github.com/gromtech/ignite-linq-issue-reproducer 

I just want to know if there any plans to support such LINQ queries in the
future.

It doesn't block anything (a lot of workarounds) but if this is going to be
implemented someday, I think users will be happy.

Thanks again. 

Best Regards,
Roman



--
Sent from: http://apache-ignite-developers.2346864.n4.nabble.com/

Re: .NET - Complex LINQ queries support

Posted by Pavel Tupitsyn <pt...@apache.org>.
Roman,

Can you try rephrasing the LINQ query as the SQL goes?

var q1 = queryable.GroupBy(o => o.Value.ContractId).Select(g => new
{ContractId = g.Key, MaxVer = g.Select(x=>x.Value.Version).Max()});
var q2 = q1.Select( ...)

At least this first part works for me. I did not try further.

Ideally please provide a full working project with the LINQ expression that
does not work for you.
I'm trying to understand if there is a limitation or a bug of some kind.

Thanks,
Pavel

On Thu, Jun 21, 2018 at 1:09 PM, Roman Guseinov <ro...@gromtech.ru> wrote:

> Hi Pavel,
>
> Thank you for the response. Regarding support every LINQ expression, I
> agree
> with you. It's not possible.
>
> Let me show an example. The following LINQ query:
>
> /var result = queryable.GroupBy(e => e.Value.ContractId).Select(group =>
> new
> {
>     ContractId = group.Key,
>     Id = group.OrderByDescending(entry => entry.Value.Version).First().Key
> }).OrderBy(g => g.Count).ToList();/
>
> we can replace by SQL query:
>
> /SELECT cid as ContractId,
>        min(id) as Id
> FROM
>   (SELECT t2.cid,
>           t3.id
>    FROM
>      (SELECT t1.ContractId AS cid, max(t1.Version) AS ver
>       FROM table AS t1
>       GROUP BY t1.ContractId) AS t2
>    JOIN table AS t3 ON t3.Version = t2.ver
>    AND t3.ContractId = t2.cid)
> GROUP BY cid/
>
> I know this is not a trivial task and it can not be implemented easily. I
> just curious if there any plans to support that in the near future.
>
> Thanks again.
>
> Best Regards,
> Roman
>
>
>
> --
> Sent from: http://apache-ignite-developers.2346864.n4.nabble.com/
>

Re: .NET - Complex LINQ queries support

Posted by Roman Guseinov <ro...@gromtech.ru>.
Hi Pavel,

Thank you for the response. Regarding support every LINQ expression, I agree
with you. It's not possible.

Let me show an example. The following LINQ query:

/var result = queryable.GroupBy(e => e.Value.ContractId).Select(group => new
{
    ContractId = group.Key,
    Id = group.OrderByDescending(entry => entry.Value.Version).First().Key
}).OrderBy(g => g.Count).ToList();/

we can replace by SQL query:

/SELECT cid as ContractId,
       min(id) as Id
FROM
  (SELECT t2.cid,
          t3.id
   FROM
     (SELECT t1.ContractId AS cid, max(t1.Version) AS ver
      FROM table AS t1
      GROUP BY t1.ContractId) AS t2
   JOIN table AS t3 ON t3.Version = t2.ver
   AND t3.ContractId = t2.cid)
GROUP BY cid/

I know this is not a trivial task and it can not be implemented easily. I
just curious if there any plans to support that in the near future.

Thanks again.

Best Regards,
Roman



--
Sent from: http://apache-ignite-developers.2346864.n4.nabble.com/

Re: .NET - Complex LINQ queries support

Posted by Pavel Tupitsyn <pt...@apache.org>.
Hi Roman,

It is even hard to say what kind of SQL should we produce for such a query.

The general idea of Ignite LINQ provider is:
Do not try to support every LINQ expression (which is not possible, because
LINQ and SQL are quite different);
but try to make most SQL scenarios possible to express in LINQ.

So think SQL first.
For your case, can you give more details? What is the SQL query you'd like
to covert to LINQ?

Thanks,
Pavel

On Thu, Jun 21, 2018 at 6:26 AM, Roman Guseinov <ro...@gromtech.ru> wrote:

> Hi Team,
>
> Is there any plan to support LINQ queries like:
>
> var result = cache.AsCacheQueryable
>   .Where(entry => !entry.Value.Dirty.HasValue)
>   .GroupBy(entry => entry.Value.ContractId)
>   .Select(group => group.OrderByDescending(entry =>
> entry.Value.Version).First().Key)
>   .ToList();
>
> It looks like such queries need be transformed to complex SQL like `SELECT
> ... FROM (SELECT ... FROM (SELECT ...) JOIN ...)`. And probably that's why
> it's not easy to implement such functionality, but users quite often want
> to
> use that.
>
> Will it be implemented in the near future? Is there any ticket for that?
>
> Thanks.
>
> Best Regards,
> Roman
>
>
>
> --
> Sent from: http://apache-ignite-developers.2346864.n4.nabble.com/
>