Skip to content

Commit

Permalink
Query: Adds FeedRange API for Query to GA (#3068)
Browse files Browse the repository at this point in the history
* Move FeedRange API for Query to GA

* Fix up build break

* Update DotNetSDKAPI.json

* Update DotNetPreviewSDKAPI.json

Co-authored-by: Samer Boshra <sboshra@microsoft.com>
  • Loading branch information
neildsh and sboshra authored Mar 8, 2022
1 parent 729e135 commit 52f38c2
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 123 deletions.
204 changes: 102 additions & 102 deletions Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,108 @@ public abstract FeedIterator<T> GetItemQueryIterator<T>(
string continuationToken = null,
QueryRequestOptions requestOptions = null);

/// <summary>
/// This method creates a query for items under a container in an Azure Cosmos database using a SQL statement with parameterized values. It returns a FeedIterator.
/// For more information on preparing SQL statements with parameterized values, please see <see cref="QueryDefinition"/>.
/// </summary>
/// <param name="feedRange">A FeedRange obtained from <see cref="Container.GetFeedRangesAsync(CancellationToken)"/></param>
/// <param name="queryDefinition">The Cosmos SQL query definition.</param>
/// <param name="continuationToken">(Optional) The continuation token in the Azure Cosmos DB service.</param>
/// <param name="requestOptions">(Optional) The options for the item query request.</param>
/// <returns>An iterator to go through the items.</returns>
/// <remarks>
/// Query as a stream only supports single partition queries
/// </remarks>
/// <exception>https://aka.ms/cosmosdb-dot-net-exceptions#stream-api</exception>
/// <example>
/// Create a query to get all the ToDoActivity that have a cost greater than 9000 for the specified partition
/// <code language="c#">
/// <![CDATA[
/// public class ToDoActivity{
/// public string id {get; set;}
/// public string status {get; set;}
/// public int cost {get; set;}
/// }
/// IReadOnlyList<FeedRange> feedRanges = await this.Container.GetFeedRangesAsync();
/// // Distribute feedRanges across multiple compute units and pass each one to a different iterator
/// QueryDefinition queryDefinition = new QueryDefinition("select * from ToDos t where t.cost > @expensive")
/// .WithParameter("@expensive", 9000);
/// using (FeedIterator feedIterator = this.Container.GetItemQueryStreamIterator(
/// feedRanges[0],
/// queryDefinition,
/// null,
/// new QueryRequestOptions() { }))
/// {
/// while (feedIterator.HasMoreResults)
/// {
/// using (ResponseMessage response = await feedIterator.ReadNextAsync())
/// {
/// using (StreamReader sr = new StreamReader(response.Content))
/// using (JsonTextReader jtr = new JsonTextReader(sr))
/// {
/// JObject result = JObject.Load(jtr);
/// }
/// }
/// }
/// }
/// ]]>
/// </code>
/// </example>
public abstract FeedIterator GetItemQueryStreamIterator(
FeedRange feedRange,
QueryDefinition queryDefinition,
string continuationToken,
QueryRequestOptions requestOptions = null);

/// <summary>
/// This method creates a query for items under a container in an Azure Cosmos database using a SQL statement with parameterized values. It returns a FeedIterator.
/// For more information on preparing SQL statements with parameterized values, please see <see cref="QueryDefinition"/>.
/// </summary>
/// <param name="feedRange">A FeedRange obtained from <see cref="Container.GetFeedRangesAsync(CancellationToken)"/>.</param>
/// <param name="queryDefinition">The Cosmos SQL query definition.</param>
/// <param name="continuationToken">(Optional) The continuation token in the Azure Cosmos DB service.</param>
/// <param name="requestOptions">(Optional) The options for the item query request.</param>
/// <returns>An iterator to go through the items.</returns>
/// <remarks>
/// Query as a stream only supports single partition queries
/// </remarks>
/// <exception>https://aka.ms/cosmosdb-dot-net-exceptions#typed-api</exception>
/// <example>
/// Create a query to get all the ToDoActivity that have a cost greater than 9000 for the specified partition
/// <code language="c#">
/// <![CDATA[
/// public class ToDoActivity{
/// public string id {get; set;}
/// public string status {get; set;}
/// public int cost {get; set;}
/// }
/// IReadOnlyList<FeedRange> feedRanges = await this.Container.GetFeedRangesAsync();
/// // Distribute feedRanges across multiple compute units and pass each one to a different iterator
/// QueryDefinition queryDefinition = new QueryDefinition("select * from ToDos t where t.cost > @expensive")
/// .WithParameter("@expensive", 9000);
/// using (FeedIterator<ToDoActivity> feedIterator = this.Container.GetItemQueryIterator<ToDoActivity>(
/// feedRanges[0],
/// queryDefinition,
/// null,
/// new QueryRequestOptions() { }))
/// {
/// while (feedIterator.HasMoreResults)
/// {
/// foreach(var item in await feedIterator.ReadNextAsync())
/// {
/// Console.WriteLine(item.cost);
/// }
/// }
/// }
/// ]]>
/// </code>
/// </example>
public abstract FeedIterator<T> GetItemQueryIterator<T>(
FeedRange feedRange,
QueryDefinition queryDefinition,
string continuationToken = null,
QueryRequestOptions requestOptions = null);

/// <summary>
/// This method creates a LINQ query for items under a container in an Azure Cosmos DB service.
/// IQueryable extension method ToFeedIterator() should be use for asynchronous execution with FeedIterator, please refer to example 2.
Expand Down Expand Up @@ -1562,108 +1664,6 @@ public abstract Task<IEnumerable<string>> GetPartitionKeyRangesAsync(
FeedRange feedRange,
CancellationToken cancellationToken = default);

/// <summary>
/// This method creates a query for items under a container in an Azure Cosmos database using a SQL statement with parameterized values. It returns a FeedIterator.
/// For more information on preparing SQL statements with parameterized values, please see <see cref="QueryDefinition"/>.
/// </summary>
/// <param name="feedRange">A FeedRange obtained from <see cref="Container.GetFeedRangesAsync(CancellationToken)"/></param>
/// <param name="queryDefinition">The Cosmos SQL query definition.</param>
/// <param name="continuationToken">(Optional) The continuation token in the Azure Cosmos DB service.</param>
/// <param name="requestOptions">(Optional) The options for the item query request.</param>
/// <returns>An iterator to go through the items.</returns>
/// <remarks>
/// Query as a stream only supports single partition queries
/// </remarks>
/// <exception>https://aka.ms/cosmosdb-dot-net-exceptions#stream-api</exception>
/// <example>
/// Create a query to get all the ToDoActivity that have a cost greater than 9000 for the specified partition
/// <code language="c#">
/// <![CDATA[
/// public class ToDoActivity{
/// public string id {get; set;}
/// public string status {get; set;}
/// public int cost {get; set;}
/// }
/// IReadOnlyList<FeedRange> feedRanges = await this.Container.GetFeedRangesAsync();
/// // Distribute feedRanges across multiple compute units and pass each one to a different iterator
/// QueryDefinition queryDefinition = new QueryDefinition("select * from ToDos t where t.cost > @expensive")
/// .WithParameter("@expensive", 9000);
/// using (FeedIterator feedIterator = this.Container.GetItemQueryStreamIterator(
/// feedRanges[0],
/// queryDefinition,
/// null,
/// new QueryRequestOptions() { }))
/// {
/// while (feedIterator.HasMoreResults)
/// {
/// using (ResponseMessage response = await feedIterator.ReadNextAsync())
/// {
/// using (StreamReader sr = new StreamReader(response.Content))
/// using (JsonTextReader jtr = new JsonTextReader(sr))
/// {
/// JObject result = JObject.Load(jtr);
/// }
/// }
/// }
/// }
/// ]]>
/// </code>
/// </example>
public abstract FeedIterator GetItemQueryStreamIterator(
FeedRange feedRange,
QueryDefinition queryDefinition,
string continuationToken,
QueryRequestOptions requestOptions = null);

/// <summary>
/// This method creates a query for items under a container in an Azure Cosmos database using a SQL statement with parameterized values. It returns a FeedIterator.
/// For more information on preparing SQL statements with parameterized values, please see <see cref="QueryDefinition"/>.
/// </summary>
/// <param name="feedRange">A FeedRange obtained from <see cref="Container.GetFeedRangesAsync(CancellationToken)"/>.</param>
/// <param name="queryDefinition">The Cosmos SQL query definition.</param>
/// <param name="continuationToken">(Optional) The continuation token in the Azure Cosmos DB service.</param>
/// <param name="requestOptions">(Optional) The options for the item query request.</param>
/// <returns>An iterator to go through the items.</returns>
/// <remarks>
/// Query as a stream only supports single partition queries
/// </remarks>
/// <exception>https://aka.ms/cosmosdb-dot-net-exceptions#typed-api</exception>
/// <example>
/// Create a query to get all the ToDoActivity that have a cost greater than 9000 for the specified partition
/// <code language="c#">
/// <![CDATA[
/// public class ToDoActivity{
/// public string id {get; set;}
/// public string status {get; set;}
/// public int cost {get; set;}
/// }
/// IReadOnlyList<FeedRange> feedRanges = await this.Container.GetFeedRangesAsync();
/// // Distribute feedRanges across multiple compute units and pass each one to a different iterator
/// QueryDefinition queryDefinition = new QueryDefinition("select * from ToDos t where t.cost > @expensive")
/// .WithParameter("@expensive", 9000);
/// using (FeedIterator<ToDoActivity> feedIterator = this.Container.GetItemQueryIterator<ToDoActivity>(
/// feedRanges[0],
/// queryDefinition,
/// null,
/// new QueryRequestOptions() { }))
/// {
/// while (feedIterator.HasMoreResults)
/// {
/// foreach(var item in await feedIterator.ReadNextAsync())
/// {
/// Console.WriteLine(item.cost);
/// }
/// }
/// }
/// ]]>
/// </code>
/// </example>
public abstract FeedIterator<T> GetItemQueryIterator<T>(
FeedRange feedRange,
QueryDefinition queryDefinition,
string continuationToken = null,
QueryRequestOptions requestOptions = null);

#endif
}
}
11 changes: 0 additions & 11 deletions Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,6 @@ public abstract Task<IEnumerable<string>> GetPartitionKeyRangesAsync(
FeedRange feedRange,
CancellationToken cancellationToken = default);

public abstract FeedIterator GetItemQueryStreamIterator(
FeedRange feedRange,
QueryDefinition queryDefinition,
string continuationToken,
QueryRequestOptions requestOptions = null);

public abstract FeedIterator<T> GetItemQueryIterator<T>(
FeedRange feedRange,
QueryDefinition queryDefinition,
string continuationToken = null,
QueryRequestOptions requestOptions = null);
#endif

public abstract class TryExecuteQueryResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,6 @@
"Microsoft.Azure.Cosmos.Container;System.Object;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": {
"Subclasses": {},
"Members": {
"Microsoft.Azure.Cosmos.FeedIterator GetItemQueryStreamIterator(Microsoft.Azure.Cosmos.FeedRange, Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.FeedIterator GetItemQueryStreamIterator(Microsoft.Azure.Cosmos.FeedRange, Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions);IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.FeedIterator`1[T] GetItemQueryIterator[T](Microsoft.Azure.Cosmos.FeedRange, Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.FeedIterator`1[T] GetItemQueryIterator[T](Microsoft.Azure.Cosmos.FeedRange, Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions);IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;"
},
"System.Threading.Tasks.Task`1[Microsoft.Azure.Cosmos.ResponseMessage] DeleteAllItemsByPartitionKeyStreamAsync(Microsoft.Azure.Cosmos.PartitionKey, Microsoft.Azure.Cosmos.RequestOptions, System.Threading.CancellationToken)": {
"Type": "Method",
"Attributes": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,11 @@
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.FeedIterator GetChangeFeedStreamIterator(Microsoft.Azure.Cosmos.ChangeFeedStartFrom, Microsoft.Azure.Cosmos.ChangeFeedMode, Microsoft.Azure.Cosmos.ChangeFeedRequestOptions);IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.FeedIterator GetItemQueryStreamIterator(Microsoft.Azure.Cosmos.FeedRange, Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.FeedIterator GetItemQueryStreamIterator(Microsoft.Azure.Cosmos.FeedRange, Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions);IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.FeedIterator GetItemQueryStreamIterator(Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions)": {
"Type": "Method",
"Attributes": [],
Expand All @@ -1053,6 +1058,11 @@
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.FeedIterator`1[T] GetChangeFeedIterator[T](Microsoft.Azure.Cosmos.ChangeFeedStartFrom, Microsoft.Azure.Cosmos.ChangeFeedMode, Microsoft.Azure.Cosmos.ChangeFeedRequestOptions);IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.FeedIterator`1[T] GetItemQueryIterator[T](Microsoft.Azure.Cosmos.FeedRange, Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.FeedIterator`1[T] GetItemQueryIterator[T](Microsoft.Azure.Cosmos.FeedRange, Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions);IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.FeedIterator`1[T] GetItemQueryIterator[T](Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions)": {
"Type": "Method",
"Attributes": [],
Expand Down

0 comments on commit 52f38c2

Please sign in to comment.