Пример #1
0
            /// <summary>
            /// Returns a value getter delegate to fetch the value of column with the given columnIndex, from the row.
            /// This throws if the column is not active in this row, or if the type
            /// <typeparamref name="TValue"/> differs from this column's type.
            /// </summary>
            /// <typeparam name="TValue"> is the column's content type.</typeparam>
            /// <param name="column"> is the output column whose getter should be returned.</param>
            public override ValueGetter<TValue> GetGetter<TValue>(DataViewSchema.Column column)
            {
                Ch.Check(IsColumnActive(column));

                var getter = _getters[column.Index] as ValueGetter<TValue>;
                if (getter == null)
                {
                    throw Ch.Except("Invalid TValue: '{0}'", typeof(TValue));
                }

                return getter;
            }
            public override ValueGetter<TValue> GetGetter<TValue>(int col)
            {
                Ch.Check(IsColumnActive(col));

                var getter = _getters[col] as ValueGetter<TValue>;
                if (getter == null)
                {
                    throw Ch.Except("Invalid TValue: '{0}'", typeof(TValue));
                }

                return getter;
            }
Пример #3
0
                protected override bool MoveNextCore()
                {
                    Ch.Assert(State != CursorState.Done);
                    var result = _enumerator.MoveNext();

                    _currentRow = result ? _enumerator.Current : null;
                    if (result && _currentRow == null)
                    {
                        throw Ch.Except("Encountered null when iterating over data, this is not supported.");
                    }
                    return(result);
                }
Пример #4
0
            public ValueGetter <TValue> GetGetter <TValue>(int col)
            {
                Ch.CheckParam(0 <= col && col < _colToActivesIndex.Length, nameof(col));
                Ch.CheckParam(_colToActivesIndex[col] >= 0, nameof(col), "requested column not active");
                ValueGetter <TValue> getter = _getters[_colToActivesIndex[col]] as ValueGetter <TValue>;

                if (getter == null)
                {
                    throw Ch.Except("Invalid TValue: '{0}'", typeof(TValue));
                }
                return(getter);
            }
Пример #5
0
            /// <summary>
            /// Returns a value getter delegate to fetch the value of column with the given columnIndex, from the row.
            /// This throws if the column is not active in this row, or if the type
            /// <typeparamref name="TValue"/> differs from this column's type.
            /// </summary>
            /// <typeparam name="TValue"> is the column's content type.</typeparam>
            /// <param name="column"> is the output column whose getter should be returned.</param>
            public override ValueGetter <TValue> GetGetter <TValue>(DataViewSchema.Column column)
            {
                Ch.CheckParam(IsColumnActive(column), nameof(column), "requested column not active");

                var getter = _getters[_colToActivesIndex[column.Index]] as ValueGetter <TValue>;

                if (getter == null)
                {
                    throw Ch.Except("Invalid TValue: '{0}'", typeof(TValue));
                }

                return(getter);
            }
Пример #6
0
            /// <summary>
            /// Returns a value getter delegate to fetch the value of column with the given columnIndex, from the row.
            /// This throws if the column is not active in this row, or if the type
            /// <typeparamref name="TValue"/> differs from this column's type.
            /// </summary>
            /// <typeparam name="TValue"> is the column's content type.</typeparam>
            /// <param name="column"> is the output column whose getter should be returned.</param>
            public override ValueGetter <TValue> GetGetter <TValue>(DataViewSchema.Column column)
            {
                Ch.CheckParam(column.Index < _getters.Length, nameof(column), "requested column not valid.");
                Ch.Check(IsColumnActive(column));

                var fn = _getters[column.Index] as ValueGetter <TValue>;

                if (fn == null)
                {
                    throw Ch.Except("Invalid TValue in GetGetter: '{0}'", typeof(TValue));
                }
                return(fn);
            }
            /// <summary>
            /// Returns a value getter delegate to fetch the value of column with the given columnIndex, from the row.
            /// This throws if the column is not active in this row, or if the type
            /// <typeparamref name="TValue"/> differs from this column's type.
            /// </summary>
            /// <typeparam name="TValue"> is the column's content type.</typeparam>
            /// <param name="column"> is the output column whose getter should be returned.</param>
            public override ValueGetter<TValue> GetGetter<TValue>(DataViewSchema.Column column)
            {
                Ch.Check(0 <= column.Index && column.Index < Schema.Count);
                Ch.Check(IsColumnActive(column));

                if (column.Index != Parent._index)
                    return Input.GetGetter<TValue>(column);
                var fn = GetGetter() as ValueGetter<TValue>;
                if (fn == null)
                    throw Ch.Except("Invalid TValue in GetGetter: '{0}'", typeof(TValue));

                return fn;
            }
Пример #8
0
            public ValueGetter <TValue> GetGetter <TValue>(int col)
            {
                Action isGood =
                    () =>
                {
                    if (!IsGood)
                    {
                        throw Ch.Except("Getter is called when the cursor is {0}, which is not allowed.", Input.State);
                    }
                };

                return(_row.GetGetterCore <TValue>(col, isGood));
            }
Пример #9
0
            public ValueGetter <TValue> GetGetter <TValue>(int col)
            {
                Ch.CheckParam(IsColumnActive(col), nameof(col), "requested column not active");

                var getter = _getters[_colToActivesIndex[col]] as ValueGetter <TValue>;

                if (getter == null)
                {
                    throw Ch.Except("Invalid TValue: '{0}'", typeof(TValue));
                }

                return(getter);
            }
            public sealed override ValueGetter <TValue> GetGetter <TValue>(DataViewSchema.Column column)
            {
                Ch.CheckParam(column.Index <= Getters.Length && IsColumnActive(column), nameof(column), "requested column not active");

                var originGetter = Getters[column.Index];
                var getter       = originGetter as ValueGetter <TValue>;

                if (getter == null)
                {
                    throw Ch.Except($"Invalid TValue in GetGetter: '{typeof(TValue)}', " +
                                    $"expected type: '{originGetter.GetType().GetGenericArguments().First()}'.");
                }
                return(getter);
            }
Пример #11
0
            public override ValueGetter <TValue> GetGetter <TValue>(int col)
            {
                Ch.CheckParam(0 <= col && col <= _colToActivesIndex.Length, nameof(col));
                Ch.CheckParam(IsColumnActive(col), nameof(col), "requested column not active");

                Ch.AssertValue(_getters[_colToActivesIndex[col]]);
                var getter = _getters[_colToActivesIndex[col]] as ValueGetter <TValue>;

                if (getter == null)
                {
                    throw Ch.Except("Invalid TValue: '{0}'", typeof(TValue));
                }
                return(getter);
            }
Пример #12
0
            protected override bool MoveNextCore()
            {
                Ch.Assert(_liveCount > 0);
                Ch.Assert(_deadCount < _blockSize || _doneConsuming);
                Ch.Assert(0 <= _circularIndex & _circularIndex < _pipeIndices.Length);

                if (++_circularIndex == _pipeIndices.Length)
                {
                    _circularIndex = 0;
                }
                --_liveCount;
                if (++_deadCount >= _blockSize && !_doneConsuming)
                {
                    // We should let the producer know it can give us more stuff.
                    // It is possible for int values to be sent beyond the
                    // end of the sentinel, but we suppose this is irrelevant.
                    PostAssert(_toProduce, _deadCount);
                    _deadCount = 0;
                }

                while (_liveCount < _poolRows && !_doneConsuming)
                {
                    // We are under capacity. Try to get some more.
                    int got = _toConsume.Receive();
                    if (got == 0)
                    {
                        // We've reached the end sentinel. There's no reason
                        // to attempt further communication with the producer.
                        // Check whether something horrible happened.
                        if (_producerTaskException != null)
                        {
                            throw Ch.Except(_producerTaskException, "Shuffle input cursor reader failed with an exception");
                        }
                        _doneConsuming = true;
                        break;
                    }
                    _liveCount += got;
                }
                if (_liveCount == 0)
                {
                    return(false);
                }
                int circularSwapIndex = (_rand.Next(Math.Min(_liveCount, _poolRows)) + _circularIndex) % _pipeIndices.Length;

                _pipeIndex = _pipeIndices[circularSwapIndex];
                _pipeIndices[circularSwapIndex] = _pipeIndices[_circularIndex];
                _pipeIndices[_circularIndex]    = _pipeIndex;
                return(true);
            }
Пример #13
0
            public override ValueGetter<TValue> GetGetter<TValue>(int col)
            {
                Ch.Check(IsColumnActive(col));

                bool isSrc;
                int index = _bindings.MapColumnIndex(out isSrc, col);
                if (isSrc)
                    return Input.GetGetter<TValue>(index);

                Ch.Assert(_getters[index] != null);
                var fn = _getters[index] as ValueGetter<TValue>;
                if (fn == null)
                    throw Ch.Except("Invalid TValue in GetGetter: '{0}'", typeof(TValue));
                return fn;
            }
            /// <summary>
            /// Returns a value getter delegate to fetch the value of column with the given columnIndex, from the row.
            /// This throws if the column is not active in this row, or if the type
            /// <typeparamref name="TValue"/> differs from this column's type.
            /// </summary>
            /// <typeparam name="TValue"> is the column's content type.</typeparam>
            /// <param name="column"> is the output column whose getter should be returned.</param>
            public override ValueGetter <TValue> GetGetter <TValue>(DataViewSchema.Column column)
            {
                Ch.CheckParam(column.Index < _getters.Length, nameof(column), "requested column not valid.");
                Ch.Check(IsColumnActive(column));

                var originFn = _getters[column.Index];
                var fn       = originFn as ValueGetter <TValue>;

                if (fn == null)
                {
                    throw Ch.Except($"Invalid TValue in GetGetter: '{typeof(TValue)}', " +
                                    $"expected type: '{originFn.GetType().GetGenericArguments().First()}'.");
                }
                return(fn);
            }
Пример #15
0
            /// <summary>
            /// Returns a value getter delegate to fetch the value of column with the given columnIndex, from the row.
            /// This throws if the column is not active in this row, or if the type
            /// <typeparamref name="TValue"/> differs from this column's type.
            /// </summary>
            /// <typeparam name="TValue"> is the column's content type.</typeparam>
            /// <param name="column"> is the output column whose getter should be returned.</param>
            public override ValueGetter <TValue> GetGetter <TValue>(DataViewSchema.Column column)
            {
                Ch.Check(IsColumnActive(column));

                var originGetter = _getters[column.Index];
                var getter       = originGetter as ValueGetter <TValue>;

                if (getter == null)
                {
                    throw Ch.Except($"Invalid TValue: '{typeof(TValue)}', " +
                                    $"expected type: '{originGetter.GetType().GetGenericArguments().First()}'.");
                }

                return(getter);
            }
            private ValueGetter<TValue> GetterDelegateCore<TValue>(int col, DataViewType type)
            {
                Ch.Check(col >= 0 && col < _colValues.Length);
                Ch.AssertValue(type);

                var conv = Conversions.Instance.GetStandardConversion(TextDataViewType.Instance, type) as ValueMapper<ReadOnlyMemory<char>, TValue>;
                if (conv == null)
                {
                    throw Ch.Except("Invalid TValue: '{0}' of the conversion.", typeof(TValue));
                }

                return (ref TValue value) =>
                {
                    conv(in _colValues[col], ref value);
                };
            }
                public ValueGetter <TValue> GetGetter <TValue>(int col)
                {
                    if (!IsColumnActive(col))
                    {
                        throw Ch.Except("Column {0} is not active in the cursor", col);
                    }
                    var getter = _getters[col];

                    Contracts.AssertValue(getter);
                    var fn = getter as ValueGetter <TValue>;

                    if (fn == null)
                    {
                        throw Ch.Except("Invalid TValue in GetGetter for column #{0}: '{1}'", col, typeof(TValue));
                    }
                    return(fn);
                }
            private ValueGetter <TValue> GetterDelegateCore <TValue>(int col, ColumnType type)
            {
                Ch.Check(col >= 0 && col < _colValues.Length);
                Ch.AssertValue(type);

                var conv = Conversions.Instance.GetStandardConversion(TextType.Instance, type) as ValueMapper <DvText, TValue>;

                if (conv == null)
                {
                    throw Ch.Except("Invalid TValue: '{0}' of the conversion.", typeof(TValue));
                }

                return((ref TValue value) =>
                {
                    conv(ref _colValues[col], ref value);
                });
            }
Пример #19
0
            public override ValueGetter <TValue> GetGetter <TValue>(int col)
            {
                Ch.Check(0 <= col && col < Schema.Count);
                Ch.Check(IsColumnActive(col));

                if (col != Parent._index)
                {
                    return(Input.GetGetter <TValue>(col));
                }
                var fn = GetGetter() as ValueGetter <TValue>;

                if (fn == null)
                {
                    throw Ch.Except("Invalid TValue in GetGetter: '{0}'", typeof(TValue));
                }

                return(fn);
            }
                public override ValueGetter <TValue> GetGetter <TValue>(int col)
                {
                    Ch.Check(0 <= col & col < Schema.Count);
                    Ch.Check(_active[col], "column is not active");
                    var column = _view._columns[col] as Column <TValue>;

                    if (column == null)
                    {
                        throw Ch.Except("Invalid TValue: '{0}'", typeof(TValue));
                    }

                    return
                        ((ref TValue value) =>
                    {
                        Ch.Check(IsGood);
                        column.CopyOut(MappedIndex(), ref value);
                    });
                }
Пример #21
0
            /// <summary>
            /// Gets the appropriate column value getter for a mapped column. If the column
            /// is not mapped, this returns false with the out parameters getting default values.
            /// If the column is mapped but the TValue is of the wrong type, an exception is
            /// thrown.
            /// </summary>
            private bool TryGetColumnValueGetter <TValue>(int col, out ValueGetter <TValue> fn)
            {
                Ch.Assert(IsColumnActive(col));

                int index;

                if (!_parent._srcIndexToInfoIndex.TryGetValue(col, out index))
                {
                    fn = null;
                    return(false);
                }

                fn = _values[index].GetGetter() as ValueGetter <TValue>;
                if (fn == null)
                {
                    throw Ch.Except("Invalid TValue: '{0}'", typeof(TValue));
                }
                return(true);
            }
                /// <summary>
                /// Returns a value getter delegate to fetch the value of column with the given columnIndex, from the row.
                /// This throws if the column is not active in this row, or if the type
                /// <typeparamref name="TValue"/> differs from this column's type.
                /// </summary>
                /// <typeparam name="TValue"> is the column's content type.</typeparam>
                /// <param name="column"> is the output column whose getter should be returned.</param>
                public override ValueGetter <TValue> GetGetter <TValue>(DataViewSchema.Column column)
                {
                    Ch.Check(column.Index < Schema.Count);
                    Ch.Check(column.Index < _active.Length && _active[column.Index], "the requested column is not active");

                    var columnValue = _view._columns[column.Index] as Column <TValue>;

                    if (columnValue == null)
                    {
                        throw Ch.Except("Invalid TValue: '{0}'", typeof(TValue));
                    }

                    return
                        ((ref TValue value) =>
                    {
                        Ch.Check(IsGood, RowCursorUtils.FetchValueStateError);
                        columnValue.CopyOut(MappedIndex(), ref value);
                    });
                }
Пример #23
0
            /// <summary>
            /// Returns a value getter delegate to fetch the value of column with the given columnIndex, from the row.
            /// This throws if the column is not active in this row, or if the type
            /// <typeparamref name="TValue"/> differs from this column's type.
            /// </summary>
            /// <typeparam name="TValue"> is the column's content type.</typeparam>
            /// <param name="column"> is the output column whose getter should be returned.</param>
            public override ValueGetter <TValue> GetGetter <TValue>(DataViewSchema.Column column)
            {
                Ch.Check(0 <= column.Index && column.Index < Schema.Count);
                Ch.Check(IsColumnActive(column));

                if (column.Index != Parent._index)
                {
                    return(Input.GetGetter <TValue>(column));
                }
                var originFn = GetGetter();
                var fn       = originFn as ValueGetter <TValue>;

                if (fn == null)
                {
                    throw Ch.Except($"Invalid TValue in GetGetter: '{typeof(TValue)}', " +
                                    $"expected type: '{originFn.GetType().GetGenericArguments().First()}'.");
                }

                return(fn);
            }
Пример #24
0
            public ValueGetter <TValue> GetGetter <TValue>(int col)
            {
                Ch.Check(IsColumnActive(col));

                int index = _bindings.MapColumnIndex(out bool isSrc, col);

                if (isSrc)
                {
                    return(Input.GetGetter <TValue>(index));
                }

                Ch.Assert(_getters[index] != null);
                var fn = _getters[index] as ValueGetter <TValue>;

                if (fn == null)
                {
                    throw Ch.Except("Invalid TValue in GetGetter: '{0}'", typeof(TValue));
                }
                return(fn);
            }
Пример #25
0
            public override ValueGetter<TValue> GetGetter<TValue>(int col)
            {
                Contracts.CheckParam(IsColumnActive(col), nameof(col), "requested column is not active");

                bool isSrc;
                col = _parent.GetBindings().MapColumnIndex(out isSrc, col);
                if (isSrc)
                {
                    Contracts.AssertValue(_input);
                    return _input.GetGetter<TValue>(col);
                }

                Ch.AssertValue(_getters);
                var getter = _getters[col];
                Ch.Assert(getter != null);
                var fn = getter as ValueGetter<TValue>;
                if (fn == null)
                    throw Ch.Except("Invalid TValue in GetGetter: '{0}'", typeof(TValue));
                return fn;
            }
Пример #26
0
            /// <summary>
            /// Returns a value getter delegate to fetch the value of column with the given columnIndex, from the row.
            /// This throws if the column is not active in this row, or if the type
            /// <typeparamref name="TValue"/> differs from this column's type.
            /// </summary>
            /// <typeparam name="TValue"> is the column's content type.</typeparam>
            /// <param name="column"> is the output column whose getter should be returned.</param>
            public override ValueGetter <TValue> GetGetter <TValue>(DataViewSchema.Column column)
            {
                Ch.Check(IsColumnActive(column));

                bool isSrc;
                int  index = _bindings.MapColumnIndex(out isSrc, column.Index);

                if (isSrc)
                {
                    return(Input.GetGetter <TValue>(Input.Schema[index]));
                }

                Ch.Assert(_getters[index] != null);
                var fn = _getters[index] as ValueGetter <TValue>;

                if (fn == null)
                {
                    throw Ch.Except("Invalid TValue in GetGetter: '{0}'", typeof(TValue));
                }
                return(fn);
            }
Пример #27
0
            /// <summary>
            /// Returns a value getter delegate to fetch the value of column with the given columnIndex, from the row.
            /// This throws if the column is not active in this row, or if the type
            /// <typeparamref name="TValue"/> differs from this column's type.
            /// </summary>
            /// <typeparam name="TValue"> is the column's content type.</typeparam>
            /// <param name="column"> is the output column whose getter should be returned.</param>
            public override ValueGetter <TValue> GetGetter <TValue>(DataViewSchema.Column column)
            {
                Ch.Check(IsColumnActive(column));

                bool isSrc;
                int  index = _bindings.MapColumnIndex(out isSrc, column.Index);

                if (isSrc)
                {
                    return(Input.GetGetter <TValue>(column));
                }

                Ch.AssertValue(_getters);
                var getter = _getters[index];

                Ch.AssertValue(getter);
                if (getter is ValueGetter <TValue> fn)
                {
                    return(fn);
                }
                throw Ch.Except("Invalid TValue in GetGetter: '{0}'", typeof(TValue));
            }
Пример #28
0
            /// <summary>
            /// Gets the appropriate column value getter for a mapped column. If the column
            /// is not mapped, this returns false with the out parameters getting default values.
            /// If the column is mapped but the TValue is of the wrong type, an exception is
            /// thrown.
            /// </summary>
            private bool TryGetColumnValueGetter <TValue>(int col, out ValueGetter <TValue> fn)
            {
                Ch.Assert(IsColumnActive(Schema[col]));

                int index;

                if (!_parent._srcIndexToInfoIndex.TryGetValue(col, out index))
                {
                    fn = null;
                    return(false);
                }

                var originFn = _values[index].GetGetter();

                fn = originFn as ValueGetter <TValue>;
                if (fn == null)
                {
                    throw Ch.Except($"Invalid TValue: '{typeof(TValue)}', " +
                                    $"expected type: '{originFn.GetType().GetGenericArguments().First()}'.");
                }
                return(true);
            }
Пример #29
0
            public ValueGetter <TValue> GetGetter <TValue>(int col)
            {
                Ch.CheckParam(0 <= col && col < _bindings.ColumnCount, nameof(col));
                Ch.CheckParam(IsColumnActive(col), nameof(col));
                bool isSrc;
                int  index = _bindings.MapColumnIndex(out isSrc, col);

                if (isSrc)
                {
                    return(Input.GetGetter <TValue>(index));
                }
                Ch.Assert(index == 0);
                Delegate idGetter = Input.GetIdGetter();

                Ch.AssertValue(idGetter);
                var fn = idGetter as ValueGetter <TValue>;

                if (fn == null)
                {
                    throw Ch.Except("Invalid TValue in GetGetter: '{0}'", typeof(TValue));
                }
                return(fn);
            }
Пример #30
0
            /// <summary>
            /// Returns a value getter delegate to fetch the value of column with the given columnIndex, from the row.
            /// This throws if the column is not active in this row, or if the type
            /// <typeparamref name="TValue"/> differs from this column's type.
            /// </summary>
            /// <typeparam name="TValue"> is the column's content type.</typeparam>
            /// <param name="column"> is the output column whose getter should be returned.</param>
            public override ValueGetter <TValue> GetGetter <TValue>(DataViewSchema.Column column)
            {
                Ch.CheckParam(column.Index < _bindings.ColumnCount, nameof(column));
                Ch.CheckParam(IsColumnActive(column), nameof(column.Index));
                bool isSrc;
                int  index = _bindings.MapColumnIndex(out isSrc, column.Index);

                if (isSrc)
                {
                    return(Input.GetGetter <TValue>(Input.Schema[index]));
                }
                Ch.Assert(index == 0);
                Delegate idGetter = Input.GetIdGetter();

                Ch.AssertValue(idGetter);
                var fn = idGetter as ValueGetter <TValue>;

                if (fn == null)
                {
                    throw Ch.Except("Invalid TValue in GetGetter: '{0}'", typeof(TValue));
                }
                return(fn);
            }