Exemplo n.º 1
0
            public Cursor(GroupTransform parent, Func <int, bool> predicate)
                : base(parent.Host)
            {
                Ch.AssertValue(predicate);

                _parent = parent;
                var binding = _parent._groupBinding;

                _active     = Utils.BuildArray(binding.OutputSchema.Count, predicate);
                _groupCount = binding.GroupColumnIndexes.Length;

                bool[] srcActiveLeading = new bool[_parent.Source.Schema.Count];
                foreach (var col in binding.GroupColumnIndexes)
                {
                    srcActiveLeading[col] = true;
                }
                var activeCols = _parent.Source.Schema.Where(x => x.Index < srcActiveLeading.Length && srcActiveLeading[x.Index]);

                _leadingCursor = parent.Source.GetRowCursor(activeCols);

                bool[] srcActiveTrailing = new bool[_parent.Source.Schema.Count];
                for (int i = 0; i < _groupCount; i++)
                {
                    if (_active[i])
                    {
                        srcActiveTrailing[binding.GroupColumnIndexes[i]] = true;
                    }
                }
                for (int i = 0; i < binding.KeepColumnIndexes.Length; i++)
                {
                    if (_active[i + _groupCount])
                    {
                        srcActiveTrailing[binding.KeepColumnIndexes[i]] = true;
                    }
                }

                activeCols      = _parent.Source.Schema.Where(x => x.Index < srcActiveTrailing.Length && srcActiveTrailing[x.Index]);
                _trailingCursor = parent.Source.GetRowCursor(activeCols);

                _groupCheckers = new GroupKeyColumnChecker[_groupCount];
                for (int i = 0; i < _groupCount; i++)
                {
                    _groupCheckers[i] = new GroupKeyColumnChecker(_leadingCursor, _parent._groupBinding.GroupColumnIndexes[i]);
                }

                _aggregators = new KeepColumnAggregator[_parent._groupBinding.KeepColumnIndexes.Length];
                for (int i = 0; i < _aggregators.Length; i++)
                {
                    if (_active[i + _groupCount])
                    {
                        _aggregators[i] = KeepColumnAggregator.Create(_trailingCursor, _parent._groupBinding.KeepColumnIndexes[i]);
                    }
                }
            }
Exemplo n.º 2
0
        public static CommonOutputs.TransformOutput Group(IHostEnvironment env, GroupTransform.Arguments input)
        {
            Contracts.CheckValue(env, nameof(env));
            env.CheckValue(input, nameof(input));

            var h    = EntryPointUtils.CheckArgsAndCreateHost(env, "GroupTransform", input);
            var view = new GroupTransform(h, input, input.Data);

            return(new CommonOutputs.TransformOutput()
            {
                Model = new TransformModelImpl(h, view, input.Data),
                OutputData = view
            });
        }
            public Cursor(GroupTransform parent, Func <int, bool> predicate)
                : base(parent.Host)
            {
                Ch.AssertValue(predicate);

                _parent = parent;
                var schema = _parent._groupSchema;

                _active     = Utils.BuildArray(schema.ColumnCount, predicate);
                _groupCount = schema.GroupIds.Length;

                bool[] srcActiveLeading = new bool[_parent.Source.Schema.ColumnCount];
                foreach (var col in schema.GroupIds)
                {
                    srcActiveLeading[col] = true;
                }
                _leadingCursor = parent.Source.GetRowCursor(x => srcActiveLeading[x]);

                bool[] srcActiveTrailing = new bool[_parent.Source.Schema.ColumnCount];
                for (int i = 0; i < _groupCount; i++)
                {
                    if (_active[i])
                    {
                        srcActiveTrailing[schema.GroupIds[i]] = true;
                    }
                }
                for (int i = 0; i < schema.KeepIds.Length; i++)
                {
                    if (_active[i + _groupCount])
                    {
                        srcActiveTrailing[schema.KeepIds[i]] = true;
                    }
                }
                _trailingCursor = parent.Source.GetRowCursor(x => srcActiveTrailing[x]);

                _groupCheckers = new GroupKeyColumnChecker[_groupCount];
                for (int i = 0; i < _groupCount; i++)
                {
                    _groupCheckers[i] = new GroupKeyColumnChecker(_leadingCursor, _parent._groupSchema.GroupIds[i]);
                }

                _aggregators = new KeepColumnAggregator[_parent._groupSchema.KeepIds.Length];
                for (int i = 0; i < _aggregators.Length; i++)
                {
                    if (_active[i + _groupCount])
                    {
                        _aggregators[i] = KeepColumnAggregator.Create(_trailingCursor, _parent._groupSchema.KeepIds[i]);
                    }
                }
            }