private static void SplitQueryFilter(Filter filter, Table targetTable, string indexName, out Dictionary <string, Condition> keyConditions, out Dictionary <string, Condition> filterConditions) { QueryFilter queryFilter = filter as QueryFilter; if (queryFilter == null) { throw new InvalidOperationException("Filter is not of type QueryFilter"); } keyConditions = new Dictionary <string, Condition>(); filterConditions = new Dictionary <string, Condition>(); var conditions = filter.ToConditions(targetTable); foreach (var kvp in conditions) { string attributeName = kvp.Key; Condition condition = kvp.Value; // depending on whether the attribute is key, place either in keyConditions or filterConditions if (IsKeyAttribute(targetTable, indexName, attributeName)) { keyConditions[attributeName] = condition; } else { filterConditions[attributeName] = condition; } } }
private static void SplitQueryFilter(Filter filter, Table targetTable, string indexName, out Dictionary<string, Condition> keyConditions, out Dictionary<string, Condition> filterConditions) { QueryFilter queryFilter = filter as QueryFilter; if (queryFilter == null) throw new InvalidOperationException("Filter is not of type QueryFilter"); keyConditions = new Dictionary<string, Condition>(); filterConditions = new Dictionary<string, Condition>(); var conditions = filter.ToConditions(targetTable.Conversion); foreach (var kvp in conditions) { string attributeName = kvp.Key; Condition condition = kvp.Value; // depending on whether the attribute is key, place either in keyConditions or filterConditions if (IsKeyAttribute(targetTable, indexName, attributeName)) keyConditions[attributeName] = condition; else filterConditions[attributeName] = condition; } }
private int GetCount() { if (IsDone && CollectResults) { return(Matches.Count); } else { if (count != -1) { return(count); } else { switch (SearchMethod) { case SearchType.Scan: ScanRequest scanReq = new ScanRequest { TableName = TableName, Select = EnumMapper.Convert(SelectValues.Count), ExclusiveStartKey = NextKey, ScanFilter = Filter.ToConditions(SourceTable.Conversion, SourceTable.IsEmptyStringValueEnabled), ConsistentRead = IsConsistentRead }; if (!string.IsNullOrEmpty(this.IndexName)) { scanReq.IndexName = this.IndexName; } if (this.FilterExpression != null && this.FilterExpression.IsSet) { this.FilterExpression.ApplyExpression(scanReq, SourceTable); } if (scanReq.ScanFilter != null && scanReq.ScanFilter.Count > 1) { scanReq.ConditionalOperator = EnumMapper.Convert(ConditionalOperator); } if (this.TotalSegments != 0) { scanReq.TotalSegments = this.TotalSegments; scanReq.Segment = this.Segment; } SourceTable.AddRequestHandler(scanReq, isAsync: false); var scanResult = SourceTable.DDBClient.Scan(scanReq); count = Matches.Count + scanResult.Count; return(count); case SearchType.Query: QueryRequest queryReq = new QueryRequest { TableName = TableName, ConsistentRead = IsConsistentRead, Select = EnumMapper.Convert(SelectValues.Count), ExclusiveStartKey = NextKey, ScanIndexForward = !IsBackwardSearch, IndexName = IndexName }; Expression.ApplyExpression(queryReq, SourceTable, KeyExpression, FilterExpression); Dictionary <string, Condition> keyConditions, filterConditions; SplitQueryFilter(Filter, SourceTable, queryReq.IndexName, out keyConditions, out filterConditions); queryReq.KeyConditions = keyConditions; queryReq.QueryFilter = filterConditions; if (queryReq.QueryFilter != null && queryReq.QueryFilter.Count > 1) { queryReq.ConditionalOperator = EnumMapper.Convert(ConditionalOperator); } SourceTable.AddRequestHandler(queryReq, isAsync: false); var queryResult = SourceTable.DDBClient.Query(queryReq); count = Matches.Count + queryResult.Count; return(count); default: throw new InvalidOperationException("Unknown Search Method"); } } } }
internal async Task <List <Document> > GetNextSetHelperAsync(CancellationToken cancellationToken) { List <Document> ret = new List <Document>(); if (!IsDone) { switch (SearchMethod) { case SearchType.Scan: ScanRequest scanReq = new ScanRequest { ExclusiveStartKey = NextKey, Limit = Limit, TableName = TableName, AttributesToGet = AttributesToGet, ScanFilter = Filter.ToConditions(SourceTable), Select = EnumMapper.Convert(Select), ConsistentRead = IsConsistentRead }; if (!string.IsNullOrEmpty(this.IndexName)) { scanReq.IndexName = this.IndexName; } if (this.FilterExpression != null && this.FilterExpression.IsSet) { this.FilterExpression.ApplyExpression(scanReq, SourceTable); } if (scanReq.ScanFilter != null && scanReq.ScanFilter.Count > 1) { scanReq.ConditionalOperator = EnumMapper.Convert(ConditionalOperator); } Common.ConvertAttributesToGetToProjectionExpression(scanReq); if (this.TotalSegments != 0) { scanReq.TotalSegments = this.TotalSegments; scanReq.Segment = this.Segment; } SourceTable.AddRequestHandler(scanReq, isAsync: true); var scanResult = await SourceTable.DDBClient.ScanAsync(scanReq, cancellationToken).ConfigureAwait(false); foreach (var item in scanResult.Items) { Document doc = SourceTable.FromAttributeMap(item); ret.Add(doc); if (CollectResults) { Matches.Add(doc); } } NextKey = scanResult.LastEvaluatedKey; if (NextKey == null || NextKey.Count == 0) { IsDone = true; } return(ret); case SearchType.Query: QueryRequest queryReq = new QueryRequest { TableName = TableName, ConsistentRead = IsConsistentRead, Select = EnumMapper.Convert(Select), ExclusiveStartKey = NextKey, Limit = Limit, ScanIndexForward = !IsBackwardSearch, AttributesToGet = AttributesToGet, IndexName = IndexName, }; Expression.ApplyExpression(queryReq, SourceTable, KeyExpression, FilterExpression); Dictionary <string, Condition> keyConditions, filterConditions; SplitQueryFilter(Filter, SourceTable, queryReq.IndexName, out keyConditions, out filterConditions); queryReq.KeyConditions = keyConditions; queryReq.QueryFilter = filterConditions; Common.ConvertAttributesToGetToProjectionExpression(queryReq); if (queryReq.QueryFilter != null && queryReq.QueryFilter.Count > 1) { queryReq.ConditionalOperator = EnumMapper.Convert(ConditionalOperator); } SourceTable.AddRequestHandler(queryReq, isAsync: true); var queryResult = await SourceTable.DDBClient.QueryAsync(queryReq, cancellationToken).ConfigureAwait(false); foreach (var item in queryResult.Items) { Document doc = SourceTable.FromAttributeMap(item); ret.Add(doc); if (CollectResults) { Matches.Add(doc); } } NextKey = queryResult.LastEvaluatedKey; if (NextKey == null || NextKey.Count == 0) { IsDone = true; } return(ret); default: throw new InvalidOperationException("Unknown Search Method"); } } return(ret); }
internal List <Document> GetNextSetHelper(bool isAsync) { List <Document> ret = new List <Document>(); if (!IsDone) { switch (SearchMethod) { case SearchType.Scan: ScanRequest scanReq = new ScanRequest { ExclusiveStartKey = NextKey, Limit = Limit, TableName = TableName, AttributesToGet = AttributesToGet, ScanFilter = Filter.ToConditions(SourceTable.Conversion), Select = EnumMapper.Convert(Select), }; if (!string.IsNullOrEmpty(this.IndexName)) { scanReq.IndexName = this.IndexName; } if (this.FilterExpression != null && this.FilterExpression.IsSet) { this.FilterExpression.ApplyExpression(scanReq, SourceTable.Conversion); } if (scanReq.ScanFilter != null && scanReq.ScanFilter.Count > 1) { scanReq.ConditionalOperator = EnumMapper.Convert(ConditionalOperator); } Common.ConvertAttributesToGetToProjectionExpression(scanReq); if (this.TotalSegments != 0) { scanReq.TotalSegments = this.TotalSegments; scanReq.Segment = this.Segment; } ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)scanReq).AddBeforeRequestHandler(isAsync ? new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerAsync) : new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerSync) ); var scanResult = SourceTable.DDBClient.Scan(scanReq); foreach (var item in scanResult.Items) { Document doc = Document.FromAttributeMap(item); ret.Add(doc); if (CollectResults) { Matches.Add(doc); } } NextKey = scanResult.LastEvaluatedKey; if (NextKey == null || NextKey.Count == 0) { IsDone = true; } return(ret); case SearchType.Query: QueryRequest queryReq = new QueryRequest { TableName = TableName, ConsistentRead = IsConsistentRead, Select = EnumMapper.Convert(Select), ExclusiveStartKey = NextKey, Limit = Limit, ScanIndexForward = !IsBackwardSearch, AttributesToGet = AttributesToGet, IndexName = IndexName, }; if (this.FilterExpression != null && this.FilterExpression.IsSet) { this.FilterExpression.ApplyExpression(queryReq, SourceTable.Conversion); } Dictionary <string, Condition> keyConditions, filterConditions; SplitQueryFilter(Filter, SourceTable, queryReq.IndexName, out keyConditions, out filterConditions); queryReq.KeyConditions = keyConditions; queryReq.QueryFilter = filterConditions; Common.ConvertAttributesToGetToProjectionExpression(queryReq); if (queryReq.QueryFilter != null && queryReq.QueryFilter.Count > 1) { queryReq.ConditionalOperator = EnumMapper.Convert(ConditionalOperator); } ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)queryReq).AddBeforeRequestHandler(isAsync ? new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerAsync) : new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerSync) ); var queryResult = SourceTable.DDBClient.Query(queryReq); foreach (var item in queryResult.Items) { Document doc = Document.FromAttributeMap(item); ret.Add(doc); if (CollectResults) { Matches.Add(doc); } } NextKey = queryResult.LastEvaluatedKey; if (NextKey == null || NextKey.Count == 0) { IsDone = true; } return(ret); default: throw new InvalidOperationException("Unknown Search Method"); } } return(ret); }