public ColumnType GetMetadataTypeOrNull(string kind, int col)
            {
                if (string.IsNullOrEmpty(kind))
                {
                    throw MetadataUtils.ExceptGetMetadata();
                }
                CheckColumnInRange(col);
                var column = SchemaDefn.Columns[col];

                return(column.Metadata.ContainsKey(kind) ? column.Metadata[kind].MetadataType : null);
            }
            public void GetMetadata <TValue>(string kind, int col, ref TValue value)
            {
                var metadataType = GetMetadataTypeOrNull(kind, col);

                if (metadataType == null)
                {
                    throw MetadataUtils.ExceptGetMetadata();
                }

                var metadata = SchemaDefn.Columns[col].Metadata[kind];

                metadata.GetGetter <TValue>()(ref value);
            }
            protected override void GetMetadataCore <TValue>(string kind, int iinfo, ref TValue value)
            {
                Contracts.Assert(0 <= iinfo && iinfo < OutputColInfos.Length);
                var meta = OutputColInfos[iinfo].Metadata;
                int mcol;

                if (meta == null || !meta.Schema.TryGetColumnIndex(kind, out mcol))
                {
                    throw MetadataUtils.ExceptGetMetadata();
                }
                // REVIEW: Again, since this is a shim, not going to sweat the potential for inappropriate exception message.
                meta.GetGetter <TValue>(mcol)(ref value);
            }
示例#4
0
            public void GetMetadata <TValue>(string kind, int col, ref TValue value)
            {
                Contracts.CheckNonEmpty(kind, nameof(kind));
                Contracts.CheckParam(col == 0, nameof(col));

                if (kind == MetadataUtils.Kinds.SlotNames)
                {
                    _getSlotNames.Marshal(col, ref value);
                }
                else
                {
                    throw MetadataUtils.ExceptGetMetadata();
                }
            }
        private void GetSlotNames(int iinfo, ref VBuffer <ReadOnlyMemory <char> > dst)
        {
            Host.Assert(0 <= iinfo && iinfo < Infos.Length);

            int size = _types[iinfo].VectorSize;

            if (size == 0)
            {
                throw MetadataUtils.ExceptGetMetadata();
            }

            var values = dst.Values;

            if (Utils.Size(values) < size)
            {
                values = new ReadOnlyMemory <char> [size];
            }

            var type = Infos[iinfo].TypeSrc;

            if (!type.IsVector)
            {
                Host.Assert(_types[iinfo].VectorSize == 2);
                var columnName = Source.Schema.GetColumnName(Infos[iinfo].Source);
                values[0] = columnName.AsMemory();
                values[1] = (columnName + IndicatorSuffix).AsMemory();
            }
            else
            {
                Host.Assert(type.IsKnownSizeVector);
                Host.Assert(size == 2 * type.VectorSize);

                // REVIEW: Do we need to verify that there is metadata or should we just call GetMetadata?
                var typeNames = Source.Schema.GetMetadataTypeOrNull(MetadataUtils.Kinds.SlotNames, Infos[iinfo].Source);
                if (typeNames == null || typeNames.VectorSize != type.VectorSize || !typeNames.ItemType.IsText)
                {
                    throw MetadataUtils.ExceptGetMetadata();
                }

                var names = default(VBuffer <ReadOnlyMemory <char> >);
                Source.Schema.GetMetadata(MetadataUtils.Kinds.SlotNames, Infos[iinfo].Source, ref names);

                // We both assert and check. If this fails, there is a bug somewhere (possibly in this code
                // but more likely in the implementation of Base. On the other hand, we don't want to proceed
                // if we've received garbage.
                Host.Check(names.Length == type.VectorSize, "Unexpected slot name vector size");

                var sb   = new StringBuilder();
                int slot = 0;
                foreach (var kvp in names.Items(all: true))
                {
                    Host.Assert(0 <= slot && slot < size);
                    Host.Assert(slot % 2 == 0);

                    sb.Clear();
                    if (kvp.Value.IsEmpty)
                    {
                        sb.Append('[').Append(slot / 2).Append(']');
                    }
                    else
                    {
                        sb.AppendMemory(kvp.Value);
                    }

                    int len = sb.Length;
                    sb.Append(IndicatorSuffix);
                    var str = sb.ToString();

                    values[slot++] = str.AsMemory().Slice(0, len);
                    values[slot++] = str.AsMemory();
                }
                Host.Assert(slot == size);
            }

            dst = new VBuffer <ReadOnlyMemory <char> >(size, values, dst.Indices);
        }