Skip to content

Commit

Permalink
Query: Fixes regression from LINQ custom serializer fix (#3749)
Browse files Browse the repository at this point in the history
Co-authored-by: Minh Le <leminh@microsoft.com>
Co-authored-by: Matias Quaranta <ealsur@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 10, 2023
1 parent 6ebb8d4 commit 682b001
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 245 deletions.
17 changes: 0 additions & 17 deletions Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Microsoft.Azure.Cosmos.Linq
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
Expand Down Expand Up @@ -713,22 +712,6 @@ public static SqlScalarExpression VisitConstant(ConstantExpression inputExpressi
return SqlArrayCreateScalarExpression.Create(arrayItems.ToImmutableArray());
}

if (context.linqSerializerOptions?.CustomCosmosSerializer != null)
{
StringWriter writer = new StringWriter(CultureInfo.InvariantCulture);

// Use the user serializer for the parameter values so custom conversions are correctly handled
using (Stream stream = context.linqSerializerOptions.CustomCosmosSerializer.ToStream(inputExpression.Value))
{
using (StreamReader streamReader = new StreamReader(stream))
{
string propertyValue = streamReader.ReadToEnd();
writer.Write(propertyValue);
return CosmosElement.Parse(writer.ToString()).Accept(CosmosElementToSqlScalarExpressionVisitor.Singleton);
}
}
}

return CosmosElement.Parse(JsonConvert.SerializeObject(inputExpression.Value)).Accept(CosmosElementToSqlScalarExpressionVisitor.Singleton);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,11 @@ public override IOrderedQueryable<T> GetItemLinqQueryable<T>(
{
requestOptions ??= new QueryRequestOptions();

if (linqSerializerOptions == null && this.ClientContext.ClientOptions != null)
if (linqSerializerOptions == null && this.ClientContext.ClientOptions.SerializerOptions != null)
{
linqSerializerOptions = new CosmosLinqSerializerOptions
{
PropertyNamingPolicy = this.ClientContext.ClientOptions.SerializerOptions != null
? this.ClientContext.ClientOptions.SerializerOptions.PropertyNamingPolicy
: CosmosPropertyNamingPolicy.Default,
CustomCosmosSerializer = this.ClientContext.ClientOptions.Serializer
PropertyNamingPolicy = this.ClientContext.ClientOptions.SerializerOptions.PropertyNamingPolicy
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ public CosmosLinqSerializerOptions()
this.PropertyNamingPolicy = CosmosPropertyNamingPolicy.Default;
}

/// <summary>
/// Gets or sets the user defined customer serializer. If no customer serializer was defined,
/// then the value is set to the default value
/// </summary>
/// <remarks>
/// The default value is null
/// </remarks>
internal CosmosSerializer CustomCosmosSerializer { get; set; }

/// <summary>
/// Gets or sets whether the naming policy used to convert a string-based name to another format,
/// such as a camel-casing format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ FROM root]]></SqlQuery>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE {}
SELECT VALUE {"value": null}
FROM root]]></SqlQuery>
</Output>
</Result>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,9 @@ Family createDataObj(Random random)
return getQuery;
}

public static Func<bool, IQueryable<Data>> GenerateSimpleCosmosData(Cosmos.Database cosmosDatabase)
public static Func<bool, IQueryable<Data>> GenerateSimpleCosmosData(
Cosmos.Database cosmosDatabase
)
{
const int DocumentCount = 10;
PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition { Paths = new System.Collections.ObjectModel.Collection<string>(new[] { "/Pk" }), Kind = PartitionKind.Hash };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
// <copyright file="LinqTranslationBaselineTests.cs" company="Microsoft Corporation">
// <copyright file="LinqAttributeContractTests.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<None Remove="BaselineTest\TestBaseline\IndexMetricsParserBaselineTest.IndexUtilizationParse.xml" />
<None Remove="BaselineTest\TestBaseline\LinqTranslationBaselineTests.TestDateTimeJsonConverterTimezones.xml" />
<None Remove="BaselineTest\TestBaseline\LinqTranslationBaselineTests.TestMemberAccessWithNullableTypes.xml" />
<None Remove="BaselineTest\TestBaseline\LinqTranslationWithCustomSerializerBaseline.TestMemberInitializer.xml" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -248,9 +247,6 @@
<Content Include="BaselineTest\TestBaseline\LinqTranslationBaselineTests.TestMemberAccess.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="BaselineTest\TestBaseline\LinqTranslationWithCustomSerializerBaseline.TestMemberInitializer.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Query\AggregateQueryTests.AggregateMixedTypes_baseline.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down

0 comments on commit 682b001

Please sign in to comment.