From deb1cca3d4b6a19cba6531b274cbc42499efab72 Mon Sep 17 00:00:00 2001 From: Minh Le Date: Mon, 15 Aug 2022 12:34:02 -0700 Subject: [PATCH 1/6] Fix ToString bug, --- .../BuiltinFunctionVisitor.cs | 15 ++++------- .../StringBuiltinFunctions.cs | 25 +++++++++++++++++++ ...ralBaselineTests.TestThenByTranslation.xml | 2 +- ...neralBaselineTests.ValidateLinqQueries.xml | 2 +- ...lationBaselineTests.TestSpecialMethods.xml | 2 +- ...ationBaselineTests.TestStringFunctions.xml | 11 ++++++++ .../LinqTranslationBaselineTests.cs | 2 ++ 7 files changed, 46 insertions(+), 13 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs b/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs index c61f1a3f11..ceb17d9bb1 100644 --- a/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs +++ b/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs @@ -65,8 +65,11 @@ public static SqlScalarExpression VisitBuiltinFunctionCall(MethodCallExpression return MathBuiltinFunctions.Visit(methodCallExpression, context); } - // String functions - if (declaringType == typeof(string)) + // String functions or ToString with Objects (String and Guid only) + if ((declaringType == typeof(string)) || + (methodCallExpression.Method.Name == "ToString" && + methodCallExpression.Arguments.Count == 0 && + methodCallExpression.Object != null)) { return StringBuiltinFunctions.Visit(methodCallExpression, context); } @@ -83,14 +86,6 @@ public static SqlScalarExpression VisitBuiltinFunctionCall(MethodCallExpression return SpatialBuiltinFunctions.Visit(methodCallExpression, context); } - // ToString with Objects (String and Guid only) - if (methodCallExpression.Method.Name == "ToString" && - methodCallExpression.Arguments.Count == 0 && - methodCallExpression.Object != null) - { - return ExpressionToSql.VisitNonSubqueryScalarExpression(methodCallExpression.Object, context); - } - throw new DocumentQueryException(string.Format(CultureInfo.CurrentCulture, ClientResources.MethodNotSupported, methodCallExpression.Method.Name)); } diff --git a/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/StringBuiltinFunctions.cs b/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/StringBuiltinFunctions.cs index 967a75b2b8..781eb8d20a 100644 --- a/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/StringBuiltinFunctions.cs +++ b/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/StringBuiltinFunctions.cs @@ -327,6 +327,27 @@ protected override SqlScalarExpression VisitExplicit(MethodCallExpression method } } + private class StringVisitToString : SqlBuiltinFunctionVisitor + { + public StringVisitToString() + : base("ToString", + true, + null) + { + } + + protected override SqlScalarExpression VisitImplicit(MethodCallExpression methodCallExpression, TranslationContext context) + { + if ((methodCallExpression.Arguments.Count == 0) && (methodCallExpression.Object != null)) + { + SqlScalarExpression str = ExpressionToSql.VisitNonSubqueryScalarExpression(methodCallExpression.Object, context); + return SqlFunctionCallScalarExpression.CreateBuiltin(SqlFunctionCallScalarExpression.Names.ToString, str); + } + + return null; + } + } + static StringBuiltinFunctions() { StringBuiltinFunctionDefinitions = new Dictionary @@ -386,6 +407,10 @@ static StringBuiltinFunctions() "Reverse", new StringVisitReverse() }, + { + "ToString", + new StringVisitToString() + }, { "TrimEnd", new StringVisitTrimEnd() diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestThenByTranslation.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestThenByTranslation.xml index 1a9bf481e4..73b8b19748 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestThenByTranslation.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestThenByTranslation.xml @@ -199,7 +199,7 @@ JOIN ( SELECT VALUE MAX(t0["Amount"]) FROM root JOIN t0 IN root["Records"]["Transactions"])) AS v0 - ORDER BY (root["IsRegistered"] ? root["FamilyId"] : root["Int"]) DESC, (v0[0] % 1000) ASC + ORDER BY (root["IsRegistered"] ? root["FamilyId"] : ToString(root["Int"])) DESC, (v0[0] % 1000) ASC ]]> diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.ValidateLinqQueries.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.ValidateLinqQueries.xml index 3aba99b2aa..152ce1c0b3 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.ValidateLinqQueries.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.ValidateLinqQueries.xml @@ -284,7 +284,7 @@ WHERE (root["id"] = "098aa945-7ed8-4c50-b7b8-bd99eddb54bc")]]> +WHERE (ToString(root["id"]) = "098aa945-7ed8-4c50-b7b8-bd99eddb54bc")]]> diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestSpecialMethods.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestSpecialMethods.xml index eefd2b26a7..97ed19e2d8 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestSpecialMethods.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestSpecialMethods.xml @@ -39,7 +39,7 @@ FROM root]]> diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml index 0f3e7e0f9c..11298eb0e1 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml @@ -495,6 +495,17 @@ FROM root]]> + + + + + + doc.StringField.ToString())]]> + + + diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs index d4b411b067..b8755c3770 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs @@ -757,6 +757,8 @@ public void TestStringFunctions() new LinqTestInput("String constant StartsWith (case-insensitive)", b => getQuery(b).Select(doc => "sTr".StartsWith(doc.StringField, StringComparison.OrdinalIgnoreCase))), // Substring new LinqTestInput("Substring", b => getQuery(b).Select(doc => doc.StringField.Substring(0, 1))), + // ToString + new LinqTestInput("Substring", b => getQuery(b).Select(doc => doc.StringField.ToString())), // ToUpper new LinqTestInput("ToUpper", b => getQuery(b).Select(doc => doc.StringField.ToUpper())) }; From b652ba952f943badda0bc06c96c3584ff8d1131a Mon Sep 17 00:00:00 2001 From: Minh Le Date: Mon, 19 Sep 2022 01:46:37 -0700 Subject: [PATCH 2/6] address code review 1 --- .../Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs | 12 +++++++++++- .../LinqGeneralBaselineTests.ValidateLinqQueries.xml | 2 +- ...nqTranslationBaselineTests.TestSpecialMethods.xml | 2 +- ...qTranslationBaselineTests.TestStringFunctions.xml | 4 ++-- .../LinqTranslationBaselineTests.cs | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs b/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs index ceb17d9bb1..e3814ba1fd 100644 --- a/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs +++ b/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs @@ -65,7 +65,17 @@ public static SqlScalarExpression VisitBuiltinFunctionCall(MethodCallExpression return MathBuiltinFunctions.Visit(methodCallExpression, context); } - // String functions or ToString with Objects (String and Guid only) + // ToString with String and Guid only becomes passthrough + if (methodCallExpression.Method.Name == "ToString" && + methodCallExpression.Arguments.Count == 0 && + methodCallExpression.Object != null && + ((methodCallExpression.Object.Type == typeof(string)) || + (methodCallExpression.Object.Type == typeof(Guid)))) + { + return ExpressionToSql.VisitNonSubqueryScalarExpression(methodCallExpression.Object, context); + } + + // String functions or ToString with Objects that are not strings and guids if ((declaringType == typeof(string)) || (methodCallExpression.Method.Name == "ToString" && methodCallExpression.Arguments.Count == 0 && diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.ValidateLinqQueries.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.ValidateLinqQueries.xml index 152ce1c0b3..3aba99b2aa 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.ValidateLinqQueries.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.ValidateLinqQueries.xml @@ -284,7 +284,7 @@ WHERE (root["id"] = "098aa945-7ed8-4c50-b7b8-bd99eddb54bc")]]> +WHERE (root["id"] = "098aa945-7ed8-4c50-b7b8-bd99eddb54bc")]]> diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestSpecialMethods.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestSpecialMethods.xml index 97ed19e2d8..eefd2b26a7 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestSpecialMethods.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestSpecialMethods.xml @@ -39,7 +39,7 @@ FROM root]]> diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml index 11298eb0e1..37056fd073 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml @@ -500,12 +500,12 @@ FROM root]]> - + doc.StringField.ToString())]]> diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs index b8755c3770..e4d91c26c8 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs @@ -758,7 +758,7 @@ public void TestStringFunctions() // Substring new LinqTestInput("Substring", b => getQuery(b).Select(doc => doc.StringField.Substring(0, 1))), // ToString - new LinqTestInput("Substring", b => getQuery(b).Select(doc => doc.StringField.ToString())), + new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.StringField.ToString())), // ToUpper new LinqTestInput("ToUpper", b => getQuery(b).Select(doc => doc.StringField.ToUpper())) }; From b2275be590affb03f4fc86c3475d5adeb25a457a Mon Sep 17 00:00:00 2001 From: Minh Le Date: Mon, 10 Oct 2022 11:44:22 -0700 Subject: [PATCH 3/6] Address code review --- ...ationBaselineTests.TestStringFunctions.xml | 81 +++++++++++++++++++ .../LinqTranslationBaselineTests.cs | 15 +++- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml index 37056fd073..ede0a293e2 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml @@ -495,6 +495,17 @@ FROM root]]> + + + + + + "str".StartsWith(doc.StringField.ToString()))]]> + + + @@ -506,6 +517,76 @@ FROM root]]> + + + + + + doc.NumericField.ToString())]]> + + + + + + + + + doc.ArrayField.ToString())]]> + + + + + + + + + + doc.Point.ToString())]]> + + + + + + + + + + doc.BooleanField.ToString())]]> + + + + + + + + + + doc.UnixTime.ToString())]]> + + + + + + + + + + doc.GuidField.ToString())]]> + + + diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs index e4d91c26c8..9f352f2a63 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs @@ -150,6 +150,8 @@ internal class DataObject : LinqTestObject public string Id; public string Pk; + + public Guid GuidField; } class DateJsonConverter : IsoDateTimeConverter @@ -663,7 +665,7 @@ private Func> CreateDataTestStringFunctions() { StringField = sb.ToString(), Id = Guid.NewGuid().ToString(), - Pk = "Test" + Pk = "Test", }; }; Func> getQuery = LinqTestsCommon.GenerateTestCosmosData(createDataObj, Records, testContainer); @@ -758,14 +760,21 @@ public void TestStringFunctions() // Substring new LinqTestInput("Substring", b => getQuery(b).Select(doc => doc.StringField.Substring(0, 1))), // ToString + new LinqTestInput("String constant StartsWith", b => getQuery(b).Select(doc => "str".StartsWith(doc.StringField.ToString()))), new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.StringField.ToString())), + new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.NumericField.ToString())), + new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.ArrayField.ToString())), + new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.Point.ToString())), + new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.BooleanField.ToString())), + new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.UnixTime.ToString())), + new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.GuidField.ToString())), // ToUpper new LinqTestInput("ToUpper", b => getQuery(b).Select(doc => doc.StringField.ToUpper())) }; this.ExecuteTestSuite(inputs); - } + } - [TestMethod] + [TestMethod] public void TestArrayFunctions() { const int Records = 100; From ccf034b0ef743d17c68f1f5b3199eeea1b0c812b Mon Sep 17 00:00:00 2001 From: Minh Le Date: Mon, 10 Oct 2022 12:32:37 -0700 Subject: [PATCH 4/6] move guid under no assign warning disable --- .../LinqTranslationBaselineTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs index 9f352f2a63..d633a1c7ff 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs @@ -114,6 +114,7 @@ internal class DataObject : LinqTestObject public int? NullableField; #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value false public bool BooleanField; + public Guid GuidField; #pragma warning restore // Field is never assigned to, and will always have its default value false [JsonConverter(typeof(StringEnumConverter))] @@ -150,8 +151,6 @@ internal class DataObject : LinqTestObject public string Id; public string Pk; - - public Guid GuidField; } class DateJsonConverter : IsoDateTimeConverter From 4fbea97c87f58be3a1228439994a69d050b04f15 Mon Sep 17 00:00:00 2001 From: Minh Le Date: Tue, 11 Oct 2022 09:39:33 -0700 Subject: [PATCH 5/6] address test errors --- .../LinqTranslationBaselineTests.TestStringFunctions.xml | 8 ++++---- .../LinqTranslationBaselineTests.cs | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml index ede0a293e2..bc5d0aa64a 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml @@ -540,7 +540,7 @@ FROM root]]> - + @@ -552,7 +552,7 @@ FROM root]]> - + @@ -564,7 +564,7 @@ FROM root]]> - + @@ -576,7 +576,7 @@ FROM root]]> - + diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs index d633a1c7ff..9fdab30cda 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs @@ -665,6 +665,10 @@ private Func> CreateDataTestStringFunctions() StringField = sb.ToString(), Id = Guid.NewGuid().ToString(), Pk = "Test", + + // For ToString tests + ArrayField = new int[] {1,2,3}, + Point = new Point(0, 0) }; }; Func> getQuery = LinqTestsCommon.GenerateTestCosmosData(createDataObj, Records, testContainer); From 7ea32278d69c368c762290652e7c1750eb0ed5a3 Mon Sep 17 00:00:00 2001 From: Minh Le Date: Wed, 12 Oct 2022 11:50:12 -0700 Subject: [PATCH 6/6] Commented out some test that was differed but expected --- ...ationBaselineTests.TestStringFunctions.xml | 48 ------------------- .../LinqTranslationBaselineTests.cs | 13 ++--- 2 files changed, 7 insertions(+), 54 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml index bc5d0aa64a..a9fc581461 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestStringFunctions.xml @@ -531,54 +531,6 @@ SELECT VALUE ToString(root["NumericField"]) FROM root]]> - - - - doc.ArrayField.ToString())]]> - - - - - - - - - - doc.Point.ToString())]]> - - - - - - - - - - doc.BooleanField.ToString())]]> - - - - - - - - - - doc.UnixTime.ToString())]]> - - - - - - diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs index 9fdab30cda..3f2866ae31 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationBaselineTests.cs @@ -667,7 +667,7 @@ private Func> CreateDataTestStringFunctions() Pk = "Test", // For ToString tests - ArrayField = new int[] {1,2,3}, + ArrayField = new int[] {}, Point = new Point(0, 0) }; }; @@ -766,11 +766,12 @@ public void TestStringFunctions() new LinqTestInput("String constant StartsWith", b => getQuery(b).Select(doc => "str".StartsWith(doc.StringField.ToString()))), new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.StringField.ToString())), new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.NumericField.ToString())), - new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.ArrayField.ToString())), - new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.Point.ToString())), - new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.BooleanField.ToString())), - new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.UnixTime.ToString())), - new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.GuidField.ToString())), + new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.GuidField.ToString())), + // For these fields, .NET ToString and CosmosDB ToString don't produce the same behavior. Manually verified that BE behavior is as expected + //new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.ArrayField.ToString())), + //new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.Point.ToString())), + //new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.BooleanField.ToString())), + //new LinqTestInput("ToString", b => getQuery(b).Select(doc => doc.UnixTime.ToString())), // ToUpper new LinqTestInput("ToUpper", b => getQuery(b).Select(doc => doc.StringField.ToUpper())) };