public virtual IJSONDocument Transform(IJSONDocument document) { IJSONDocument newDocument; if (_criteria.GetAllFields) { newDocument = document.Clone() as IJSONDocument; } else { newDocument = JSONType.CreateNew(); } //if (!_criteria.IsGrouped) // newDocument.Key = document.Key; for (int i = 0; i < _criteria.ProjectionCount; i++) { IEvaluable field = _criteria[i]; IJsonValue finalValue; if (field.Evaluate(out finalValue, document)) { //newDocument[field.ToString()] = finalValue.Value; var binaryExpression = field as BinaryExpression; if (binaryExpression != null) { if (binaryExpression.Alias != null) { newDocument[binaryExpression.Alias] = finalValue.Value; continue; } } newDocument[field.CaseSensitiveInString] = finalValue.Value; } else { return(null); } } if (_criteria.ContainsOrder && !_criteria.IsGrouped) { _criteria.OrderByField.FillWithAttributes(document, newDocument); } else if (_criteria.IsGrouped) { _criteria.GroupByField.FillWithAttributes(document, newDocument); } if (newDocument.Count == 0) { return(null); } return(newDocument); }
public override IEnumerable <KeyValuePair <AttributeValue, long> > Enumerate(QueryCriteria value) { IQueryStore tempCollection = value.SubstituteStore; IJSONDocument doc = JSONType.CreateNew(); doc.Add("$count(*)", _count); doc.Key = Guid.NewGuid().ToString(); tempCollection.InsertDocument(doc, null); var rowid = tempCollection.GetRowId(new DocumentKey(doc.Key)); value.Store = tempCollection; value.GroupByField = new AllField(Field.FieldType.Grouped); yield return(new KeyValuePair <AttributeValue, long>(NullValue.Null, rowid)); }
public override IEnumerable <KeyValuePair <AttributeValue, long> > Enumerate(QueryCriteria value) { _filterDocument = JSONType.CreateNew(); if (_childPredicates.Count > 0) { foreach (var childPredicate in _childPredicates) { var predicate = childPredicate as TerminalPredicate; if (predicate != null) { foreach (var kvp in predicate.Enumerate(value)) { _filterDocument.Clear(); PopulateDocument(kvp.Key, predicate.Source.Attributes); if (_condition.IsTrue(_filterDocument)) { yield return(kvp); } } } } } }
public override IEnumerable <KeyValuePair <AttributeValue, long> > Enumerate(QueryCriteria value) { IQueryStore tempCollection = value.SubstituteStore; var key = new DocumentKey(); var finalResultSet = new SortedDictionary <AttributeValue, long>(); if (_childPredicates != null) { foreach (var childPredicate in _childPredicates) { var predicate = childPredicate as TerminalPredicate; if (predicate != null) { foreach (var kvp in predicate.Enumerate(value)) { var newDocument = value.Store.GetDocument(kvp.Value, null); if (newDocument == null) { continue; } AttributeValue newKey; if (value.GroupByField.GetAttributeValue(newDocument, out newKey)) { key.Value = newKey.ValueInString; if (finalResultSet.ContainsKey(newKey)) { if (value.ContainsAggregations) { var groupDocument = tempCollection.GetDocument(finalResultSet[newKey], null); foreach (var aggregation in value.Aggregations) { IJsonValue calculatedValue; if (aggregation.Evaluation.Evaluate(out calculatedValue, newDocument)) { aggregation.Aggregation.Value = groupDocument[aggregation.FieldName]; aggregation.Aggregation.ApplyValue(calculatedValue.Value); groupDocument[aggregation.FieldName] = aggregation.Aggregation.Value; } } tempCollection.UpdateDocument(finalResultSet[newKey], groupDocument, new OperationContext()); } } else { var aggregateDocument = JSONType.CreateNew(); value.GroupByField.FillWithAttributes(newDocument, aggregateDocument); if (value.ContainsAggregations) { foreach (var aggregation in value.Aggregations) { IJsonValue calculatedValue; if (aggregation.Evaluation.Evaluate(out calculatedValue, newDocument)) { aggregation.Reset(); aggregation.Aggregation.ApplyValue(calculatedValue.Value); aggregateDocument[aggregation.FieldName] = aggregation.Aggregation.Value; } } } aggregateDocument.Key = key.Value as string; tempCollection.InsertDocument(aggregateDocument, new OperationContext()); long newRowId = tempCollection.GetRowId(key); finalResultSet.Add(newKey, newRowId); } } } } } } if (finalResultSet.Count == 0) { var emptyDoc = JSONType.CreateNew(); if (value.ContainsAggregations) { foreach (var aggregation in value.Aggregations) { emptyDoc[aggregation.FieldName] = 0; } } key.Value = value.GroupByField.FieldId.ToString(); emptyDoc.Key = (string)key.Value; tempCollection.InsertDocument(emptyDoc, new OperationContext()); finalResultSet.Add(new NullValue(), tempCollection.GetRowId(key)); } value.Store = tempCollection; return(finalResultSet); }