private ReadOnlyMemory <char> GetSlotName(int index, VBuffer <ReadOnlyMemory <char> > slotNames) { _env.Assert(0 <= index && index < slotNames.Length); var slotName = slotNames.GetItemOrDefault(index); return(slotName.IsEmpty ? new ReadOnlyMemory <char>($"f{index}".ToCharArray()) : slotName); }
/// <summary> /// Gets the mapping from T into a StringBuilder representation, using various heuristics. /// This StringBuilder representation will be a component of the composed KeyValues for the /// hash outputs. /// </summary> public static ValueMapper <T, StringBuilder> GetSimpleMapper <T>(DataViewSchema schema, int col) { Contracts.AssertValue(schema); Contracts.Assert(0 <= col && col < schema.Count); var type = schema[col].Type.GetItemType(); Contracts.Assert(type.RawType == typeof(T)); var conv = Conversion.Conversions.DefaultInstance; // First: if not key, then get the standard string conversion. if (!(type is KeyDataViewType keyType)) { return(conv.GetStringConversion <T>(type)); } bool identity; // Second choice: if key, utilize the KeyValues metadata for that key, if it has one and is text. if (schema[col].HasKeyValues()) { // REVIEW: Non-textual KeyValues are certainly possible. Should we handle them? // Get the key names. VBuffer <ReadOnlyMemory <char> > keyValues = default; schema[col].GetKeyValues(ref keyValues); ReadOnlyMemory <char> value = default; // REVIEW: We could optimize for identity, but it's probably not worthwhile. var keyMapper = conv.GetStandardConversion <T, uint>(type, NumberDataViewType.UInt32, out identity); return ((in T src, ref StringBuilder dst) => { ClearDst(ref dst); uint intermediate = 0; keyMapper(in src, ref intermediate); if (intermediate == 0) { return; } keyValues.GetItemOrDefault((int)(intermediate - 1), ref value); dst.AppendMemory(value); });