Skip to content

Commit

Permalink
[INTERNAL] IncludedPath: Adds IsFullIndex for compute (#2555)
Browse files Browse the repository at this point in the history
* add internal IsFullIndex to IncludedPath class

* add included path serialization unit test

* remote INTERNAL macro

Co-authored-by: j82w <j82w@users.noreply.github.com>
  • Loading branch information
PaulCheng and j82w authored Jun 15, 2021
1 parent 10cb815 commit 867c8c8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Microsoft.Azure.Cosmos/src/Resource/Settings/IncludedPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Specifies a path within a JSON document to be included in the Azure Cosmos DB service.
/// </summary>
public
#if !INTERNAL
sealed
#endif
class IncludedPath
public sealed class IncludedPath
{
/// <summary>
/// Gets or sets the path to be indexed in the Azure Cosmos DB service.
Expand All @@ -38,5 +34,11 @@ class IncludedPath
/// </value>
[JsonProperty(PropertyName = Constants.Properties.Indexes)]
internal Collection<Index> Indexes { get; set; } = new Collection<Index>();

/// <summary>
/// Gets or sets whether this is a full index used for collection types.
/// </summary>
[JsonProperty(PropertyName = Constants.Properties.IsFullIndex, NullValueHandling = NullValueHandling.Ignore)]
internal bool? IsFullIndex { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.Azure.Cosmos.Tests
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Azure.Documents;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
Expand Down Expand Up @@ -120,6 +121,50 @@ public void DefaultIndexingPolicySameAsDocumentCollection()
CosmosContainerSettingsTests.AssertSerializedPayloads(containerSettings, dc);
}

[TestMethod]
public void ValidateIncludedPathSerialization()
{
ContainerProperties containerSettings = new ContainerProperties("TestContainer", "/partitionKey")
{
IndexingPolicy = new Cosmos.IndexingPolicy()
};

containerSettings.IndexingPolicy.IncludedPaths.Add(new Cosmos.IncludedPath()
{
Path = "/textprop/?",
});
containerSettings.IndexingPolicy.IncludedPaths.Add(new Cosmos.IncludedPath()
{
Path = "/listprop/?",
IsFullIndex = true,
});

using (Stream stream = MockCosmosUtil.Serializer.ToStream<ContainerProperties>(containerSettings))
{
StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd();

Match match = Regex.Match(content, "\"includedPaths\":\\[(.+?)\\],\"excludedPaths\"");
Assert.IsTrue(match.Success, "IncludedPaths not found in serialized content");

// verify IncludedPath ignores null IsFullIndex
string includedPaths = match.Groups[1].Value;
string delimiter = "},{";
int position = includedPaths.IndexOf(delimiter);
string textPropIncludedPath = includedPaths.Substring(0, position + 1);
string listPropIncludedPath = includedPaths.Substring(position + delimiter.Length - 1);

Assert.AreEqual("{\"path\":\"/textprop/?\",\"indexes\":[]}", textPropIncludedPath);
Assert.AreEqual("{\"path\":\"/listprop/?\",\"indexes\":[],\"isFullIndex\":true}", listPropIncludedPath);

// verify deserialization
stream.Position = 0;
containerSettings = MockCosmosUtil.Serializer.FromStream<ContainerProperties>(stream);
Assert.IsNull(containerSettings.IndexingPolicy.IncludedPaths[0].IsFullIndex, "textprop IsFullIndex is not null");
Assert.IsTrue((bool)containerSettings.IndexingPolicy.IncludedPaths[1].IsFullIndex, "listprop IsFullIndex is not set to true");
}
}

private static string SerializeDocumentCollection(DocumentCollection collection)
{
using (MemoryStream ms = new MemoryStream())
Expand Down

0 comments on commit 867c8c8

Please sign in to comment.