public object Combine(object value) { if (!(value is IJSONDocument)) { throw new Exception("At MaxDataCombiner: Document needs to be in IJSONDocument format"); } IJSONDocument document = (IJSONDocument)value; IJSONDocument updateDoc = new JSONDocument(); foreach (var attribute in _attributes) { object value1 = document[_userDefinedName]; object value2 = _document[_userDefinedName]; int comparer; if (value1 is IComparable) { comparer = JSONComparer.Compare((IComparable)value1, value2); } else { comparer = JsonWrapper.Wrap(value1).CompareTo(JsonWrapper.Wrap(value2)); } if (comparer > 0) { updateDoc.Add(_userDefinedName, value1); } } JsonDocumentUtil.Update(_document, updateDoc); //_document.Update(updateDoc); return(_document); }
public UpdateResult <JSONDocument> UpdateDocument(JSONDocument update) { UpdateResult <JSONDocument> result = new UpdateResult <JSONDocument>(); CacheItem item; if (_documentCache.TryGetValue(new DocumentKey(update.Key), out item)) { result.OldDocument = item.Document.Clone() as JSONDocument; JsonDocumentUtil.Update(item.Document, update); //_documentCache[update.Key].Document.Update(update); result.RowId = item.Metadata.RowId; result.NewDocument = item.Document.Clone() as JSONDocument; } return(result); }
public object Combine(object value) { if (!(value is IJSONDocument)) { throw new Exception("At AverageDataCombiner: Document needs to be in IJSONDocument format"); } bool isUpdateApplicable = false; IJSONDocument document = (IJSONDocument)value; IJSONDocument updateDoc = new JSONDocument(); foreach (var attribute in _attributes) { IJSONDocument sumAndCount = new JSONDocument(); if (document.GetAttributeDataType(_userDefinedName) == ExtendedJSONDataTypes.Array) { if (_document.Contains("$" + _userDefinedName) && _document.GetAttributeDataType("$" + _userDefinedName) == ExtendedJSONDataTypes.Array) { double[] sumAndCountDoc = document.GetArray <double>(_userDefinedName); double sum = sumAndCountDoc[0]; double count = sumAndCountDoc[1]; double[] existingSumAndCount = _document.GetArray <double>("$" + _userDefinedName); double sum1 = existingSumAndCount[0]; double count1 = existingSumAndCount[1]; double combinedSum = sum + sum1; double combinedCount = count + count1; sumAndCountDoc[0] = combinedSum; sumAndCountDoc[1] = combinedCount; updateDoc.Add("$" + _userDefinedName, sumAndCountDoc); updateDoc.Add(_userDefinedName, combinedSum / combinedCount); isUpdateApplicable = true; } } } if (isUpdateApplicable) { JsonDocumentUtil.Update(_document, updateDoc); } return(_document); }
public object Combine(object value) { if (!(value is IJSONDocument)) { throw new Exception("At SumDataCombiner: Document needs to be in IJSONDocument format"); } IJSONDocument document = (IJSONDocument)value; IJSONDocument updateDoc = new JSONDocument(); foreach (var attribute in _attributes) { double value1 = document.GetAsDouble(_userDefinedName); double value2 = _document.GetAsDouble(_userDefinedName); updateDoc.Add(_userDefinedName, value1 + value2); } JsonDocumentUtil.Update(_document, updateDoc); //_document.Update(updateDoc); return(_document); }
public bool MoveNext() { if (!_closed) { if (_combiners.Count < 1) { throw new Exception("DataCombiner is not defined for Group By Operation"); } if (_current == null && _lastUnSentElement == null) // True first time only { if (_dataSelector.MoveNext()) { _lastUnSentElement = (ISetElement)_dataSelector.Current; } else { _closed = true; return(false); } } if (_lastUnSentElement == null) { _closed = true; return(false); } // bool found = false; _current = _lastUnSentElement; _lastUnSentElement = null; foreach (IDataCombiner dataCombiner in _combiners) { dataCombiner.Reset(); _current.Value = dataCombiner.Initialize(_current.Value) as IJSONDocument; } while (_dataSelector.MoveNext()) { _lastUnSentElement = (ISetElement)_dataSelector.Current; if (_comparer.Compare(_current.Value, _lastUnSentElement.Value) == 0) { //JSONDocumentComparer jdocComparer = (JSONDocumentComparer)_comparer; //foreach (string field in jdocComparer.FieldNamesGroupBy) // Can be optimized for better performance. Will do it later if required // _current.Value.Remove(field); foreach (IDataCombiner dataCombiner in _combiners) { JsonDocumentUtil.Update(_current.Value, (IJSONDocument)dataCombiner.Combine(_lastUnSentElement.Value)); // _current.Value.Update((IJSONDocument)dataCombiner.Combine(_lastUnSentElement.Value)); } _lastUnSentElement = null; } else { return(true); } } return(true); } return(false); }