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:
[email protected]


Reply via email to