From d6d616150f5d26333e415ddda10d5a1902148c3b Mon Sep 17 00:00:00 2001 From: Shaun Cooper Date: Tue, 5 Nov 2024 12:46:10 -0600 Subject: [PATCH] Remove unused code related to checking if query features are supported. --- .../Query/Core/QueryPlan/QueryPlanHandler.cs | 254 ------------------ .../Core/QueryPlan/QueryPlanRetriever.cs | 1 - .../Query/HybridSearchQueryTests.cs | 1 + .../QueryPlanBaselineTests.VectorSearch.xml | 18 +- 4 files changed, 10 insertions(+), 264 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanHandler.cs b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanHandler.cs index 4c03555986..3b7d54717e 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanHandler.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanHandler.cs @@ -27,7 +27,6 @@ public async Task> TryGetQueryPlanAsync( Documents.ResourceType resourceType, PartitionKeyDefinition partitionKeyDefinition, VectorEmbeddingPolicy vectorEmbeddingPolicy, - QueryFeatures supportedQueryFeatures, bool hasLogicalPartitionKey, bool useSystemPrefix, GeospatialType geospatialType, @@ -62,52 +61,6 @@ public async Task> TryGetQueryPlanAsync( return tryGetQueryInfo; } - /// - /// Used in the compute gateway to support legacy gateways query execution pattern. - /// - public async Task> TryGetQueryInfoAndIfSupportedAsync( - QueryFeatures supportedQueryFeatures, - SqlQuerySpec sqlQuerySpec, - Documents.ResourceType resourceType, - PartitionKeyDefinition partitionKeyDefinition, - VectorEmbeddingPolicy vectorEmbeddingPolicy, - bool hasLogicalPartitionKey, - bool useSystemPrefix, - GeospatialType geospatialType, - CancellationToken cancellationToken = default) - { - if (sqlQuerySpec == null) - { - throw new ArgumentNullException(nameof(sqlQuerySpec)); - } - - if (partitionKeyDefinition == null) - { - throw new ArgumentNullException(nameof(partitionKeyDefinition)); - } - - cancellationToken.ThrowIfCancellationRequested(); - - TryCatch tryGetQueryInfo = await this.TryGetQueryInfoAsync( - sqlQuerySpec, - resourceType, - partitionKeyDefinition, - vectorEmbeddingPolicy, - hasLogicalPartitionKey, - useSystemPrefix, - geospatialType, - cancellationToken); - if (tryGetQueryInfo.Failed) - { - return TryCatch<(PartitionedQueryExecutionInfo, bool)>.FromException(tryGetQueryInfo.Exception); - } - - QueryFeatures neededQueryFeatures = QueryPlanSupportChecker.GetNeededQueryFeatures( - tryGetQueryInfo.Result.QueryInfo, - supportedQueryFeatures); - return TryCatch<(PartitionedQueryExecutionInfo, bool)>.FromResult((tryGetQueryInfo.Result, neededQueryFeatures == QueryFeatures.None)); - } - private Task> TryGetQueryInfoAsync( SqlQuerySpec sqlQuerySpec, Documents.ResourceType resourceType, @@ -134,212 +87,5 @@ private Task> TryGetQueryInfoAsync( geospatialType: geospatialType, cancellationToken: cancellationToken); } - - private static class QueryPlanSupportChecker - { - public static QueryFeatures GetNeededQueryFeatures( - QueryInfo queryInfo, - QueryFeatures supportedQueryFeatures) - { - QueryFeatures neededQueryFeatures = QueryFeatures.None; - neededQueryFeatures |= QueryPlanSupportChecker.GetNeededQueryFeaturesIfAggregateQuery(queryInfo, supportedQueryFeatures); - neededQueryFeatures |= QueryPlanSupportChecker.GetNeededQueryFeaturesIfDistinctQuery(queryInfo, supportedQueryFeatures); - neededQueryFeatures |= QueryPlanSupportChecker.GetNeedQueryFeaturesIfGroupByQuery(queryInfo, supportedQueryFeatures); - neededQueryFeatures |= QueryPlanSupportChecker.GetNeededQueryFeaturesIfOffsetLimitQuery(queryInfo, supportedQueryFeatures); - neededQueryFeatures |= QueryPlanSupportChecker.GetNeededQueryFeaturesIfOrderByQuery(queryInfo, supportedQueryFeatures); - neededQueryFeatures |= QueryPlanSupportChecker.GetNeededQueryFeaturesIfTopQuery(queryInfo, supportedQueryFeatures); - - return neededQueryFeatures; - } - - private static QueryFeatures GetNeededQueryFeaturesIfAggregateQuery( - QueryInfo queryInfo, - QueryFeatures supportedQueryFeatures) - { - QueryFeatures neededQueryFeatures = QueryFeatures.None; - if (queryInfo.HasAggregates) - { - bool isSingleAggregate = (queryInfo.Aggregates.Count == 1) - || (queryInfo.GroupByAliasToAggregateType.Values.Where(aggregateOperator => aggregateOperator.HasValue).Count() == 1); - if (isSingleAggregate) - { - if (queryInfo.HasSelectValue) - { - if (!supportedQueryFeatures.HasFlag(QueryFeatures.Aggregate)) - { - neededQueryFeatures |= QueryFeatures.Aggregate; - } - } - else - { - if (!supportedQueryFeatures.HasFlag(QueryFeatures.NonValueAggregate)) - { - neededQueryFeatures |= QueryFeatures.NonValueAggregate; - } - } - } - else - { - if (!supportedQueryFeatures.HasFlag(QueryFeatures.NonValueAggregate)) - { - neededQueryFeatures |= QueryFeatures.NonValueAggregate; - } - - if (!supportedQueryFeatures.HasFlag(QueryFeatures.MultipleAggregates)) - { - neededQueryFeatures |= QueryFeatures.MultipleAggregates; - } - } - } - - return neededQueryFeatures; - } - - private static QueryFeatures GetNeededQueryFeaturesIfDistinctQuery( - QueryInfo queryInfo, - QueryFeatures supportedQueryFeatures) - { - QueryFeatures neededQueryFeatures = QueryFeatures.None; - if (queryInfo.HasDistinct) - { - if (!supportedQueryFeatures.HasFlag(QueryFeatures.Distinct)) - { - neededQueryFeatures |= QueryFeatures.Distinct; - } - } - - return neededQueryFeatures; - } - - private static QueryFeatures GetNeededQueryFeaturesIfTopQuery( - QueryInfo queryInfo, - QueryFeatures supportedQueryFeatures) - { - QueryFeatures neededQueryFeatures = QueryFeatures.None; - if (queryInfo.HasTop) - { - if (!supportedQueryFeatures.HasFlag(QueryFeatures.Top)) - { - neededQueryFeatures |= QueryFeatures.Top; - } - } - - return neededQueryFeatures; - } - - private static QueryFeatures GetNeededQueryFeaturesIfOffsetLimitQuery( - QueryInfo queryInfo, - QueryFeatures supportedQueryFeatures) - { - QueryFeatures neededQueryFeatures = QueryFeatures.None; - if (queryInfo.HasLimit || queryInfo.HasOffset) - { - if (!supportedQueryFeatures.HasFlag(QueryFeatures.OffsetAndLimit)) - { - neededQueryFeatures |= QueryFeatures.OffsetAndLimit; - } - } - - return neededQueryFeatures; - } - - private static QueryFeatures GetNeedQueryFeaturesIfGroupByQuery( - QueryInfo queryInfo, - QueryFeatures supportedQueryFeatures) - { - QueryFeatures neededQueryFeatures = QueryFeatures.None; - if (queryInfo.HasGroupBy) - { - if (!supportedQueryFeatures.HasFlag(QueryFeatures.GroupBy)) - { - neededQueryFeatures |= QueryFeatures.GroupBy; - } - } - - return neededQueryFeatures; - } - - private static QueryFeatures GetNeededQueryFeaturesIfOrderByQuery( - QueryInfo queryInfo, - QueryFeatures supportedQueryFeatures) - { - QueryFeatures neededQueryFeatures = QueryFeatures.None; - if (queryInfo.HasOrderBy) - { - if (queryInfo.OrderByExpressions.Count == 1) - { - if (!supportedQueryFeatures.HasFlag(QueryFeatures.OrderBy)) - { - neededQueryFeatures |= QueryFeatures.OrderBy; - } - } - else - { - if (!supportedQueryFeatures.HasFlag(QueryFeatures.MultipleOrderBy)) - { - neededQueryFeatures |= QueryFeatures.MultipleOrderBy; - } - } - } - - return neededQueryFeatures; - } - } - - private static class QueryPlanExceptionFactory - { - private static readonly IReadOnlyList QueryFeatureList = (QueryFeatures[])Enum.GetValues(typeof(QueryFeatures)); - private static readonly ReadOnlyDictionary FeatureToUnsupportedException = new ReadOnlyDictionary( - QueryFeatureList - .ToDictionary( - x => x, - x => new ArgumentException(QueryPlanExceptionFactory.FormatExceptionMessage(x.ToString())))); - - public static bool TryGetUnsupportedException( - QueryInfo queryInfo, - QueryFeatures supportedQueryFeatures, - out Exception queryPlanHandlerException) - { - QueryFeatures neededQueryFeatures = QueryPlanSupportChecker.GetNeededQueryFeatures( - queryInfo, - supportedQueryFeatures); - if (neededQueryFeatures != QueryFeatures.None) - { - List queryPlanHandlerExceptions = new List(); - foreach (QueryFeatures queryFeature in QueryPlanExceptionFactory.QueryFeatureList) - { - if ((neededQueryFeatures & queryFeature) == queryFeature) - { - Exception unsupportedFeatureException = QueryPlanExceptionFactory.FeatureToUnsupportedException[queryFeature]; - queryPlanHandlerExceptions.Add(unsupportedFeatureException); - } - } - - queryPlanHandlerException = new QueryPlanHandlerException(queryPlanHandlerExceptions); - return true; - } - - queryPlanHandlerException = default; - return false; - } - - private static string FormatExceptionMessage(string feature) - { - return $"Query contained {feature}, which the calling client does not support."; - } - - private sealed class QueryPlanHandlerException : AggregateException - { - private const string QueryContainsUnsupportedFeaturesExceptionMessage = "Query contains 1 or more unsupported features. Upgrade your SDK to a version that does support the requested features:"; - public QueryPlanHandlerException(IEnumerable innerExceptions) - : base( - QueryContainsUnsupportedFeaturesExceptionMessage - + Environment.NewLine - + string.Join(Environment.NewLine, innerExceptions.Select(innerException => innerException.Message)), - innerExceptions) - { - } - } - } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanRetriever.cs b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanRetriever.cs index 3b5d620837..a6108d0b4a 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanRetriever.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanRetriever.cs @@ -86,7 +86,6 @@ public static async Task GetQueryPlanWithServiceI resourceType, partitionKeyDefinition, vectorEmbeddingPolicy, - QueryPlanRetriever.SupportedQueryFeatures, hasLogicalPartitionKey, useSystemPrefix, geospatialType, diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/HybridSearchQueryTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/HybridSearchQueryTests.cs index 66e7c544fb..2bc5c03cc0 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/HybridSearchQueryTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/HybridSearchQueryTests.cs @@ -19,6 +19,7 @@ public sealed class HybridSearchQueryTests : QueryTestsBase private static readonly IndexingPolicy CompositeIndexPolicy = CreateIndexingPolicy(); + [Ignore("This test can only be enabled after emulator upgrade")] [TestMethod] public async Task SanityTests() { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.VectorSearch.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.VectorSearch.xml index c17a92d4b8..8bd7793d15 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.VectorSearch.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.VectorSearch.xml @@ -197,7 +197,7 @@ ORDER BY VectorDistance(c.embedding, @vectorEmbedding, true)]]> Ascending - VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true) + VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.0056763873435556889, -0.013547309674322605, -0.0024455438833683729, 0.015792045742273331, -0.016796082258224487, -0.012471556663513184], true) @@ -209,10 +209,10 @@ ORDER BY VectorDistance(c.embedding, @vectorEmbedding, true)]]> [[],"Infinity") - +ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.0056763873435556889, -0.013547309674322605, -0.0024455438833683729, 0.015792045742273331, -0.016796082258224487, -0.012471556663513184], true)]]> @@ -240,7 +240,7 @@ ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.02733845636248588 Descending - VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true) + VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.0056763873435556889, -0.013547309674322605, -0.0024455438833683729, 0.015792045742273331, -0.016796082258224487, -0.012471556663513184], true) @@ -252,10 +252,10 @@ ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.02733845636248588 [[],"Infinity") - +ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.0056763873435556889, -0.013547309674322605, -0.0024455438833683729, 0.015792045742273331, -0.016796082258224487, -0.012471556663513184], true)]]> @@ -283,7 +283,7 @@ ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.02733845636248588 Descending - VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, (- 0.0056763873435556889), (- 0.013547309674322605), (- 0.0024455438833683729), 0.015792045742273331, (- 0.016796082258224487), (- 0.012471556663513184)], true) + VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.0056763873435556889, -0.013547309674322605, -0.0024455438833683729, 0.015792045742273331, -0.016796082258224487, -0.012471556663513184], true) @@ -295,10 +295,10 @@ ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.02733845636248588 [[],"Infinity") - +ORDER BY VectorDistance(c.embedding, [0.0039695268496870995, 0.027338456362485886, -0.0056763873435556889, -0.013547309674322605, -0.0024455438833683729, 0.015792045742273331, -0.016796082258224487, -0.012471556663513184], true)]]>