Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] Category: Fixes Some issue #4865

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Microsoft.Azure.Cosmos.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29123.88
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Cosmos", "Microsoft.Azure.Cosmos\src\Microsoft.Azure.Cosmos.csproj", "{36F6F6A8-CEC8-4261-9948-903495BC3C25}"
EndProject
Expand Down Expand Up @@ -34,7 +34,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Cosmos.Encr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FaultInjection", "Microsoft.Azure.Cosmos\FaultInjection\src\FaultInjection.csproj", "{021DDC27-02EF-42C4-9A9E-AA600833C2EE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.Cosmos.Encryption.Custom.Performance.Tests", "Microsoft.Azure.Cosmos.Encryption.Custom\tests\Microsoft.Azure.Cosmos.Encryption.Custom.Performance.Tests\Microsoft.Azure.Cosmos.Encryption.Custom.Performance.Tests.csproj", "{CE4D6DA8-148D-4A98-943B-D8C2D532E1DC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Cosmos.Encryption.Custom.Performance.Tests", "Microsoft.Azure.Cosmos.Encryption.Custom\tests\Microsoft.Azure.Cosmos.Encryption.Custom.Performance.Tests\Microsoft.Azure.Cosmos.Encryption.Custom.Performance.Tests.csproj", "{CE4D6DA8-148D-4A98-943B-D8C2D532E1DC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ public async Task<ContainerResponse> CreateIfNotExistsAsync(
containerProperties.VectorEmbeddingPolicy = this.vectorEmbeddingPolicy;
}

if (this.fullTextPolicy != null)
{
containerProperties.FullTextPolicy = this.fullTextPolicy;
}

return containerProperties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ private static async Task<PartitionedQueryExecutionInfo> GetPartitionedQueryExec
CancellationToken cancellationToken)
{
PartitionedQueryExecutionInfo partitionedQueryExecutionInfo;
if (cosmosQueryContext.QueryClient.BypassQueryParsing())
//if (true)
{
// For non-Windows platforms(like Linux and OSX) in .NET Core SDK, we cannot use ServiceInterop, so need to bypass in that case.
// We are also now bypassing this for 32 bit host process running even on Windows as there are many 32 bit apps that will not work without this
Expand All @@ -588,22 +588,22 @@ private static async Task<PartitionedQueryExecutionInfo> GetPartitionedQueryExec
trace,
cancellationToken);
}
else
{
Documents.PartitionKeyDefinition partitionKeyDefinition = GetPartitionKeyDefinition(inputParameters, containerQueryProperties);

partitionedQueryExecutionInfo = await QueryPlanRetriever.GetQueryPlanWithServiceInteropAsync(
cosmosQueryContext.QueryClient,
inputParameters.SqlQuerySpec,
cosmosQueryContext.ResourceTypeEnum,
partitionKeyDefinition,
containerQueryProperties.VectorEmbeddingPolicy,
inputParameters.PartitionKey != null,
containerQueryProperties.GeospatialType,
cosmosQueryContext.UseSystemPrefix,
trace,
cancellationToken);
}
//else
//{
// Documents.PartitionKeyDefinition partitionKeyDefinition = GetPartitionKeyDefinition(inputParameters, containerQueryProperties);

// partitionedQueryExecutionInfo = await QueryPlanRetriever.GetQueryPlanWithServiceInteropAsync(
// cosmosQueryContext.QueryClient,
// inputParameters.SqlQuerySpec,
// cosmosQueryContext.ResourceTypeEnum,
// partitionKeyDefinition,
// containerQueryProperties.VectorEmbeddingPolicy,
// inputParameters.PartitionKey != null,
// containerQueryProperties.GeospatialType,
// cosmosQueryContext.UseSystemPrefix,
// trace,
// cancellationToken);
//}

return partitionedQueryExecutionInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ public static Task<PartitionedQueryExecutionInfo> GetQueryPlanThroughGatewayAsyn
ResourceType.Document,
OperationType.QueryPlan,
sqlQuerySpec,
partitionKey,
GetSupportedQueryFeaturesString(isNonStreamingOrderByQueryFeatureDisabled),
partitionKey,
// GetSupportedQueryFeaturesString(isNonStreamingOrderByQueryFeatureDisabled),
"Aggregate, Distinct, GroupBy, MultipleAggregates, MultipleOrderBy, OffsetAndLimit, OrderBy, Top, NonValueAggregate, DCount, NonStreamingOrderBy, CountIf, HybridSearch",
trace,
cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,15 @@ public override async Task<PartitionedQueryExecutionInfo> ExecuteQueryPlanReques
cancellationToken: cancellationToken))
{
// Syntax exception are argument exceptions and thrown to the user.
message.EnsureSuccessStatusCode();
partitionedQueryExecutionInfo = this.clientContext.SerializerCore.FromStream<PartitionedQueryExecutionInfo>(message.Content);
message.EnsureSuccessStatusCode();

//using (var streamReader = new StreamReader(message.Content))
//{
// string result = streamReader.ReadToEnd();
// Console.WriteLine(result);
//}
//message.Content.Seek(0, SeekOrigin.Begin);
partitionedQueryExecutionInfo = this.clientContext.SerializerCore.FromStream<PartitionedQueryExecutionInfo>(message.Content);
}

return partitionedQueryExecutionInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ await this.database.DefineContainer(containerName, partitionKeyPath)
}

[TestMethod]
[Ignore("This test will be enabled once the full text search changes are made available into the public emulator.")]
// [Ignore("This test will be enabled once the full text search changes are made available into the public emulator.")]
public async Task TestFullTextSearchPolicy()
{
string fullTextPath1 = "/fts1", fullTextPath2 = "/fts2", fullTextPath3 = "/fts3";
Expand Down Expand Up @@ -749,7 +749,7 @@ await databaseForVectorEmbedding.DefineContainer(containerName, partitionKeyPath
Assert.AreEqual(fullTextPaths.Count, containerSettings.IndexingPolicy.FullTextIndexes.Count());
Assert.AreEqual(fullTextPath1, containerSettings.IndexingPolicy.FullTextIndexes[0].Path);
Assert.AreEqual(fullTextPath2, containerSettings.IndexingPolicy.FullTextIndexes[1].Path);
Assert.AreEqual(fullTextPath1, containerSettings.IndexingPolicy.FullTextIndexes[2].Path);
Assert.AreEqual(fullTextPath3, containerSettings.IndexingPolicy.FullTextIndexes[2].Path);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
namespace Microsoft.Azure.Cosmos.Query
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class HybridRankingQueryTests
{
private CosmosClient CreateCosmosClient(bool local)
{
}

[TestMethod]
public async Task CreateCollectionIndexOnly()
{
string fullTextPath1 = "/fts1";
Database databaseForVectorEmbedding = await this.CreateCosmosClient(local: false).CreateDatabaseAsync("fullTextSearchDB",
cancellationToken: default);

Collection<FullTextPath> fullTextPaths = new Collection<FullTextPath>()
{
new FullTextPath()
{
Path = fullTextPath1,
Language = "en-US",
}
};

string containerName = "fullTextContainerTestIndexOnly";
string partitionKeyPath = "/pk";

ContainerResponse containerResponse =
await databaseForVectorEmbedding.DefineContainer(containerName, partitionKeyPath)
.WithIndexingPolicy()
.WithFullTextIndex()
.Path(fullTextPath1)
.Attach()
.Attach()
.CreateAsync();

Assert.AreEqual(HttpStatusCode.Created, containerResponse.StatusCode);
Assert.AreEqual(containerName, containerResponse.Resource.Id);
Assert.AreEqual(partitionKeyPath, containerResponse.Resource.PartitionKey.Paths.First());
ContainerProperties containerSettings = containerResponse.Resource;

// Validate FullText Paths.
Assert.IsNotNull(containerSettings.FullTextPolicy);
Assert.IsNotNull(containerSettings.FullTextPolicy.FullTextPaths);
Assert.AreEqual(fullTextPaths.Count, containerSettings.FullTextPolicy.FullTextPaths.Count());
Assert.IsTrue(fullTextPaths.OrderBy(x => x.Path).SequenceEqual(containerSettings.FullTextPolicy.FullTextPaths.OrderBy(x => x.Path)));

// Validate Full Text Indexes.
Assert.IsNotNull(containerSettings.IndexingPolicy.FullTextIndexes);
Assert.AreEqual(fullTextPaths.Count, containerSettings.IndexingPolicy.FullTextIndexes.Count());
Assert.AreEqual(fullTextPath1, containerSettings.IndexingPolicy.FullTextIndexes[0].Path);
}

[TestMethod]
public async Task CreatePolicyAndIdnexOnExistingContainer()
{
string path = "/abstract";
CosmosClient client = this.CreateCosmosClient(local: false);
Container container = client.GetContainer("HybridRankTesting", "arxiv-250kdocuments-index");
ContainerResponse response = await container.ReadContainerAsync();
ContainerProperties containerProperties = response.Resource;
containerProperties.FullTextPolicy = new FullTextPolicy
{
DefaultLanguage = "en-US",
FullTextPaths = new Collection<FullTextPath>
{
new FullTextPath
{
Path = path,
Language = "en-US",
}
}
};
containerProperties.IndexingPolicy.FullTextIndexes.Add(new FullTextIndexPath { Path = path });

ContainerResponse containerResponse = await container.ReplaceContainerAsync(containerProperties);
Assert.IsTrue(containerResponse.StatusCode == HttpStatusCode.OK);
}

[TestMethod]
public async Task CreateCollectionBothPolicyAndIndex()
{
string fullTextPath1 = "/fts1";
Database databaseForVectorEmbedding = await this.CreateCosmosClient(local: false).CreateDatabaseAsync("fullTextSearchDB",
cancellationToken: default);

Collection<FullTextPath> fullTextPaths = new Collection<FullTextPath>()
{
new FullTextPath()
{
Path = fullTextPath1,
Language = "en-US",
}
};

string containerName = "fullTextContainerTestPolicyAndIndex";
string partitionKeyPath = "/pk";

ContainerResponse containerResponse =
await databaseForVectorEmbedding.DefineContainer(containerName, partitionKeyPath)
.WithFullTextPolicy(
defaultLanguage: "en-US",
fullTextPaths: fullTextPaths)
.Attach()
.WithIndexingPolicy()
.WithFullTextIndex()
.Path(fullTextPath1)
.Attach()
.Attach()
.CreateAsync();

Assert.AreEqual(HttpStatusCode.Created, containerResponse.StatusCode);
Assert.AreEqual(containerName, containerResponse.Resource.Id);
Assert.AreEqual(partitionKeyPath, containerResponse.Resource.PartitionKey.Paths.First());
ContainerProperties containerSettings = containerResponse.Resource;

// Validate FullText Paths.
Assert.IsNotNull(containerSettings.FullTextPolicy);
Assert.IsNotNull(containerSettings.FullTextPolicy.FullTextPaths);
Assert.AreEqual(fullTextPaths.Count, containerSettings.FullTextPolicy.FullTextPaths.Count());
Assert.IsTrue(fullTextPaths.OrderBy(x => x.Path).SequenceEqual(containerSettings.FullTextPolicy.FullTextPaths.OrderBy(x => x.Path)));

// Validate Full Text Indexes.
Assert.IsNotNull(containerSettings.IndexingPolicy.FullTextIndexes);
Assert.AreEqual(fullTextPaths.Count, containerSettings.IndexingPolicy.FullTextIndexes.Count());
Assert.AreEqual(fullTextPath1, containerSettings.IndexingPolicy.FullTextIndexes[0].Path);
}

[TestMethod]
public async Task CreateCollectionPolicyOnly()
{
string fullTextPath1 = "/fts1", fullTextPath2 = "/fts2", fullTextPath3 = "/fts3";
Database databaseForVectorEmbedding = await this.CreateCosmosClient(local: false).CreateDatabaseAsync("fullTextSearchDBPolicyOnly",
cancellationToken: default);

Collection<FullTextPath> fullTextPaths = new Collection<FullTextPath>()
{
new FullTextPath()
{
Path = fullTextPath1,
Language = "en-US",
},
new FullTextPath()
{
Path = fullTextPath2,
Language = "en-US",
},
new FullTextPath()
{
Path = fullTextPath3,
Language = "en-US",
},
};

string containerName = "fullTextContainerTestPolicyOnly";
string partitionKeyPath = "/pk";

ContainerResponse containerResponse =
await databaseForVectorEmbedding.DefineContainer(containerName, partitionKeyPath)
.WithFullTextPolicy(
defaultLanguage: "en-US",
fullTextPaths: fullTextPaths)
.Attach()
//.WithIndexingPolicy()
// .WithFullTextIndex()
// .Path(fullTextPath1)
// .Attach()
// .WithFullTextIndex()
// .Path(fullTextPath2)
// .Attach()
// .WithFullTextIndex()
// .Path(fullTextPath3)
// .Attach()
//.Attach()
.CreateAsync();

Assert.AreEqual(HttpStatusCode.Created, containerResponse.StatusCode);
Assert.AreEqual(containerName, containerResponse.Resource.Id);
Assert.AreEqual(partitionKeyPath, containerResponse.Resource.PartitionKey.Paths.First());
ContainerProperties containerSettings = containerResponse.Resource;

// Validate FullText Paths.
//Assert.IsNotNull(containerSettings.FullTextPolicy);
//Assert.IsNotNull(containerSettings.FullTextPolicy.FullTextPaths);
//Assert.AreEqual(fullTextPaths.Count, containerSettings.FullTextPolicy.FullTextPaths.Count());
//Assert.IsTrue(fullTextPaths.OrderBy(x => x.Path).SequenceEqual(containerSettings.FullTextPolicy.FullTextPaths.OrderBy(x => x.Path)));

// Validate Full Text Indexes.
//Assert.IsNotNull(containerSettings.IndexingPolicy.FullTextIndexes);
//Assert.AreEqual(fullTextPaths.Count, containerSettings.IndexingPolicy.FullTextIndexes.Count());
//Assert.AreEqual(fullTextPath1, containerSettings.IndexingPolicy.FullTextIndexes[0].Path);
//Assert.AreEqual(fullTextPath2, containerSettings.IndexingPolicy.FullTextIndexes[1].Path);
//Assert.AreEqual(fullTextPath3, containerSettings.IndexingPolicy.FullTextIndexes[2].Path);
}

[TestMethod]
public async Task HybridRankingQuery()
{
CosmosClient client = this.CreateCosmosClient(local: false);
Container container = client.GetContainer("HybridRankTesting", "arxiv-ada2-15properties-1536dimensions-100documents");
FeedIterator<dynamic> iterator = container.GetItemQueryIterator<dynamic>(
queryText: @"SELECT TOP 10 c.id FROM c ORDER BY RANK FullTextScore(c.text, ['quantum'])"
);
List<dynamic> results = new();
while (iterator.HasMoreResults)
{
FeedResponse<dynamic> page = await iterator.ReadNextAsync();
results.AddRange(page);
}

foreach (dynamic item in results)
{
Console.WriteLine(item);
}
}
}
}
Loading