void MoveNext() { do { if (!enumerator.MoveNext()) { enumerator = null; return; } } while (!filterExpr.Evaluate(enumerator.Current.Value)); }
public override Task <IList <TElement> > ExecuteQueryAtomicAsync <TElement>( TableQuery <TElement> query, TableRequestOptions requestOptions = null, OperationContext operationContext = null) { FilterExpression filterExpr = ChainTableUtils.ParseFilterString(query.FilterString); ChainTableUtils.GetSingleTargetedPartitionKey(filterExpr); // validation, ignore result if (query.SelectColumns != null) { throw new NotImplementedException("select"); } if (query.TakeCount != null) { throw new NotImplementedException("top"); } return(Task.FromResult( (IList <TElement>)(from kvp in table where filterExpr.Evaluate(kvp.Value) select ChainTableUtils.CopyEntity <TElement>(kvp.Value)).ToList())); }
// XXX: This could loop a long time. Do we want to make it cancelable? public async Task <TElement> ReadRowAsync() { using (await LockAsyncBuggable()) { CheckDisposed(); for (;;) { // Figure out which side has the next primary key to return (or // both) and pull the row(s) with that key from one or both sides. int?cmp = DetermineNextSide(); if (cmp == null) { return(default(TElement)); } MTableEntity nextInOld = null, nextInNew = null; if (cmp <= 0) { nextInOld = oldTableNext; oldTableNext = await oldTableStream.ReadRowAsync(); } if (cmp >= 0) { nextInNew = newTableNext; newTableNext = await newTableStream.ReadRowAsync(); } MTableEntity ent = (nextInNew != null) ? nextInNew : nextInOld; // Compare to end of ExecuteQueryAtomicAsync. if (!RowKeyIsInternal(ent.RowKey) && origFilterExpr.Evaluate(ent) && !ent.deleted) { return(ent.Export <TElement>()); } // Otherwise keep going. } } }
public override async Task <IList <TElement> > ExecuteQueryAtomicAsync <TElement>(TableQuery <TElement> query, TableRequestOptions requestOptions = null, OperationContext operationContext = null) { if (query.SelectColumns != null) { throw new NotImplementedException("select"); } if (query.TakeCount != null) { throw new NotImplementedException("top"); } FilterExpression origFilterExpr = ChainTableUtils.ParseFilterString(query.FilterString); string partitionKey = ChainTableUtils.GetSingleTargetedPartitionKey(origFilterExpr); TableQuery <MTableEntity> mtableQuery = ChainTableUtils.CopyQuery <TElement, MTableEntity>(query); MTableConfiguration config; using (configService.Subscribe(FixedSubscriber <MTableConfiguration> .Instance, out config)) { IEnumerable <MTableEntity> results; if (config.state <= TableClientState.USE_OLD_HIDE_METADATA) { results = await oldTable.ExecuteQueryAtomicAsync(mtableQuery, requestOptions, operationContext); await monitor.AnnotateLastBackendCallAsync(wasLinearizationPoint : true); } else if (config.state >= TableClientState.USE_NEW_WITH_TOMBSTONES) { results = await newTable.ExecuteQueryAtomicAsync(mtableQuery, requestOptions, operationContext); await monitor.AnnotateLastBackendCallAsync(wasLinearizationPoint : true); } else { // Modify the filter to make sure it matches the meta row. if (origFilterExpr is ComparisonExpression) { // filterExpr must be "PartitionKey eq A", which already matches the meta row; nothing to do. } else { // filterExpr must be "(PartitionKey eq A) and (B)". // Rewrite to "(PartitionKey eq A) and ((RowKey eq ROW_KEY_PARTITION_META) or (B))". var boe = (BooleanOperatorExpression)origFilterExpr; mtableQuery.FilterString = TableQuery.CombineFilters(boe.Left.ToFilterString(), TableOperators.And, TableQuery.CombineFilters( TableQuery.GenerateFilterCondition(TableConstants.RowKey, QueryComparisons.Equal, ROW_KEY_PARTITION_META), TableOperators.Or, boe.Right.ToFilterString())); } IList <MTableEntity> oldRows = await oldTable.ExecuteQueryAtomicAsync(mtableQuery, requestOptions, operationContext); MTablePartitionState?state = (from r in oldRows where r.RowKey == ROW_KEY_PARTITION_META select r.partitionState).SingleOrDefault(); IList <MTableEntity> newRows; if (state == MTablePartitionState.SWITCHED) { await monitor.AnnotateLastBackendCallAsync(); // If the filter string includes conditions on user-defined properties, // a row in the old table can be shadowed by a row in the new table // that doesn't satisfy those conditions. To make sure we retrieve all // potential shadowing rows, retrieve the entire partition. // XXX: At a minimum, we should try to keep conditions on the // primary key, but how clever do we want to get with query rewriting? if (!IsBugEnabled(MTableOptionalBug.QueryAtomicFilterShadowing)) { mtableQuery.FilterString = TableQuery.GenerateFilterCondition( TableConstants.PartitionKey, QueryComparisons.Equal, partitionKey); } newRows = await newTable.ExecuteQueryAtomicAsync(mtableQuery, requestOptions, operationContext); await monitor.AnnotateLastBackendCallAsync(wasLinearizationPoint : true); } else { await monitor.AnnotateLastBackendCallAsync(wasLinearizationPoint : true); newRows = new List <MTableEntity>(); } // Merge lists. Hopefully this is pretty clear. Walking the lists // in lockstep might be faster but is a lot more code. var merged = new SortedDictionary <string, MTableEntity>(StringComparer.Ordinal); foreach (MTableEntity ent in oldRows) { merged[ent.RowKey] = ent; } foreach (MTableEntity ent in newRows) { merged[ent.RowKey] = ent; } results = merged.Values; } return((from ent in results where !RowKeyIsInternal(ent.RowKey) && origFilterExpr.Evaluate(ent) && !ent.deleted select ent.Export <TElement>()).ToList()); } }
internal List <DynamicTableEntity> GetValidStreamReadRows(int startRevision, FilterExpression filterExpr, PrimaryKey continuationKey) { IEnumerable <IEnumerable <DynamicTableEntity> > filteredDumps = from dump in dumps.Skip(startRevision) select dump.Values.Where(row => (row.GetPrimaryKey().CompareTo(continuationKey) >= 0) && filterExpr.Evaluate(row)); PrimaryKey nextMandatoryKey = (from dump in filteredDumps select dump.Select(row => row.GetPrimaryKey())).IntersectAll().FirstOrDefault(); List <DynamicTableEntity> possible = filteredDumps.SelectMany(dump => dump.Where(row => (nextMandatoryKey == null || row.GetPrimaryKey().CompareTo(nextMandatoryKey) <= 0))) .Distinct((IEqualityComparer <DynamicTableEntity>)BetterComparer.Instance).ToList(); if (nextMandatoryKey == null) { possible.Add(null); // i.e., "end of stream" is a valid read } return(possible); }