Skip to content

Commit

Permalink
Merge branch 'release/9.0-staging' into release/9.0 (#35255)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd authored Dec 2, 2024
2 parents 1a71476 + 8741e71 commit bb72406
Show file tree
Hide file tree
Showing 63 changed files with 1,948 additions and 965 deletions.
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<PackageVersion Include="Microsoft.DotNet.Build.Tasks.Templating" Version="$(MicrosoftDotNetBuildTasksTemplatingVersion)" />

<!-- Azure SDK for .NET dependencies -->
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.43.0" />
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.45.2" />

<!-- SQL Server dependencies -->
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.6" />
Expand All @@ -51,14 +51,14 @@
<PackageVersion Include="NetTopologySuite.IO.SqlServerBytes" Version="2.1.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="mod_spatialite" Version="4.3.0.1" />
<PackageVersion Include="SQLitePCLRaw.core" Version="$(SQLitePCLRawVersion)" />
<PackageVersion Include="SQLitePCLRaw.core" Version="$(SQLitePCLRawVersion)" />
<PackageVersion Include="SQLitePCLRaw.bundle_sqlite3" Version="$(SQLitePCLRawVersion)" />
<PackageVersion Include="SQLitePCLRaw.bundle_e_sqlite3" Version="$(SQLitePCLRawVersion)" />

<!-- Pinned versions for Component Governance/NuGetAudit - Remove when root dependencies are updated -->
<!--Workaround for Microsoft.CodeAnalysis.Workspaces.MSBuild 4.8.0, see https://github.com/dotnet/efcore/issues/34637-->
<PackageVersion Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildFrameworkVersion)" />
<!--Workaround for Microsoft.Data.SqlClient v5.1.6 and Microsoft.CodeAnalysis.Analyzer.Testing v1.1.2-->
<PackageVersion Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildFrameworkVersion)" />
<!--Workaround for Microsoft.Data.SqlClient v5.1.6 and Microsoft.CodeAnalysis.Analyzer.Testing v1.1.2-->
<PackageVersion Include="System.Formats.Asn1" Version="$(SystemFormatsAsn1Version)" />
</ItemGroup>
</Project>
36 changes: 0 additions & 36 deletions src/EFCore.Cosmos/Extensions/DistanceFunction.cs

This file was deleted.

19 changes: 0 additions & 19 deletions src/EFCore.Cosmos/Extensions/Embedding.cs

This file was deleted.

40 changes: 0 additions & 40 deletions src/EFCore.Cosmos/Extensions/VectorDataType.cs

This file was deleted.

14 changes: 0 additions & 14 deletions src/EFCore.Cosmos/Extensions/VectorIndexPath.cs

This file was deleted.

35 changes: 0 additions & 35 deletions src/EFCore.Cosmos/Extensions/VectorIndexType.cs

This file was deleted.

6 changes: 0 additions & 6 deletions src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/EFCore.Cosmos/Properties/CosmosStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@
<data name="NoSubqueryPushdown" xml:space="preserve">
<value>Azure Cosmos DB does not have an appropriate subquery for this translation.</value>
</data>
<data name="NoVectorContainerConfig" xml:space="preserve">
<value>Container configuration for embeddings is not yet supported by the Cosmos SDK. Instead, configure the container manually. See https://aka.ms/ef-cosmos-vectors for more information.</value>
</data>
<data name="NullTypeMappingInSqlTree" xml:space="preserve">
<value>The expression '{sqlExpression}' in the SQL tree does not have a type mapping assigned.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal;
/// </summary>
public class CosmosQueryableMethodTranslatingExpressionVisitor : QueryableMethodTranslatingExpressionVisitor
{
private static readonly bool UseOldBehavior35094 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue35094", out var enabled) && enabled;

private readonly CosmosQueryCompilationContext _queryCompilationContext;
private readonly ISqlExpressionFactory _sqlExpressionFactory;
private readonly ITypeMappingSource _typeMappingSource;
Expand Down Expand Up @@ -445,23 +448,29 @@ private ShapedQueryExpression CreateShapedQueryExpression(SelectExpression selec
/// </summary>
protected override ShapedQueryExpression? TranslateAverage(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
{
var selectExpression = (SelectExpression)source.QueryExpression;
if (selectExpression.IsDistinct
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
if (UseOldBehavior35094)
{
return null;
}
var selectExpression = (SelectExpression)source.QueryExpression;
if (selectExpression.IsDistinct
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
return null;
}

if (selector != null)
{
source = TranslateSelect(source, selector);
}
if (selector != null)
{
source = TranslateSelect(source, selector);
}

var projection = (SqlExpression)selectExpression.GetMappedProjection(new ProjectionMember());
projection = _sqlExpressionFactory.Function("AVG", new[] { projection }, projection.Type, projection.TypeMapping);
var projection = (SqlExpression)selectExpression.GetMappedProjection(new ProjectionMember());
projection = _sqlExpressionFactory.Function("AVG", new[] { projection }, projection.Type, projection.TypeMapping);

return AggregateResultShaper(source, projection, throwOnNullResult: true, resultType);
return AggregateResultShaper(source, projection, throwOnNullResult: true, resultType);

}

return TranslateAggregate(source, selector, resultType, "AVG");
}

/// <summary>
Expand Down Expand Up @@ -843,24 +852,29 @@ protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression sou
/// </summary>
protected override ShapedQueryExpression? TranslateMax(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
{
var selectExpression = (SelectExpression)source.QueryExpression;
if (selectExpression.IsDistinct
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
if (UseOldBehavior35094)
{
return null;
}
var selectExpression = (SelectExpression)source.QueryExpression;
if (selectExpression.IsDistinct
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
return null;
}

if (selector != null)
{
source = TranslateSelect(source, selector);
}
if (selector != null)
{
source = TranslateSelect(source, selector);
}

var projection = (SqlExpression)selectExpression.GetMappedProjection(new ProjectionMember());
var projection = (SqlExpression)selectExpression.GetMappedProjection(new ProjectionMember());

projection = _sqlExpressionFactory.Function("MAX", new[] { projection }, resultType, projection.TypeMapping);
projection = _sqlExpressionFactory.Function("MAX", new[] { projection }, resultType, projection.TypeMapping);

return AggregateResultShaper(source, projection, throwOnNullResult: true, resultType);
return AggregateResultShaper(source, projection, throwOnNullResult: true, resultType);
}

return TranslateAggregate(source, selector, resultType, "MAX");
}

/// <summary>
Expand All @@ -871,24 +885,29 @@ protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression sou
/// </summary>
protected override ShapedQueryExpression? TranslateMin(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
{
var selectExpression = (SelectExpression)source.QueryExpression;
if (selectExpression.IsDistinct
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
if (UseOldBehavior35094)
{
return null;
}
var selectExpression = (SelectExpression)source.QueryExpression;
if (selectExpression.IsDistinct
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
return null;
}

if (selector != null)
{
source = TranslateSelect(source, selector);
}
if (selector != null)
{
source = TranslateSelect(source, selector);
}

var projection = (SqlExpression)selectExpression.GetMappedProjection(new ProjectionMember());
var projection = (SqlExpression)selectExpression.GetMappedProjection(new ProjectionMember());

projection = _sqlExpressionFactory.Function("MIN", new[] { projection }, resultType, projection.TypeMapping);
projection = _sqlExpressionFactory.Function("MIN", new[] { projection }, resultType, projection.TypeMapping);

return AggregateResultShaper(source, projection, throwOnNullResult: true, resultType);
return AggregateResultShaper(source, projection, throwOnNullResult: true, resultType);
}

return TranslateAggregate(source, selector, resultType, "MIN");
}

/// <summary>
Expand Down Expand Up @@ -1520,6 +1539,35 @@ protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression s

#endregion Queryable collection support

private ShapedQueryExpression? TranslateAggregate(ShapedQueryExpression source, LambdaExpression? selector, Type resultType, string functionName)
{
var selectExpression = (SelectExpression)source.QueryExpression;
if (selectExpression.IsDistinct
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
return null;
}

if (selector != null)
{
source = TranslateSelect(source, selector);
}

if (!_subquery && resultType.IsNullableType())
{
// For nullable types, we want to return null from Max, Min, and Average, rather than throwing. See Issue #35094.
// Note that relational databases typically return null, which propagates. Cosmos will instead return no elements,
// and hence for Cosmos only we need to change no elements into null.
source = source.UpdateResultCardinality(ResultCardinality.SingleOrDefault);
}

var projection = (SqlExpression)selectExpression.GetMappedProjection(new ProjectionMember());
projection = _sqlExpressionFactory.Function(functionName, [projection], resultType, _typeMappingSource.FindMapping(resultType));

return AggregateResultShaper(source, projection, throwOnNullResult: true, resultType);
}

private bool TryApplyPredicate(ShapedQueryExpression source, LambdaExpression predicate)
{
var select = (SelectExpression)source.QueryExpression;
Expand Down
7 changes: 2 additions & 5 deletions src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,14 @@ private static async Task<bool> CreateContainerIfNotExistsOnceAsync(
AnalyticalStoreTimeToLiveInSeconds = parameters.AnalyticalStoreTimeToLiveInSeconds,
};

// TODO: Enable these once they are available in the Cosmos SDK. See #33783.
if (embeddings.Any())
{
throw new InvalidOperationException(CosmosStrings.NoVectorContainerConfig);
//containerProperties.VectorEmbeddingPolicy = new VectorEmbeddingPolicy(embeddings);
containerProperties.VectorEmbeddingPolicy = new VectorEmbeddingPolicy(embeddings);
}

if (vectorIndexes.Any())
{
throw new InvalidOperationException(CosmosStrings.NoVectorContainerConfig);
//containerProperties.IndexingPolicy = new IndexingPolicy { VectorIndexes = vectorIndexes };
containerProperties.IndexingPolicy = new IndexingPolicy { VectorIndexes = vectorIndexes };
}

var response = await wrapper.Client.GetDatabase(wrapper._databaseId).CreateContainerIfNotExistsAsync(
Expand Down
Loading

0 comments on commit bb72406

Please sign in to comment.