示例#1
0
                public bool MoveNext()
                {
                    if (_enumerator.MoveNext() == false)
                    {
                        return(false);
                    }

                    var output = _enumerator.Current;

                    _parent._indexContext.CachedProperties.NewDocument();

                    using (_createBlittableResult.Start())
                        using (var writer = new BlittableJsonWriter(_parent._indexContext))
                        {
                            IPropertyAccessor accessor;

                            if (_parent._isMultiMap == false)
                            {
                                accessor = _parent._propertyAccessor ??
                                           (_parent._propertyAccessor = PropertyAccessor.CreateMapReduceOutputAccessor(output.GetType(), output, _groupByFields));
                            }
                            else
                            {
                                accessor = TypeConverter.GetPropertyAccessorForMapReduceOutput(output, _groupByFields);
                            }

                            _reduceKeyProcessor.Reset();

                            writer.WriteStartObject();
                            foreach (var property in accessor.GetPropertiesInOrder(output))
                            {
                                var value          = property.Value;
                                var blittableValue = TypeConverter.ToBlittableSupportedType(value, context: _parent._indexContext);

                                writer.WritePropertyName(property.Key);
                                WriteValue(writer, blittableValue);

                                if (property.IsGroupByField)
                                {
                                    var valueForProcessor = property.GroupByField.GetValue(value, blittableValue);
                                    _reduceKeyProcessor.Process(_parent._indexContext.Allocator, valueForProcessor);
                                }
                            }

                            writer.WriteEndObject();

                            if (_reduceKeyProcessor.ProcessedFields != _groupByFields.Count)
                            {
                                ThrowMissingGroupByFieldsInMapOutput(output, _groupByFields, _parent._compiledIndex);
                            }

                            var reduceHashKey = _reduceKeyProcessor.Hash;

                            writer.FinalizeDocument();

                            Current.Data          = writer.CreateReader();
                            Current.ReduceKeyHash = reduceHashKey;
                        }

                    return(true);
示例#2
0
                public bool MoveNext()
                {
                    if (_enumerator.MoveNext() == false)
                    {
                        return(false);
                    }

                    var output = _enumerator.Current;

                    using (_createBlittableResult.Start())
                    {
                        PropertyAccessor accessor;

                        if (_parent._isMultiMap == false)
                        {
                            accessor = _parent._propertyAccessor ??
                                       (_parent._propertyAccessor = PropertyAccessor.CreateMapReduceOutputAccessor(output.GetType(), output, _groupByFields));
                        }
                        else
                        {
                            accessor = TypeConverter.GetPropertyAccessorForMapReduceOutput(output, _groupByFields);
                        }

                        var mapResult = new DynamicJsonValue();

                        _reduceKeyProcessor.Reset();

                        var propertiesInOrder = accessor.PropertiesInOrder;
                        int properties        = propertiesInOrder.Count;

                        for (int i = 0; i < properties; i++)
                        {
                            var field = propertiesInOrder[i];

                            var value          = field.Value.GetValue(output);
                            var blittableValue = TypeConverter.ToBlittableSupportedType(value);
                            mapResult[field.Key] = blittableValue;

                            if (field.Value.IsGroupByField)
                            {
                                var valueForProcessor = field.Value.GroupByField.GetValue(value, blittableValue);
                                _reduceKeyProcessor.Process(_parent._indexContext.Allocator, valueForProcessor);
                            }
                        }

                        if (_reduceKeyProcessor.ProcessedFields != _groupByFields.Count)
                        {
                            ThrowMissingGroupByFieldsInMapOutput(output, _groupByFields, _parent._compiledIndex);
                        }

                        var reduceHashKey = _reduceKeyProcessor.Hash;

                        Current.Data          = _parent._indexContext.ReadObject(mapResult, "map-result");
                        Current.ReduceKeyHash = reduceHashKey;
                    }

                    return(true);
                }
示例#3
0
        public static PropertyAccessor GetPropertyAccessorForMapReduceOutput(object value, HashSet <CompiledIndexField> groupByFields)
        {
            var type = value.GetType();

            if (value is Dictionary <string, object> ) // don't use cache when using dictionaries
            {
                return(PropertyAccessor.Create(type, value));
            }

            return(PropertyAccessorCache.GetOrAdd(type, x => PropertyAccessor.CreateMapReduceOutputAccessor(type, value, groupByFields)));
        }
示例#4
0
                public bool MoveNext()
                {
                    if (_enumerator.MoveNext() == false)
                        return false;

                    var output = _enumerator.Current;

                    using (_createBlittableResult.Start())
                    {
                        IPropertyAccessor accessor;

                        if (_parent._isMultiMap == false)
                            accessor = _parent._propertyAccessor ??
                                       (_parent._propertyAccessor = PropertyAccessor.CreateMapReduceOutputAccessor(output.GetType(), output, _groupByFields));
                        else
                            accessor = TypeConverter.GetPropertyAccessorForMapReduceOutput(output, _groupByFields);

                        var mapResult = new DynamicJsonValue();

                        _reduceKeyProcessor.Reset();

                        foreach (var property in accessor.GetPropertiesInOrder(output))
                        {
                            var value = property.Value;
                            var blittableValue = TypeConverter.ToBlittableSupportedType(value, context: _parent._indexContext);
                            mapResult[property.Key] = blittableValue;

                            if (property.IsGroupByField)
                            {
                                var valueForProcessor = property.GroupByField.GetValue(value, blittableValue);
                                _reduceKeyProcessor.Process(_parent._indexContext.Allocator, valueForProcessor);
                            }
                        }

                        if (_reduceKeyProcessor.ProcessedFields != _groupByFields.Count)
                            ThrowMissingGroupByFieldsInMapOutput(output, _groupByFields, _parent._compiledIndex);

                        var reduceHashKey = _reduceKeyProcessor.Hash;

                        Current.Data = _parent._indexContext.ReadObject(mapResult, "map-result");
                        Current.ReduceKeyHash = reduceHashKey;
                    }

                    return true;
                }
示例#5
0
        public static PropertyAccessor GetPropertyAccessorForMapReduceOutput(object value, HashSet <string> groupByFields)
        {
            var type = value.GetType();

            return(PropertyAccessorCache.GetOrAdd(type, x => PropertyAccessor.CreateMapReduceOutputAccessor(x, groupByFields)));
        }