Esempio n. 1
0
        private TypedCursorable(IHostEnvironment env, IDataView data, bool ignoreMissingColumns, InternalSchemaDefinition schemaDefn)
        {
            Contracts.AssertValue(env, "env");
            _host = env.Register("TypedCursorable");
            _host.AssertValue(data);
            _host.AssertValue(schemaDefn);

            _data = data;
            // Get column indices. Throw if there are missing columns (optionally, ignore them).
            var acceptedCols = new List <InternalSchemaDefinition.Column>();
            var indices      = new List <int>();

            foreach (var col in schemaDefn.Columns)
            {
                int colIndex;
                if (!_data.Schema.TryGetColumnIndex(col.ColumnName, out colIndex))
                {
                    if (ignoreMissingColumns)
                    {
                        continue;
                    }
                    throw _host.Except("Column '{0}' not found in the data view", col.ColumnName);
                }
                var realColType = _data.Schema[colIndex].Type;
                if (!IsCompatibleType(realColType, col.MemberInfo))
                {
                    throw _host.Except(
                              "Can't bind the IDataView column '{0}' of type '{1}' to field or property '{2}' of type '{3}'.",
                              col.ColumnName, realColType, col.MemberInfo.Name, col.FieldOrPropertyType.FullName);
                }

                acceptedCols.Add(col);
                indices.Add(colIndex);
            }
            _columns       = acceptedCols.ToArray();
            _columnIndices = indices.ToArray();
            _host.Assert(_columns.Length == _columnIndices.Length);

            int n = _columns.Length;

            _pokes = new Delegate[n];
            _peeks = new Delegate[n];
            var schema = _data.Schema;

            for (int i = 0; i < n; i++)
            {
                if (_columns[i].ColumnType is VectorType)
                {
                    _peeks[i] = ApiUtils.GeneratePeek <TypedCursorable <TRow>, TRow>(_columns[i]);
                }
                _pokes[i] = ApiUtils.GeneratePoke <TypedCursorable <TRow>, TRow>(_columns[i]);
            }
        }
Esempio n. 2
0
            private static Delegate[] MakePeeks(InternalSchemaDefinition schemaDef)
            {
                var peeks = new Delegate[schemaDef.Columns.Length];

                for (var i = 0; i < peeks.Length; i++)
                {
                    var currentColumn = schemaDef.Columns[i];
                    peeks[i] = currentColumn.IsComputed
                        ? currentColumn.Generator
                        : ApiUtils.GeneratePeek <InputRow <TRow>, TRow>(currentColumn);
                }
                return(peeks);
            }