This is an automated email from the ASF dual-hosted git repository.
gurustron pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 2b2b078 IGNITE-13336 .NET: Fix misleading exception when LINQ
expression can't be translated to SQL (#8459)
2b2b078 is described below
commit 2b2b07842ffc5512b0b1207ac4b03db887899862
Author: gurustron <[email protected]>
AuthorDate: Thu Nov 19 21:26:48 2020 +0300
IGNITE-13336 .NET: Fix misleading exception when LINQ expression can't be
translated to SQL (#8459)
* IGNITE-13336 - repro.
* IGNITE-13336 - exception message..
* IGNITE-13336 - tests.
---
.../Cache/Query/Linq/CacheLinqTest.Misc.cs | 28 ++++++++++++++++++++++
.../Impl/CacheQueryExpressionVisitor.cs | 6 ++---
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git
a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Misc.cs
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Misc.cs
index 6d26131..012f900 100644
---
a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Misc.cs
+++
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Misc.cs
@@ -27,11 +27,14 @@
namespace Apache.Ignite.Core.Tests.Cache.Query.Linq
{
using System;
+ using System.Collections.Generic;
using System.Linq;
+ using System.Linq.Expressions;
using Apache.Ignite.Core.Cache;
using Apache.Ignite.Core.Cache.Configuration;
using Apache.Ignite.Linq;
using NUnit.Framework;
+ using NUnit.Framework.Constraints;
/// <summary>
/// Tests LINQ.
@@ -353,5 +356,30 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Linq
Assert.IsTrue(ex.ToString().Contains("QueryCancelledException: The
query was cancelled while executing."));
}
+
+ /// <summary>
+ /// Tests that <see cref="InvocationExpression"/> is not supported.
+ /// </summary>
+ [Test]
+ public void TestInvokeThrowsNotSupportedException()
+ {
+ var constraint = new
ReusableConstraint(Is.TypeOf<NotSupportedException>()
+ .And.Message.StartsWith("The LINQ expression '")
+ .And.Message.Contains("Invoke")
+ .And.Message.Contains(
+ "could not be translated. Either rewrite the query in a
form that can be translated, or switch to client evaluation explicitly by
inserting a call to either AsEnumerable() or ToList()."));
+
+ Func<ICacheEntry<int, Person>, bool> filter = entry => false;
+ // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
+ Assert.Throws(constraint, () => GetPersonCache().AsCacheQueryable()
+ .Where(x => filter(x))
+ .ToList());
+
+ Func<ICacheEntry<int, Person>, int> selector = x => x.Key;
+ // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
+ Assert.Throws(constraint, () => GetPersonCache().AsCacheQueryable()
+ .Select(x => selector(x))
+ .FirstOrDefault());
+ }
}
}
diff --git
a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryExpressionVisitor.cs
b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryExpressionVisitor.cs
index cc14260..91bde9a0 100644
---
a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryExpressionVisitor.cs
+++
b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryExpressionVisitor.cs
@@ -334,6 +334,7 @@ namespace Apache.Ignite.Linq.Impl
return expression;
}
+
/// <summary>
/// Gets the name of the field from a member expression, with quotes
when necessary.
/// </summary>
@@ -515,9 +516,8 @@ namespace Apache.Ignite.Linq.Impl
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of
public methods")]
protected override Expression VisitInvocation(InvocationExpression
expression)
{
- VisitArguments(expression.Arguments);
-
- return expression;
+ throw new NotSupportedException("The LINQ expression '" +
expression +
+ "' could not be translated. Either rewrite the query in a form
that can be translated, or switch to client evaluation explicitly by inserting
a call to either AsEnumerable() or ToList().");
}
/** <inheritdoc /> */