示例#1
0
        internal async Task <List <(ReminderTableEntry Entity, string ETag)> > FindReminderEntries(uint begin, uint end)
        {
            string sBegin = ReminderTableEntry.ConstructPartitionKey(ServiceId, begin);
            string sEnd   = ReminderTableEntry.ConstructPartitionKey(ServiceId, end);
            string query;

            if (begin < end)
            {
                // Query between the specified lower and upper bounds.
                // Note that the lower bound is exclusive and the upper bound is inclusive in the below query.
                query = TableClient.CreateQueryFilter($"(PartitionKey gt {sBegin}) and (PartitionKey le {sEnd})");
            }
            else
            {
                var(partitionKeyLowerBound, partitionKeyUpperBound) = ReminderTableEntry.ConstructPartitionKeyBounds(ServiceId);
                if (begin == end)
                {
                    // Query the entire range
                    query = TableClient.CreateQueryFilter($"(PartitionKey gt {partitionKeyLowerBound}) and (PartitionKey lt {partitionKeyUpperBound})");
                }
                else
                {
                    // (begin > end)
                    // Query wraps around the ends of the range, so the query is the union of two disjunct queries
                    // Include everything outside of the (begin, end] range, which wraps around to become:
                    // [partitionKeyLowerBound, end] OR (begin, partitionKeyUpperBound]
                    Debug.Assert(begin > end);
                    query = TableClient.CreateQueryFilter($"((PartitionKey gt {partitionKeyLowerBound}) and (PartitionKey le {sEnd})) or ((PartitionKey gt {sBegin}) and (PartitionKey lt {partitionKeyUpperBound}))");
                }
            }

            var queryResults = await ReadTableEntriesAndEtagsAsync(query);

            return(queryResults.ToList());
        }
示例#2
0
        private async Task UnregisterManyBlock(List <GrainAddress> addresses)
        {
            var queryBuilder = new StringBuilder();

            queryBuilder.Append(TableClient.CreateQueryFilter($"(PartitionKey eq {clusterId}) and ("));
            var first = true;

            foreach (var addr in addresses)
            {
                if (!first)
                {
                    queryBuilder.Append(" or ");
                }
                else
                {
                    first = false;
                }

                var rowKey      = GrainDirectoryEntity.GrainIdToRowKey(addr.GrainId);
                var queryClause = TableClient.CreateQueryFilter($"((RowKey eq {rowKey}) and (ActivationId eq {addr.ActivationId.ToString()}))");
                queryBuilder.Append(queryClause);
            }

            queryBuilder.Append(')');
            var entities = await this.tableDataManager.ReadTableEntriesAndEtagsAsync(queryBuilder.ToString());

            await this.tableDataManager.DeleteTableEntriesAsync(entities);
        }
示例#3
0
        internal async Task <List <(ReminderTableEntry Entity, string ETag)> > FindReminderEntries(GrainReference grainRef)
        {
            var partitionKey = ReminderTableEntry.ConstructPartitionKey(ServiceId, grainRef);

            var(rowKeyLowerBound, rowKeyUpperBound) = ReminderTableEntry.ConstructRowKeyBounds(grainRef);
            var query        = TableClient.CreateQueryFilter($"(PartitionKey eq {partitionKey}) and ((RowKey gt {rowKeyLowerBound}) and (RowKey le {rowKeyUpperBound}))");
            var queryResults = await ReadTableEntriesAndEtagsAsync(query);

            return(queryResults.ToList());
        }
示例#4
0
    public static string SearchStatesQuery(
        string oneFuzzVersion,
        Guid?poolId     = default,
        Guid?scaleSetId = default,
        IEnumerable <NodeState>?states = default,
        PoolName?poolName           = default,
        bool excludeUpdateScheduled = false,
        int?numResults = default)
    {
        List <string> queryParts = new();

        if (poolId is not null)
        {
            queryParts.Add($"(pool_id eq '{poolId}')");
        }

        if (poolName is not null)
        {
            queryParts.Add($"(PartitionKey eq '{poolName}')");
        }

        if (scaleSetId is not null)
        {
            queryParts.Add($"(scaleset_id eq '{scaleSetId}')");
        }

        if (states is not null)
        {
            var q = Query.EqualAnyEnum("state", states);
            queryParts.Add($"({q})");
        }

        if (excludeUpdateScheduled)
        {
            queryParts.Add($"reimage_requested eq false");
            queryParts.Add($"delete_requested eq false");
        }

        //# azure table query always return false when the column does not exist
        //# We write the query this way to allow us to get the nodes where the
        //# version is not defined as well as the nodes with a mismatched version
        var versionQuery = TableClient.CreateQueryFilter($"not (version eq {oneFuzzVersion})");

        queryParts.Add(versionQuery);

        return(Query.And(queryParts));
    }
        // Used as an alternative to binding to IQueryable.
        private async Task <JArray> CreateJArray(TableAttribute attribute, CancellationToken cancellation)
        {
            var table = GetTable(attribute);

            string filter = attribute.Filter;

            if (!string.IsNullOrEmpty(attribute.PartitionKey))
            {
                var partitionKeyPredicate = TableClient.CreateQueryFilter($"PartitionKey eq {attribute.PartitionKey}");
                if (!string.IsNullOrEmpty(filter))
                {
                    filter = $"{partitionKeyPredicate} and {filter}";
                }
                else
                {
                    filter = partitionKeyPredicate;
                }
            }

            int?maxPerPage = null;

            if (attribute.Take > 0)
            {
                maxPerPage = attribute.Take;
            }

            int countRemaining = attribute.Take;

            JArray entityArray = new JArray();
            var    entities    = table.QueryAsync <TableEntity>(
                filter: filter,
                maxPerPage: maxPerPage,
                cancellationToken: cancellation).ConfigureAwait(false);

            await foreach (var entity in entities)
            {
                countRemaining--;
                entityArray.Add(ConvertEntityToJObject(entity));
                if (countRemaining == 0)
                {
                    break;
                }
            }
            return(entityArray);
        }
        public async Task TableQueryableComplexFilterWithCreateFilter()
        {
            var entitiesToCreate = CreateComplexTableEntities(PartitionKeyValue, 4);

            // Create the new entities.

            await CreateTestEntities(entitiesToCreate).ConfigureAwait(false);

            var filter  = TableClient.CreateQueryFilter <ComplexEntity>(ent => (ent.RowKey == "0004" && ent.Int32 == 4) || ((ent.Int32 == 2) && (ent.String == "wrong string" || ent.Bool == true)) || (ent.LongPrimitiveN == (long)int.MaxValue + 50));
            var results = await client.QueryAsync <ComplexEntity>(filter).ToEnumerableAsync().ConfigureAwait(false);

            foreach (ComplexEntity ent in results)
            {
                Assert.IsTrue(ent.Int32 == 4 || ent.Int32 == 2);
            }

            Assert.That(results.Count, Is.EqualTo(2));
        }
        public void QueryEntities()
        {
            string storageUri        = StorageUri;
            string accountName       = StorageAccountName;
            string storageAccountKey = PrimaryStorageAccountKey;
            string tableName         = "OfficeSupplies4p1";
            string partitionKey      = "somePartition";
            string rowKey            = "1";
            string rowKey2           = "2";

            var serviceClient = new TableServiceClient(
                new Uri(storageUri),
                new TableSharedKeyCredential(accountName, storageAccountKey));

            serviceClient.CreateTable(tableName);
            var tableClient = serviceClient.GetTableClient(tableName);

            var entity = new TableEntity(partitionKey, rowKey)
            {
                { "Product", "Markers" },
                { "Price", 5.00 },
                { "Quantity", 34 }
            };

            tableClient.AddEntity(entity);

            var entity2 = new TableEntity(partitionKey, rowKey2)
            {
                { "Product", "Planner" },
                { "Price", 7.00 },
                { "Quantity", 34 }
            };

            tableClient.AddEntity(entity2);

            #region Snippet:TablesSample4QueryEntitiesFilter
            Pageable <TableEntity> queryResultsFilter = tableClient.Query <TableEntity>(filter: $"PartitionKey eq '{partitionKey}'");

            // Iterate the <see cref="Pageable"> to access all queried entities.

            foreach (TableEntity qEntity in queryResultsFilter)
            {
                Console.WriteLine($"{qEntity.GetString("Product")}: {qEntity.GetDouble("Price")}");
            }

            Console.WriteLine($"The query returned {queryResultsFilter.Count()} entities.");
            #endregion

            #region Snippet:TablesSample4QueryEntitiesFilterWithQueryFilter
            // The CreateQueryFilter method is also available to assist with properly formatting and escaping OData queries.
#if SNIPPET
            Pageable <TableEntity> queryResultsFilter = tableClient.Query <TableEntity>(filter: TableClient.CreateQueryFilter($"PartitionKey eq {partitionKey}"));
#else
            queryResultsFilter = tableClient.Query <TableEntity>(filter: TableClient.CreateQueryFilter($"PartitionKey eq {partitionKey}"));
#endif
            // Iterate the <see cref="Pageable"> to access all queried entities.

            foreach (TableEntity qEntity in queryResultsFilter)
            {
                Console.WriteLine($"{qEntity.GetString("Product")}: {qEntity.GetDouble("Price")}");
            }

            Console.WriteLine($"The query returned {queryResultsFilter.Count()} entities.");

            // It handles esca
            #endregion
            #region Snippet:TablesSample4QueryEntitiesExpression
            // Use the <see cref="TableClient"> to query the table using a filter expression.

            double priceCutOff = 6.00;
            Pageable <OfficeSupplyEntity> queryResultsLINQ = tableClient.Query <OfficeSupplyEntity>(ent => ent.Price >= priceCutOff);
            #endregion

            #region Snippet:TablesSample4QueryEntitiesSelect
            Pageable <TableEntity> queryResultsSelect = tableClient.Query <TableEntity>(select: new List <string>()
            {
                "Product", "Price"
            });
            #endregion

            #region Snippet:TablesSample4QueryEntitiesMaxPerPage
            Pageable <TableEntity> queryResultsMaxPerPage = tableClient.Query <TableEntity>(maxPerPage: 10);

            // Iterate the <see cref="Pageable"> by page.

            foreach (Page <TableEntity> page in queryResultsMaxPerPage.AsPages())
            {
                Console.WriteLine("This is a new page!");
                foreach (TableEntity qEntity in page.Values)
                {
                    Console.WriteLine($"# of {qEntity.GetString("Product")} inventoried: {qEntity.GetInt32("Quantity")}");
                }
            }
            #endregion

            serviceClient.DeleteTable(tableName);
        }
示例#8
0
        public async Task <IList <Uri> > FindAllGatewayProxyEndpoints()
        {
            if (logger.IsEnabled(LogLevel.Debug))
            {
                logger.LogDebug((int)ErrorCode.Runtime_Error_100277, "Searching for active gateway silos for deployment {DeploymentId}.", this.DeploymentId);
            }

            try
            {
                const string Active       = nameof(SiloStatus.Active);
                const string Zero         = "0";
                var          queryResults = await storage.ReadTableEntriesAndEtagsAsync(TableClient.CreateQueryFilter($"PartitionKey eq {DeploymentId} and Status eq {Active} and ProxyPort ne {Zero}"));

                var gatewaySiloInstances = queryResults.Select(entity => ConvertToGatewayUri(entity.Item1)).ToList();

                logger.LogInformation((int)ErrorCode.Runtime_Error_100278, "Found {GatewaySiloCount} active Gateway Silos for deployment {DeploymentId}.", gatewaySiloInstances.Count, this.DeploymentId);
                return(gatewaySiloInstances);
            }catch (Exception exc)
            {
                logger.LogError((int)ErrorCode.Runtime_Error_100331, exc, "Error searching for active gateway silos for deployment {DeploymentId} ", this.DeploymentId);
                throw;
            }
        }
示例#9
0
 public static string SingleEntity(string partitionKey, string rowKey)
 => TableClient.CreateQueryFilter($"(PartitionKey eq {partitionKey}) and (RowKey eq {rowKey})");
示例#10
0
 public static string RowKey(string rowKey)
 => TableClient.CreateQueryFilter($"RowKey eq {rowKey}");
示例#11
0
 internal static string PointQuery(string partitionKey, string rowKey)
 {
     return(TableClient.CreateQueryFilter($"(PartitionKey eq {partitionKey}) and (RowKey eq {rowKey})"));
 }
示例#12
0
 internal static string RangeQuery(string partitionKey, string minRowKey, string maxRowKey)
 {
     return(TableClient.CreateQueryFilter($"((PartitionKey eq {partitionKey}) and (RowKey ge {minRowKey})) and (RowKey le {maxRowKey})"));
 }
示例#13
0
 public static string TimeRange(DateTimeOffset min, DateTimeOffset max)
 {
     // NB: this uses the auto-populated Timestamp property, and will result in a table scan
     // TODO: should this be inclusive at the endpoints?
     return(TableClient.CreateQueryFilter($"Timestamp lt {max} and Timestamp gt {min}"));
 }
示例#14
0
        public void TestDynamicTableEntityFilterExpressions(string expectedFilter, Expression <Func <DynamicTableEntity, bool> > expression)
        {
            var filter = TableClient.CreateQueryFilter(expression);

            Assert.That(filter, Is.EqualTo(expectedFilter));
        }
示例#15
0
        // For all queries below, note that TableClient.CreateQueryFilter takes a FormattableString
        // and handles escaping the interpolated values properly. It also handles quoting the values
        // where needed, so use {string} and not '{string}'.

        public static string PartitionKey(string partitionKey)
        => TableClient.CreateQueryFilter($"PartitionKey eq {partitionKey}");
示例#16
0
 public IAsyncEnumerable <Pool> GetByClientId(Guid clientId)
 {
     return(QueryAsync(filter: TableClient.CreateQueryFilter($"client_id eq {clientId}")));
 }
示例#17
0
 public IAsyncEnumerable <Node> SearchByPoolName(PoolName poolName)
 {
     return(QueryAsync(TableClient.CreateQueryFilter($"(pool_name eq {poolName})")));
 }