You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/04/12 15:24:09 UTC

[GitHub] [ignite] olegbevz opened a new pull request #8999: [IGNITE-14523] Support for string.Compare in Apache Ignie LINQ provider

olegbevz opened a new pull request #8999:
URL: https://github.com/apache/ignite/pull/8999


   Currently Apache Ignite does not support string comparison for LINQ provider (Apache.Ignite.Linq project).
   
   For example following modified query insideThinClientQueryExample.ScanQueryExample method will throw Exception:
   
   var employees = cache.AsCacheQueryable().Select(x => x.Value).Where(x => string.Compare(x.Name, "Daniel Adams") >= 0);
   
   Business case: in our project we use DevExteme.AspNet.Data library to build LINQ queries for Apache Ignite and in some cases the library builds complex queries with string.Compare method call. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn commented on a change in pull request #8999: IGNITE-14523 .NET: Add string.Compare support to LINQ provider

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #8999:
URL: https://github.com/apache/ignite/pull/8999#discussion_r613354601



##########
File path: modules/platforms/dotnet/Apache.Ignite.Linq/Impl/MethodVisitor.cs
##########
@@ -329,6 +331,50 @@ private static void AppendAdjustment(CacheQueryExpressionVisitor visitor, int[]
             visitor.Parameters.Add(paramValue);
         }
 
+        /// <summary>
+        /// Get IgnoreCase parameter for string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <returns></returns>
+        private static bool GetStringCompareIgnoreCaseParameter(Expression expression)
+        {
+            if (expression is ConstantExpression constant)
+            {
+                if (constant.Value is bool ignoreCase)
+                {
+                    return ignoreCase;
+                }
+            }
+
+            throw new ArgumentException("ignoreCase");            
+        }
+
+        /// <summary>
+        /// Visits string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <param name="visitor"></param>
+        private static void VisitStringCompare(MethodCallExpression expression, CacheQueryExpressionVisitor visitor, bool ignoreCase)
+        {
+            visitor.ResultBuilder.Append("casewhen(");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[0]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(" = ");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[1]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(", 0, casewhen(");
+            visitor.ResultBuilder.Append("lower(");

Review comment:
       The difference is caused by the fact that this `string.Compare` overload is culture-specific (uses `CultureInfo.CurrentCulture`).
   
   I don't think we should try to mimic this behavior when translating to SQL.
   Let's keep it simple, [like EF Core does](https://docs.microsoft.com/en-us/ef/core/miscellaneous/collations-and-case-sensitivity#translation-of-built-in-net-string-operations for equality `EF Core makes no attempt to translate simple equality to a database case-sensitive operation`.
   
   * If `ignoreCase` is set - use `lower`, otherwise don't.
   * Alternatively, drop the support for this overload to avoid confusion, keep only `Compare(string, string)`

##########
File path: modules/platforms/dotnet/Apache.Ignite.Linq/Impl/MethodVisitor.cs
##########
@@ -329,6 +331,50 @@ private static void AppendAdjustment(CacheQueryExpressionVisitor visitor, int[]
             visitor.Parameters.Add(paramValue);
         }
 
+        /// <summary>
+        /// Get IgnoreCase parameter for string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <returns></returns>
+        private static bool GetStringCompareIgnoreCaseParameter(Expression expression)
+        {
+            if (expression is ConstantExpression constant)
+            {
+                if (constant.Value is bool ignoreCase)
+                {
+                    return ignoreCase;
+                }
+            }
+
+            throw new ArgumentException("ignoreCase");            
+        }
+
+        /// <summary>
+        /// Visits string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <param name="visitor"></param>
+        private static void VisitStringCompare(MethodCallExpression expression, CacheQueryExpressionVisitor visitor, bool ignoreCase)
+        {
+            visitor.ResultBuilder.Append("casewhen(");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[0]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(" = ");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[1]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(", 0, casewhen(");
+            visitor.ResultBuilder.Append("lower(");

Review comment:
       The difference is caused by the fact that this `string.Compare` overload is culture-specific (uses `CultureInfo.CurrentCulture`).
   
   I don't think we should try to mimic this behavior when translating to SQL.
   Let's keep it simple, [like EF Core does](https://docs.microsoft.com/en-us/ef/core/miscellaneous/collations-and-case-sensitivity#translation-of-built-in-net-string-operations for equality `EF Core makes no attempt to translate simple equality to a database case-sensitive operation`.
   
   * If `ignoreCase` is `true` - use `lower`, otherwise don't.
   * Alternatively, drop the support for this overload to avoid confusion, keep only `Compare(string, string)`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn merged pull request #8999: IGNITE-14523 .NET: Add string.Compare support to LINQ provider

Posted by GitBox <gi...@apache.org>.
ptupitsyn merged pull request #8999:
URL: https://github.com/apache/ignite/pull/8999


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn commented on a change in pull request #8999: IGNITE-14523 .NET: Add string.Compare support to LINQ provider

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #8999:
URL: https://github.com/apache/ignite/pull/8999#discussion_r613354601



##########
File path: modules/platforms/dotnet/Apache.Ignite.Linq/Impl/MethodVisitor.cs
##########
@@ -329,6 +331,50 @@ private static void AppendAdjustment(CacheQueryExpressionVisitor visitor, int[]
             visitor.Parameters.Add(paramValue);
         }
 
+        /// <summary>
+        /// Get IgnoreCase parameter for string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <returns></returns>
+        private static bool GetStringCompareIgnoreCaseParameter(Expression expression)
+        {
+            if (expression is ConstantExpression constant)
+            {
+                if (constant.Value is bool ignoreCase)
+                {
+                    return ignoreCase;
+                }
+            }
+
+            throw new ArgumentException("ignoreCase");            
+        }
+
+        /// <summary>
+        /// Visits string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <param name="visitor"></param>
+        private static void VisitStringCompare(MethodCallExpression expression, CacheQueryExpressionVisitor visitor, bool ignoreCase)
+        {
+            visitor.ResultBuilder.Append("casewhen(");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[0]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(" = ");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[1]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(", 0, casewhen(");
+            visitor.ResultBuilder.Append("lower(");

Review comment:
       The difference is caused by the fact that this `string.Compare` overload is culture-specific (uses `CultureInfo.CurrentCulture`).
   
   I don't think we should try to mimic this behavior when translating to SQL.
   Let's keep it simple, [like EF Core does](https://docs.microsoft.com/en-us/ef/core/miscellaneous/collations-and-case-sensitivity#translation-of-built-in-net-string-operations) for equality: `EF Core makes no attempt to translate simple equality to a database case-sensitive operation`.
   
   * If `ignoreCase` is `true` - use `lower`, otherwise don't.
   * Alternatively, drop the support for this overload to avoid confusion, keep only `Compare(string, string)`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] olegbevz commented on a change in pull request #8999: IGNITE-14523 .NET: Add string.Compare support to LINQ provider

Posted by GitBox <gi...@apache.org>.
olegbevz commented on a change in pull request #8999:
URL: https://github.com/apache/ignite/pull/8999#discussion_r613406863



##########
File path: modules/platforms/dotnet/Apache.Ignite.Linq/Impl/MethodVisitor.cs
##########
@@ -329,6 +331,50 @@ private static void AppendAdjustment(CacheQueryExpressionVisitor visitor, int[]
             visitor.Parameters.Add(paramValue);
         }
 
+        /// <summary>
+        /// Get IgnoreCase parameter for string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <returns></returns>
+        private static bool GetStringCompareIgnoreCaseParameter(Expression expression)
+        {
+            if (expression is ConstantExpression constant)
+            {
+                if (constant.Value is bool ignoreCase)
+                {
+                    return ignoreCase;
+                }
+            }
+
+            throw new ArgumentException("ignoreCase");            
+        }
+
+        /// <summary>
+        /// Visits string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <param name="visitor"></param>
+        private static void VisitStringCompare(MethodCallExpression expression, CacheQueryExpressionVisitor visitor, bool ignoreCase)
+        {
+            visitor.ResultBuilder.Append("casewhen(");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[0]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(" = ");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[1]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(", 0, casewhen(");
+            visitor.ResultBuilder.Append("lower(");

Review comment:
       @ptupitsyn, I did what was easiest: updated VisitStringCompare method to use ignoreCase in both cases + updated unit tests




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] olegbevz commented on a change in pull request #8999: [IGNITE-14523] Support for string.Compare in Apache Ignie LINQ provider

Posted by GitBox <gi...@apache.org>.
olegbevz commented on a change in pull request #8999:
URL: https://github.com/apache/ignite/pull/8999#discussion_r613271447



##########
File path: modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Strings.cs
##########
@@ -110,6 +110,30 @@ public void TestStrings()
 
             // String + int
             CheckFunc(x => x + 10, strings);
+
+            // string.Compare(string strA, string strB)
+            CheckWhereFunc(x => string.Compare(x, "Person_1300") < 0, strings);

Review comment:
       agree, added tests for `<=` and `>=`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn commented on a change in pull request #8999: IGNITE-14523 .NET: Add string.Compare support to LINQ provider

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #8999:
URL: https://github.com/apache/ignite/pull/8999#discussion_r613964196



##########
File path: modules/platforms/dotnet/Apache.Ignite.Linq/Impl/MethodVisitor.cs
##########
@@ -329,6 +331,56 @@ private static void AppendAdjustment(CacheQueryExpressionVisitor visitor, int[]
             visitor.Parameters.Add(paramValue);
         }
 
+        /// <summary>
+        /// Get IgnoreCase parameter for string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <returns></returns>
+        private static bool GetStringCompareIgnoreCaseParameter(Expression expression)
+        {
+            var constant = expression as ConstantExpression;
+            if (constant != null)
+            {
+                if (constant.Value is bool)
+                {
+                    return (bool)constant.Value;
+                }
+            }
+
+            throw new NotSupportedException(
+                "Parameter 'ignoreCase' from 'string.Compare method should be specified as a constant expression");
+        }
+
+        /// <summary>
+        /// Visits string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <param name="visitor"></param>
+        private static void VisitStringCompare(MethodCallExpression expression, CacheQueryExpressionVisitor visitor, bool ignoreCase)
+        {
+            visitor.ResultBuilder.Append("nvl2(");
+            visitor.Visit(expression.Arguments[1]);
+            visitor.ResultBuilder.Append(", ");
+            visitor.ResultBuilder.Append("casewhen(");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[0]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(" = ");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[1]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(", 0, casewhen(");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[0]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(" >= ");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[1]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(", 1, -1))");
+            visitor.ResultBuilder.Append(", 1)");
+        }
+

Review comment:
       I tried to make this a bit easier to read:
   
   ```suggestion
               // Ex: nvl2(?, casewhen(_T0.NAME = ?, 0, casewhen(_T0.NAME >= ?, 1, -1)), 1)
               visitor.ResultBuilder.Append("nvl2(");
               visitor.Visit(expression.Arguments[1]);
               visitor.ResultBuilder.Append(", casewhen(");
               VisitArg(visitor, expression, 0, ignoreCase);
               visitor.ResultBuilder.Append(" = ");
               VisitArg(visitor, expression, 1, ignoreCase);
               visitor.ResultBuilder.Append(", 0, casewhen(");
               VisitArg(visitor, expression, 0, ignoreCase);
               visitor.ResultBuilder.Append(" >= ");
               VisitArg(visitor, expression, 1, ignoreCase);
               visitor.ResultBuilder.Append(", 1, -1)), 1)");
           }
   
           /// <summary>
           /// Visits member expression argument.
           /// </summary>
           private static void VisitArg(CacheQueryExpressionVisitor visitor, MethodCallExpression expression, int idx,
               bool lower)
           {
               if (lower)
                   visitor.ResultBuilder.Append("lower(");
   
               visitor.Visit(expression.Arguments[idx]);
   
               if (lower)
                   visitor.ResultBuilder.Append(")");
           }
   
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] olegbevz commented on a change in pull request #8999: [IGNITE-14523] Support for string.Compare in Apache Ignie LINQ provider

Posted by GitBox <gi...@apache.org>.
olegbevz commented on a change in pull request #8999:
URL: https://github.com/apache/ignite/pull/8999#discussion_r613304208



##########
File path: modules/platforms/dotnet/Apache.Ignite.Linq/Impl/MethodVisitor.cs
##########
@@ -329,6 +331,50 @@ private static void AppendAdjustment(CacheQueryExpressionVisitor visitor, int[]
             visitor.Parameters.Add(paramValue);
         }
 
+        /// <summary>
+        /// Get IgnoreCase parameter for string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <returns></returns>
+        private static bool GetStringCompareIgnoreCaseParameter(Expression expression)
+        {
+            if (expression is ConstantExpression constant)
+            {
+                if (constant.Value is bool ignoreCase)
+                {
+                    return ignoreCase;
+                }
+            }
+
+            throw new ArgumentException("ignoreCase");            

Review comment:
       updated exception details and edded test




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn commented on a change in pull request #8999: [IGNITE-14523] Support for string.Compare in Apache Ignie LINQ provider

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #8999:
URL: https://github.com/apache/ignite/pull/8999#discussion_r612659627



##########
File path: modules/platforms/dotnet/Apache.Ignite.Linq/Impl/MethodVisitor.cs
##########
@@ -329,6 +331,50 @@ private static void AppendAdjustment(CacheQueryExpressionVisitor visitor, int[]
             visitor.Parameters.Add(paramValue);
         }
 
+        /// <summary>
+        /// Get IgnoreCase parameter for string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <returns></returns>
+        private static bool GetStringCompareIgnoreCaseParameter(Expression expression)
+        {
+            if (expression is ConstantExpression constant)
+            {
+                if (constant.Value is bool ignoreCase)
+                {
+                    return ignoreCase;
+                }
+            }
+
+            throw new ArgumentException("ignoreCase");            
+        }
+
+        /// <summary>
+        /// Visits string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <param name="visitor"></param>
+        private static void VisitStringCompare(MethodCallExpression expression, CacheQueryExpressionVisitor visitor, bool ignoreCase)
+        {
+            visitor.ResultBuilder.Append("casewhen(");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[0]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(" = ");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[1]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(", 0, casewhen(");
+            visitor.ResultBuilder.Append("lower(");

Review comment:
       `lower` is used even if `ignoreCase` is `false` - not sure this is correct.

##########
File path: modules/platforms/dotnet/Apache.Ignite.Linq/Impl/MethodVisitor.cs
##########
@@ -329,6 +331,50 @@ private static void AppendAdjustment(CacheQueryExpressionVisitor visitor, int[]
             visitor.Parameters.Add(paramValue);
         }
 
+        /// <summary>
+        /// Get IgnoreCase parameter for string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <returns></returns>
+        private static bool GetStringCompareIgnoreCaseParameter(Expression expression)
+        {
+            if (expression is ConstantExpression constant)

Review comment:
       We are still on C# 4, this won't compile for some targets (I'll set `<LangVersion>` in the proj file to make this obvious). Please refactor without pattern matching.
   

##########
File path: modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Strings.cs
##########
@@ -110,6 +110,30 @@ public void TestStrings()
 
             // String + int
             CheckFunc(x => x + 10, strings);
+
+            // string.Compare(string strA, string strB)
+            CheckWhereFunc(x => string.Compare(x, "Person_1300") < 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "Person_1300") > 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "Person_1300") == 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300") < 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300") > 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300") == 0, strings);
+
+            // string.Compare(string strA, string strB, true)
+            CheckWhereFunc(x => string.Compare(x, "Person_1300", true) < 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "Person_1300", true) > 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "Person_1300", true) == 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300", true) < 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300", true) > 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300", true) == 0, strings);
+
+            // string.Compare(string strA, string strB, false)
+            CheckWhereFunc(x => string.Compare(x, "Person_1300", false) < 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "Person_1300", false) > 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "Person_1300", false) == 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300", false) < 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300", false) > 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300", false) == 0, strings);

Review comment:
       Please add tests for `null` which is a valid `string.Compare` argument:
   ```
   CheckWhereFunc(x => string.Compare(x, null, true) > 0, strings);
   ```

##########
File path: modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Strings.cs
##########
@@ -110,6 +110,30 @@ public void TestStrings()
 
             // String + int
             CheckFunc(x => x + 10, strings);
+
+            // string.Compare(string strA, string strB)
+            CheckWhereFunc(x => string.Compare(x, "Person_1300") < 0, strings);

Review comment:
       What about `>=` and `<=`, do we support that?

##########
File path: modules/platforms/dotnet/Apache.Ignite.Linq/Impl/MethodVisitor.cs
##########
@@ -329,6 +331,50 @@ private static void AppendAdjustment(CacheQueryExpressionVisitor visitor, int[]
             visitor.Parameters.Add(paramValue);
         }
 
+        /// <summary>
+        /// Get IgnoreCase parameter for string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <returns></returns>
+        private static bool GetStringCompareIgnoreCaseParameter(Expression expression)
+        {
+            if (expression is ConstantExpression constant)
+            {
+                if (constant.Value is bool ignoreCase)
+                {
+                    return ignoreCase;
+                }
+            }
+
+            throw new ArgumentException("ignoreCase");            

Review comment:
       1. Let's use `NotSupportedException` here and explain the problem in detail. 
   2. Please add a test for this use case so we understand when this can happen




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] olegbevz commented on a change in pull request #8999: [IGNITE-14523] Support for string.Compare in Apache Ignie LINQ provider

Posted by GitBox <gi...@apache.org>.
olegbevz commented on a change in pull request #8999:
URL: https://github.com/apache/ignite/pull/8999#discussion_r613303908



##########
File path: modules/platforms/dotnet/Apache.Ignite.Linq/Impl/MethodVisitor.cs
##########
@@ -329,6 +331,50 @@ private static void AppendAdjustment(CacheQueryExpressionVisitor visitor, int[]
             visitor.Parameters.Add(paramValue);
         }
 
+        /// <summary>
+        /// Get IgnoreCase parameter for string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <returns></returns>
+        private static bool GetStringCompareIgnoreCaseParameter(Expression expression)
+        {
+            if (expression is ConstantExpression constant)

Review comment:
       ok, updated method body




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] olegbevz commented on a change in pull request #8999: [IGNITE-14523] Support for string.Compare in Apache Ignie LINQ provider

Posted by GitBox <gi...@apache.org>.
olegbevz commented on a change in pull request #8999:
URL: https://github.com/apache/ignite/pull/8999#discussion_r613280896



##########
File path: modules/platforms/dotnet/Apache.Ignite.Linq/Impl/MethodVisitor.cs
##########
@@ -329,6 +331,50 @@ private static void AppendAdjustment(CacheQueryExpressionVisitor visitor, int[]
             visitor.Parameters.Add(paramValue);
         }
 
+        /// <summary>
+        /// Get IgnoreCase parameter for string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <returns></returns>
+        private static bool GetStringCompareIgnoreCaseParameter(Expression expression)
+        {
+            if (expression is ConstantExpression constant)
+            {
+                if (constant.Value is bool ignoreCase)
+                {
+                    return ignoreCase;
+                }
+            }
+
+            throw new ArgumentException("ignoreCase");            
+        }
+
+        /// <summary>
+        /// Visits string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <param name="visitor"></param>
+        private static void VisitStringCompare(MethodCallExpression expression, CacheQueryExpressionVisitor visitor, bool ignoreCase)
+        {
+            visitor.ResultBuilder.Append("casewhen(");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[0]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(" = ");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[1]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(", 0, casewhen(");
+            visitor.ResultBuilder.Append("lower(");

Review comment:
       It seems that string.Compare method considers case only for string equality and ignores case while defining if string is greater than the other. Looks strange for me too. 
   You can run these lines of code:
   ``		
   Console.WriteLine(string.Compare("Person_1300", "Person_1300", false)); // 0
   Console.WriteLine(string.Compare("Person_1299", "Person_1300", false)); // -1
   Console.WriteLine(string.Compare("Person_1301", "Person_1300", false)); // 1
   Console.WriteLine(string.Compare("Person_1300", "person_1300", false)); // 1
   Console.WriteLine(string.Compare("Person_1299", "person_1300", false)); // -1
   Console.WriteLine(string.Compare("Person_1301", "person_1300", false)); // 1
   ``
   On the opposite side ignite considers case for string comparison:
   ``
   SELECT 'Person_1300' < 'person_1300', 'Person_1299' < 'person_1300', 'Person_1301' < 'person_1300'; // true, true, true
   ``
   Thus to mimic .NET method behavior I had to always convert strings to lower case while defining if string is greater than the other.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] olegbevz commented on a change in pull request #8999: [IGNITE-14523] Support for string.Compare in Apache Ignie LINQ provider

Posted by GitBox <gi...@apache.org>.
olegbevz commented on a change in pull request #8999:
URL: https://github.com/apache/ignite/pull/8999#discussion_r613273052



##########
File path: modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Strings.cs
##########
@@ -110,6 +110,30 @@ public void TestStrings()
 
             // String + int
             CheckFunc(x => x + 10, strings);
+
+            // string.Compare(string strA, string strB)
+            CheckWhereFunc(x => string.Compare(x, "Person_1300") < 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "Person_1300") > 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "Person_1300") == 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300") < 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300") > 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300") == 0, strings);
+
+            // string.Compare(string strA, string strB, true)
+            CheckWhereFunc(x => string.Compare(x, "Person_1300", true) < 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "Person_1300", true) > 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "Person_1300", true) == 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300", true) < 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300", true) > 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300", true) == 0, strings);
+
+            // string.Compare(string strA, string strB, false)
+            CheckWhereFunc(x => string.Compare(x, "Person_1300", false) < 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "Person_1300", false) > 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "Person_1300", false) == 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300", false) < 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300", false) > 0, strings);
+            CheckWhereFunc(x => string.Compare(x, "person_1300", false) == 0, strings);

Review comment:
       agree, added tests for null arguments, also had to modify sql query with nvl2 operator( 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn commented on a change in pull request #8999: IGNITE-14523 .NET: Add string.Compare support to LINQ provider

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #8999:
URL: https://github.com/apache/ignite/pull/8999#discussion_r613354601



##########
File path: modules/platforms/dotnet/Apache.Ignite.Linq/Impl/MethodVisitor.cs
##########
@@ -329,6 +331,50 @@ private static void AppendAdjustment(CacheQueryExpressionVisitor visitor, int[]
             visitor.Parameters.Add(paramValue);
         }
 
+        /// <summary>
+        /// Get IgnoreCase parameter for string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <returns></returns>
+        private static bool GetStringCompareIgnoreCaseParameter(Expression expression)
+        {
+            if (expression is ConstantExpression constant)
+            {
+                if (constant.Value is bool ignoreCase)
+                {
+                    return ignoreCase;
+                }
+            }
+
+            throw new ArgumentException("ignoreCase");            
+        }
+
+        /// <summary>
+        /// Visits string.Compare method
+        /// </summary>
+        /// <param name="expression"></param>
+        /// <param name="visitor"></param>
+        private static void VisitStringCompare(MethodCallExpression expression, CacheQueryExpressionVisitor visitor, bool ignoreCase)
+        {
+            visitor.ResultBuilder.Append("casewhen(");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[0]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(" = ");
+            if (ignoreCase) visitor.ResultBuilder.Append("lower(");
+            visitor.Visit(expression.Arguments[1]);
+            if (ignoreCase) visitor.ResultBuilder.Append(")");
+            visitor.ResultBuilder.Append(", 0, casewhen(");
+            visitor.ResultBuilder.Append("lower(");

Review comment:
       The difference is caused by the fact that this `string.Compare` overload is culture-specific (uses `CultureInfo.CurrentCulture`).
   
   I don't think we should try to mimic this behavior when translating to SQL.
   Let's keep it simple, [like EF Core does](https://docs.microsoft.com/en-us/ef/core/miscellaneous/collations-and-case-sensitivity#translation-of-built-in-net-string-operations for equality) `EF Core makes no attempt to translate simple equality to a database case-sensitive operation`.
   
   * If `ignoreCase` is `true` - use `lower`, otherwise don't.
   * Alternatively, drop the support for this overload to avoid confusion, keep only `Compare(string, string)`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org