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