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

Query: Adds FeedRange API for Query to GA #3068

Merged
merged 5 commits into from
Mar 8, 2022
Merged
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
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,
neildsh marked this conversation as resolved.
Show resolved Hide resolved
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
}
}
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