Esempio n. 1
0
        public override FeedIterator <T> CreateItemQuery <T>(
            CosmosSqlQueryDefinition sqlQueryDefinition,
            int maxConcurrency,
            int?maxItemCount                   = null,
            string continuationToken           = null,
            QueryRequestOptions requestOptions = null)
        {
            requestOptions = requestOptions ?? new QueryRequestOptions();
            requestOptions.EnableCrossPartitionQuery = true;
            requestOptions.RequestContinuation       = continuationToken;
            requestOptions.MaxItemCount   = maxItemCount;
            requestOptions.MaxConcurrency = maxConcurrency;

            CosmosQueryExecutionContext cosmosQueryExecution = new CosmosQueryExecutionContextFactory(
                client: this.queryClient,
                resourceTypeEnum: ResourceType.Document,
                operationType: OperationType.Query,
                resourceType: typeof(T),
                sqlQuerySpec: sqlQueryDefinition.ToSqlQuerySpec(),
                queryRequestOptions: requestOptions,
                resourceLink: this.LinkUri,
                isContinuationExpected: true,
                allowNonValueAggregateQuery: true,
                correlatedActivityId: Guid.NewGuid());

            return(new FeedIteratorCore <T>(
                       maxItemCount,
                       continuationToken,
                       requestOptions,
                       this.NextResultSetAsync <T>,
                       cosmosQueryExecution));
        }
 /// <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 CosmosResultSetStreamIterator.
 ///  For more information on preparing SQL statements with parameterized values, please see <see cref="CosmosSqlQueryDefinition"/>.
 /// </summary>
 /// <param name="sqlQueryDefinition">The cosmos SQL query definition.</param>
 /// <param name="maxConcurrency">The number of concurrent operations run client side during parallel query execution in the Azure Cosmos DB service.</param>
 /// <param name="partitionKey">The partition key for the item. <see cref="Microsoft.Azure.Documents.PartitionKey"/></param>
 /// <param name="maxItemCount">(Optional) The max item count to return as part of the query</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 <see cref="QueryRequestOptions"/></param>
 /// <remarks>
 /// Query as a stream only supports single partition queries
 /// </remarks>
 /// <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;}
 /// }
 ///
 /// CosmosSqlQueryDefinition sqlQuery = new CosmosSqlQueryDefinition("select * from ToDos t where t.cost > @expensive").UseParameter("@expensive", 9000);
 /// FeedIterator feedIterator = this.Container.CreateItemQueryStream(
 ///     sqlQueryDefinition: sqlQuery,
 ///     partitionKey: "Error");
 ///
 /// while (feedIterator.HasMoreResults)
 /// {
 ///     using (CosmosResponseMessage response = await feedIterator.FetchNextSetAsync())
 ///     {
 ///         using (StreamReader sr = new StreamReader(response.Content))
 ///         using (JsonTextReader jtr = new JsonTextReader(sr))
 ///         {
 ///             JObject result = JObject.Load(jtr);
 ///         }
 ///     }
 /// }
 /// ]]>
 /// </code>
 /// </example>
 /// <returns>An iterator to go through the items.</returns>
 public abstract FeedIterator CreateItemQueryStream(
     CosmosSqlQueryDefinition sqlQueryDefinition,
     int maxConcurrency,
     PartitionKey partitionKey          = null,
     int?maxItemCount                   = null,
     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 CosmosResultSetStreamIterator.
 ///  For more information on preparing SQL statements with parameterized values, please see <see cref="CosmosSqlQueryDefinition"/>.
 /// </summary>
 /// <param name="sqlQueryDefinition">The cosmos SQL query definition.</param>
 /// <param name="maxConcurrency">The number of concurrent operations run client side during parallel query execution in the Azure Cosmos DB service.</param>
 /// <param name="partitionKey">The partition key for the item. <see cref="Microsoft.Azure.Documents.PartitionKey"/></param>
 /// <param name="maxItemCount">(Optional) The max item count to return as part of the query</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 <see cref="CosmosQueryRequestOptions"/></param>
 /// <remarks>
 /// Query as a stream only supports single partition queries
 /// </remarks>
 /// <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;}
 /// }
 ///
 /// CosmosSqlQueryDefinition sqlQuery = new CosmosSqlQueryDefinition("select * from ToDos t where t.cost > @expensive").UseParameter("@expensive", 9000);
 /// CosmosResultSetIterator setIterator = this.Container.Items.CreateItemQueryAsStream(
 ///     sqlQueryDefinition: sqlQuery,
 ///     partitionKey: "Error");
 ///
 /// while (setIterator.HasMoreResults)
 /// {
 ///     using (CosmosResponseMessage response = await setIterator.FetchNextSetAsync())
 ///     {
 ///         using (StreamReader sr = new StreamReader(response.Content))
 ///         using (JsonTextReader jtr = new JsonTextReader(sr))
 ///         {
 ///             JObject result = JObject.Load(jtr);
 ///         }
 ///     }
 /// }
 /// ]]>
 /// </code>
 /// </example>
 public abstract CosmosResultSetIterator CreateItemQueryAsStream(
     CosmosSqlQueryDefinition sqlQueryDefinition,
     int maxConcurrency,
     object partitionKey      = null,
     int?maxItemCount         = null,
     string continuationToken = null,
     CosmosQueryRequestOptions requestOptions = null);
        public override CosmosResultSetIterator CreateItemQueryAsStream(
            CosmosSqlQueryDefinition sqlQueryDefinition,
            int maxConcurrency,
            object partitionKey      = null,
            int?maxItemCount         = null,
            string continuationToken = null,
            CosmosQueryRequestOptions requestOptions = null)
        {
            requestOptions = requestOptions ?? new CosmosQueryRequestOptions();
            requestOptions.MaxConcurrency            = maxConcurrency;
            requestOptions.EnableCrossPartitionQuery = true;
            requestOptions.RequestContinuation       = continuationToken;
            requestOptions.MaxItemCount = maxItemCount;
            requestOptions.PartitionKey = partitionKey;

            IDocumentQueryExecutionContext documentQueryExecution = new CosmosQueryExecutionContextFactory(
                client: this.queryClient,
                resourceTypeEnum: ResourceType.Document,
                operationType: OperationType.Query,
                resourceType: typeof(CosmosQueryResponse),
                sqlQuerySpec: sqlQueryDefinition.ToSqlQuerySpec(),
                queryRequestOptions: requestOptions,
                resourceLink: this.container.LinkUri,
                isContinuationExpected: true,
                allowNonValueAggregateQuery: true,
                correlatedActivityId: Guid.NewGuid());

            return(new CosmosResultSetIteratorCore(
                       maxItemCount,
                       continuationToken,
                       requestOptions,
                       this.QueryRequestExecutor,
                       documentQueryExecution));
        }
Esempio n. 5
0
        public override CosmosResultSetIterator CreateItemQueryAsStream(
            CosmosSqlQueryDefinition sqlQueryDefinition,
            int maxConcurrency,
            object partitionKey      = null,
            int?maxItemCount         = null,
            string continuationToken = null,
            CosmosQueryRequestOptions requestOptions = null)
        {
            requestOptions = requestOptions ?? new CosmosQueryRequestOptions();
            requestOptions.maxConcurrency            = maxConcurrency;
            requestOptions.EnableCrossPartitionQuery = true;

            FeedOptions feedOptions = requestOptions.ToFeedOptions();

            feedOptions.RequestContinuation = continuationToken;
            feedOptions.MaxItemCount        = maxItemCount;
            if (partitionKey != null)
            {
                PartitionKey pk = new PartitionKey(partitionKey);
                feedOptions.PartitionKey = pk;
            }

            DocumentQuery <CosmosQueryResponse> documentQuery = (DocumentQuery <CosmosQueryResponse>) this.client.DocumentClient.CreateDocumentQuery <CosmosQueryResponse>(
                collectionLink: this.container.LinkUri.OriginalString,
                feedOptions: feedOptions,
                querySpec: sqlQueryDefinition.ToSqlQuerySpec());

            return(new CosmosResultSetIteratorCore(
                       maxItemCount,
                       continuationToken,
                       requestOptions,
                       this.QueryRequestExecutor,
                       documentQuery));
        }
 /// <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 CosmosResultSetIterator.
 ///  For more information on preparing SQL statements with parameterized values, please see <see cref="CosmosSqlQueryDefinition"/>.
 /// </summary>
 /// <param name="sqlQueryDefinition">The cosmos SQL query definition.</param>
 /// <param name="maxConcurrency">The number of concurrent operations run client side during parallel query execution in the Azure Cosmos DB service.</param>
 /// <param name="maxItemCount">(Optional) The max item count to return as part of the query</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 <see cref="CosmosQueryRequestOptions"/></param>
 /// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
 /// <example>
 /// Create a query to get all the ToDoActivity that have a cost greater than 9000
 /// <code language="c#">
 /// <![CDATA[
 /// public class ToDoActivity{
 ///     public string id {get; set;}
 ///     public string status {get; set;}
 ///     public int cost {get; set;}
 /// }
 ///
 /// CosmosSqlQueryDefinition sqlQuery = new CosmosSqlQueryDefinition("select * from ToDos t where t.cost > @expensive").UseParameter("@expensive", 9000);
 /// CosmosResultSetIterator<ToDoActivity> setIterator = this.Container.Items.CreateItemQuery<ToDoActivity>(
 ///     sqlQuery,
 ///     maxConcurrency: 2);
 ///
 /// while (setIterator.HasMoreResults)
 /// {
 ///     foreach(var item in await setIterator.FetchNextSetAsync()){
 ///     {
 ///         Console.WriteLine(item.cost);
 ///     }
 /// }
 /// ]]>
 /// </code>
 /// </example>
 public abstract CosmosResultSetIterator <T> CreateItemQuery <T>(
     CosmosSqlQueryDefinition sqlQueryDefinition,
     int maxConcurrency,
     int?maxItemCount         = null,
     string continuationToken = null,
     CosmosQueryRequestOptions requestOptions = null,
     CancellationToken cancellationToken      = default(CancellationToken));
Esempio n. 7
0
        public override CosmosResultSetIterator <T> CreateItemQuery <T>(
            CosmosSqlQueryDefinition sqlQueryDefinition,
            int maxConcurrency,
            int?maxItemCount         = null,
            string continuationToken = null,
            CosmosQueryRequestOptions requestOptions = null,
            CancellationToken cancellationToken      = default(CancellationToken))
        {
            CosmosQueryRequestOptions options = requestOptions ?? new CosmosQueryRequestOptions();

            options.maxConcurrency            = maxConcurrency;
            options.EnableCrossPartitionQuery = true;

            return(new CosmosDefaultResultSetIterator <T>(
                       maxItemCount,
                       continuationToken,
                       options,
                       this.NextResultSetAsync <T>,
                       sqlQueryDefinition.ToSqlQuerySpec()));
        }
Esempio n. 8
0
        public override CosmosResultSetIterator <T> CreateItemQuery <T>(
            CosmosSqlQueryDefinition sqlQueryDefinition,
            object partitionKey,
            int?maxItemCount         = null,
            string continuationToken = null,
            CosmosQueryRequestOptions requestOptions = null)
        {
            CosmosQueryRequestOptions options = requestOptions ?? new CosmosQueryRequestOptions();

            if (partitionKey != null)
            {
                PartitionKey pk = new PartitionKey(partitionKey);
                options.PartitionKey = pk;
            }

            options.EnableCrossPartitionQuery = false;

            return(new CosmosDefaultResultSetIterator <T>(
                       maxItemCount,
                       continuationToken,
                       options,
                       this.NextResultSetAsync <T>,
                       sqlQueryDefinition.ToSqlQuerySpec()));
        }
 /// <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="CosmosSqlQueryDefinition"/>.
 /// </summary>
 /// <param name="sqlQueryDefinition">The cosmos SQL query definition.</param>
 /// <param name="partitionKey">The partition key for the item. <see cref="Microsoft.Azure.Documents.PartitionKey"/></param>
 /// <param name="maxItemCount">(Optional) The max item count to return as part of the query</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 <see cref="QueryRequestOptions"/></param>
 /// <example>
 /// Create a query to get all the ToDoActivity that have a cost greater than 9000
 /// <code language="c#">
 /// <![CDATA[
 /// public class ToDoActivity{
 ///     public string id {get; set;}
 ///     public string status {get; set;}
 ///     public int cost {get; set;}
 /// }
 ///
 /// CosmosSqlQueryDefinition sqlQuery = new CosmosSqlQueryDefinition("select * from ToDos t where t.cost > @expensive").UseParameter("@expensive", 9000);
 /// FeedIterator<ToDoActivity> feedIterator = this.Container.CreateItemQuery<ToDoActivity>(
 ///     sqlQueryDefinition: sqlQuery,
 ///     partitionKey: "Error");
 ///
 /// while (feedIterator.HasMoreResults)
 /// {
 ///     foreach(var item in await feedIterator.FetchNextSetAsync()){
 ///     {
 ///         Console.WriteLine(item.cost);
 ///     }
 /// }
 /// ]]>
 /// </code>
 /// </example>
 /// <returns>An iterator to go through the items.</returns>
 public abstract FeedIterator <T> CreateItemQuery <T>(
     CosmosSqlQueryDefinition sqlQueryDefinition,
     PartitionKey partitionKey,
     int?maxItemCount                   = null,
     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 CosmosResultSetIterator.
 ///  For more information on preparing SQL statements with parameterized values, please see <see cref="CosmosSqlQueryDefinition"/>.
 /// </summary>
 /// <param name="sqlQueryDefinition">The cosmos SQL query definition.</param>
 /// <param name="partitionKey">The partition key for the item. <see cref="Microsoft.Azure.Documents.PartitionKey"/></param>
 /// <param name="maxItemCount">(Optional) The max item count to return as part of the query</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 <see cref="CosmosQueryRequestOptions"/></param>
 /// <example>
 /// Create a query to get all the ToDoActivity that have a cost greater than 9000
 /// <code language="c#">
 /// <![CDATA[
 /// public class ToDoActivity{
 ///     public string id {get; set;}
 ///     public string status {get; set;}
 ///     public int cost {get; set;}
 /// }
 ///
 /// CosmosSqlQueryDefinition sqlQuery = new CosmosSqlQueryDefinition("select * from ToDos t where t.cost > @expensive").UseParameter("@expensive", 9000);
 /// CosmosResultSetIterator<ToDoActivity> setIterator = this.Container.Items.CreateItemQuery<ToDoActivity>(
 ///     sqlQueryDefinition: sqlQuery,
 ///     partitionKey: "Error");
 ///
 /// while (setIterator.HasMoreResults)
 /// {
 ///     foreach(var item in await setIterator.FetchNextSetAsync()){
 ///     {
 ///         Console.WriteLine(item.cost);
 ///     }
 /// }
 /// ]]>
 /// </code>
 /// </example>
 public abstract CosmosResultSetIterator <T> CreateItemQuery <T>(
     CosmosSqlQueryDefinition sqlQueryDefinition,
     object partitionKey,
     int?maxItemCount         = null,
     string continuationToken = null,
     CosmosQueryRequestOptions requestOptions = null);