protected Data(DataKind kind, HexSpan span)
 {
     Kind = kind;
     Span = span;
 }
 public Column(int columnIndex, ColumnPurpose purpose, DataKind itemKind)
 {
     ColumnIndex = columnIndex;
     Purpose     = purpose;
     ItemKind    = itemKind;
 }
示例#3
0
 internal DeleteData(DataKind kind, string key, int version)
 {
     Kind    = kind;
     Key     = key;
     Version = version;
 }
 protected SoundCloudUserData(DataKind kind) : base(kind)
 {
     User = new User() { Id = 0 };
 }
 private string ItemsKey(DataKind kind) => _prefix + ":" + kind.Name;
示例#6
0
        /// <summary>
        /// Read a value from the stream. The value must have been written using ObjectWriter.WriteValue.
        /// </summary>
        public object ReadValue()
        {
            DataKind kind = (DataKind)reader.ReadByte();

            switch (kind)
            {
            case DataKind.Null:
                return(null);

            case DataKind.Boolean_T:
                return(BooleanTrue);

            case DataKind.Boolean_F:
                return(BooleanFalse);

            case DataKind.Int8:
                return(reader.ReadSByte());

            case DataKind.UInt8:
                return(reader.ReadByte());

            case DataKind.Int16:
                return(reader.ReadInt16());

            case DataKind.UInt16:
                return(reader.ReadUInt16());

            case DataKind.Int32:
                return(reader.ReadInt32());

            case DataKind.Int32_B:
                return((int)reader.ReadByte());

            case DataKind.Int32_S:
                return((int)reader.ReadUInt16());

            case DataKind.Int32_Z:
                return(Int32Zero);

            case DataKind.UInt32:
                return(reader.ReadUInt32());

            case DataKind.Int64:
                return(reader.ReadInt64());

            case DataKind.UInt64:
                return(reader.ReadUInt64());

            case DataKind.Float4:
                return(reader.ReadSingle());

            case DataKind.Float8:
                return(reader.ReadDouble());

            case DataKind.Decimal:
                return(reader.ReadDecimal());

            case DataKind.DateTime:
                return(this.ReadDateTime());

            case DataKind.Char:
                return(this.ReadChar());

            case DataKind.StringUtf8:
            case DataKind.StringUtf16:
            case DataKind.StringRef:
            case DataKind.StringRef_B:
            case DataKind.StringRef_S:
                return(ReadString(kind));

            case DataKind.Object_W:
            case DataKind.ObjectRef:
            case DataKind.ObjectRef_B:
            case DataKind.ObjectRef_S:
                return(ReadObject(kind));

            case DataKind.Type:
            case DataKind.TypeRef:
            case DataKind.TypeRef_B:
            case DataKind.TypeRef_S:
                return(ReadType(kind));

            case DataKind.Enum:
                return(ReadEnum());

            case DataKind.Array:
            case DataKind.Array_0:
            case DataKind.Array_1:
            case DataKind.Array_2:
            case DataKind.Array_3:
                return(ReadArray(kind));

            default:
                throw ExceptionUtilities.UnexpectedValue(kind);
            }
        }
示例#7
0
 internal KeyType(DataKind kind, ulong min, int count, bool contiguous = true)
     : this(ToRawType(kind), kind, min, count, contiguous)
 {
 }
        /// <summary>
        /// Given a field or property info on a type, returns whether this appears to be a vector type,
        /// and also the associated data kind for this type. If a data kind could not
        /// be determined, this will throw.
        /// </summary>
        /// <param name="memberInfo">The field or property info to inspect.</param>
        /// <param name="isVector">Whether this appears to be a vector type.</param>
        /// <param name="kind">The data kind of the type, or items of this type if vector.</param>
        public static void GetVectorAndKind(MemberInfo memberInfo, out bool isVector, out DataKind kind)
        {
            Contracts.AssertValue(memberInfo);
            switch (memberInfo)
            {
            case FieldInfo fieldInfo:
                GetVectorAndKind(fieldInfo.FieldType, fieldInfo.Name, out isVector, out kind);
                break;

            case PropertyInfo propertyInfo:
                GetVectorAndKind(propertyInfo.PropertyType, propertyInfo.Name, out isVector, out kind);
                break;

            default:
                Contracts.Assert(false);
                throw Contracts.ExceptNotSupp("Expected a FieldInfo or a PropertyInfo");
            }
        }
        /// <summary>
        /// Given a parameter info on a type, returns whether this appears to be a vector type,
        /// and also the associated data kind for this type. If a data kind could not
        /// be determined, this will throw.
        /// </summary>
        /// <param name="parameterInfo">The parameter info to inspect.</param>
        /// <param name="isVector">Whether this appears to be a vector type.</param>
        /// <param name="kind">The data kind of the type, or items of this type if vector.</param>
        public static void GetVectorAndKind(ParameterInfo parameterInfo, out bool isVector, out DataKind kind)
        {
            Contracts.AssertValue(parameterInfo);
            Type rawParameterType = parameterInfo.ParameterType;
            var  name             = parameterInfo.Name;

            GetVectorAndKind(rawParameterType, name, out isVector, out kind);
        }
示例#10
0
 public int GetDataKind(out DataKind dataKind)
 {
     dataKind = default(DataKind);
     int _dataKindEnum;
     int hr = S.StdCall<int>(GetVTableMember(9), Punk, out _dataKindEnum);
     GC.KeepAlive(this);
     dataKind = (DataKind)_dataKindEnum;
     return hr;
 }
示例#11
0
        private string ReadString(DataKind kind)
        {
            switch (kind)
            {
                case DataKind.StringRef_B:
                    return (string)this.dataMap.GetValue(reader.ReadByte());

                case DataKind.StringRef_S:
                    return (string)this.dataMap.GetValue(reader.ReadUInt16());

                case DataKind.StringRef:
                    return (string)this.dataMap.GetValue(reader.ReadInt32());

                case DataKind.String:
                    int id = this.dataMap.GetNextId();
                    string value = reader.ReadString();
                    this.dataMap.AddValue(id, value);
                    return value;

                default:
                    throw ExceptionUtilities.UnexpectedValue(kind);
            }
        }
示例#12
0
 private static string mapKind(DataKind kind)
 {
   switch (kind)
   {
      case DataKind.DateTimeLocal: return "datetime-local";
      case DataKind.Telephone: return "tel";
      default: return kind.ToString().ToLowerInvariant();
   }
 }
示例#13
0
        public FieldAttribute(
            Type protoType,
            string protoFieldName, //Schema:Field
            string targetName   = ANY_TARGET,
            object storeFlag    = null,
            object key          = null,
            object kind         = null,
            object required     = null,
            object visible      = null,
            string valueList    = null,
            object dflt         = null,
            object min          = null,
            object max          = null,
            object minLength    = null,
            object maxLength    = null,
            object charCase     = null,
            string backendName  = null,
            string backendType  = null,
            string description  = null,
            string metadata     = null,
            object nonUI        = null,
            string formatRegExp = null,
            string formatDescr  = null,
            string displayFormat = null
            )
            : base(targetName, null)
        {
            if (protoType==null || protoFieldName.IsNullOrWhiteSpace()) throw new CRUDException(StringConsts.ARGUMENT_ERROR+"FieldAttr.ctor(protoType|protoFieldName=null|empty)");
            try
            {
              var schema = Schema.GetForTypedRow(protoType);
              var protoTargetName = targetName;
              var segs = protoFieldName.Split(':');
              if (segs.Length>1)
              {
                protoTargetName = segs[0].Trim();
                protoFieldName = segs[1].Trim();
              }
              if (protoTargetName.IsNullOrWhiteSpace()) throw new Exception("Wrong target syntax");
              if (protoFieldName.IsNullOrWhiteSpace()) throw new Exception("Wrong field syntax");

              var protoFieldDef = schema[protoFieldName];
              if (protoFieldDef==null) throw new Exception("Prototype '{0}' field '{1}' not found".Args(protoType.FullName, protoFieldName));
              var protoAttr = protoFieldDef[protoTargetName];

              try
              {
                StoreFlag        = storeFlag    == null? protoAttr.StoreFlag   : (StoreFlag)storeFlag;
                BackendName      = backendName  == null? protoAttr.BackendName : backendName;
                BackendType      = backendType  == null? protoAttr.BackendType : backendType;
                Key              = key          == null? protoAttr.Key         : (bool)key;
                Kind             = kind         == null? protoAttr.Kind        : (DataKind)kind;
                Required         = required     == null? protoAttr.Required    : (bool)required;
                Visible          = visible      == null? protoAttr.Visible     : (bool)visible;
                Min              = min          == null? protoAttr.Min         : min;
                Max              = max          == null? protoAttr.Max         : max;
                Default          = dflt         == null? protoAttr.Default     : dflt;
                MinLength        = minLength    == null? protoAttr.MinLength   : (int)minLength;
                MaxLength        = maxLength    == null? protoAttr.MaxLength   : (int)maxLength;
                CharCase         = charCase     == null? protoAttr.CharCase    : (CharCase)charCase;
                ValueList        = valueList    == null? protoAttr.ValueList   : valueList;
                Description      = description  == null? protoAttr.Description : description;
                NonUI            = nonUI        == null? protoAttr.NonUI       : (bool)nonUI;
                FormatRegExp     = formatRegExp == null? protoAttr.FormatRegExp: formatRegExp;
                FormatDescription= formatDescr  == null? protoAttr.FormatDescription: formatDescr;
                DisplayFormat    = displayFormat== null? protoAttr.DisplayFormat    : displayFormat;

                if (metadata.IsNullOrWhiteSpace())
                 m_MetadataContent = protoAttr.m_MetadataContent;
                else
                if (protoAttr.m_MetadataContent.IsNullOrWhiteSpace()) m_MetadataContent = metadata;
                else
                {
                  var conf1 = ParseMetadataContent(protoAttr.m_MetadataContent);
                  var conf2 = ParseMetadataContent(metadata);

                  var merged = new LaconicConfiguration();
                  merged.CreateFromMerge(conf1, conf2);
                  m_MetadataContent = merged.SaveToString();
                }
              }
              catch(Exception err)
              {
                throw new Exception("Invalid assignment of prototype override value: " + err.ToMessageWithType());
              }
            }
            catch(Exception error)
            {
              throw new CRUDException(StringConsts.CRUD_FIELD_ATTR_PROTOTYPE_CTOR_ERROR.Args(error.Message));
            }
        }
示例#14
0
        /// <summary>
        /// Used for injection of pre-parsed value list
        /// </summary>
        public FieldAttribute(
            JSONDataMap valueList,
            string targetName   = ANY_TARGET,
            StoreFlag storeFlag = StoreFlag.LoadAndStore,
            bool key            = false,
            DataKind kind       = DataKind.Text,
            bool required       = false,
            bool visible        = true,
            object dflt         = null,
            object min          = null,
            object max          = null,
            int minLength       = 0,
            int maxLength       = 0,
            CharCase charCase   = CharCase.AsIs,
            string backendName  = null,
            string backendType  = null,
            string description  = null,
            string metadata = null,
            bool nonUI = false,
            string formatRegExp = null,
            string formatDescr  = null,
            string displayFormat = null
            )
            : base(targetName, metadata)
        {
            if (valueList == null)
               throw new CRUDException("FieldAttribute(JSONDataMap valueList==null)");

              StoreFlag = storeFlag;
              BackendName = backendName;
              BackendType = backendType;
              Key = key;
              Kind = kind;
              Required = required;
              Visible = visible;
              Min = min;
              Max = max;
              Default = dflt;
              MinLength = minLength;
              MaxLength = maxLength;
              CharCase = charCase;
              Description = description;
              NonUI = nonUI;
              FormatRegExp = formatRegExp;
              FormatDescription = formatDescr;
              DisplayFormat = displayFormat;

              m_CacheValueListPresetInCtor = true;
              m_CacheValueList_Insensitive = valueList;
              m_CacheValueList_Sensitive = valueList;
              ValueList = null;
        }
示例#15
0
        private Array ReadPrimitiveTypeArrayElements(Type type, DataKind kind, int length)
        {
            Debug.Assert(s_reverseTypeMap[kind] == type);

            // optimizations for supported array type by binary reader
            if (type == typeof(byte))
            {
                return(_reader.ReadBytes(length));
            }

            if (type == typeof(char))
            {
                return(_reader.ReadChars(length));
            }

            // optimizations for string where object reader/writer has its own mechanism to
            // reduce duplicated strings
            if (type == typeof(string))
            {
                return(ReadPrimitiveTypeArrayElements(length, ReadString));
            }

            if (type == typeof(bool))
            {
                return(ReadBooleanArray(length));
            }

            // otherwise, read elements directly from underlying binary writer
            switch (kind)
            {
            case DataKind.Int8:
                return(ReadPrimitiveTypeArrayElements(length, _reader.ReadSByte));

            case DataKind.Int16:
                return(ReadPrimitiveTypeArrayElements(length, _reader.ReadInt16));

            case DataKind.Int32:
                return(ReadPrimitiveTypeArrayElements(length, _reader.ReadInt32));

            case DataKind.Int64:
                return(ReadPrimitiveTypeArrayElements(length, _reader.ReadInt64));

            case DataKind.UInt16:
                return(ReadPrimitiveTypeArrayElements(length, _reader.ReadUInt16));

            case DataKind.UInt32:
                return(ReadPrimitiveTypeArrayElements(length, _reader.ReadUInt32));

            case DataKind.UInt64:
                return(ReadPrimitiveTypeArrayElements(length, _reader.ReadUInt64));

            case DataKind.Float4:
                return(ReadPrimitiveTypeArrayElements(length, _reader.ReadSingle));

            case DataKind.Float8:
                return(ReadPrimitiveTypeArrayElements(length, _reader.ReadDouble));

            case DataKind.Decimal:
                return(ReadPrimitiveTypeArrayElements(length, _reader.ReadDecimal));

            default:
                throw ExceptionUtilities.UnexpectedValue(kind);
            }
        }
        /// <summary>
        /// Given a type and name for a variable, returns whether this appears to be a vector type,
        /// and also the associated data kind for this type. If a data kind could not
        /// be determined, this will throw.
        /// </summary>
        /// <param name="rawType">The type of the variable to inspect.</param>
        /// <param name="name">The name of the variable to inspect.</param>
        /// <param name="isVector">Whether this appears to be a vector type.</param>
        /// <param name="kind">The data kind of the type, or items of this type if vector.</param>
        public static void GetVectorAndKind(Type rawType, string name, out bool isVector, out DataKind kind)
        {
            // Determine whether this is a vector, and also determine the raw item type.
            Type rawItemType;

            isVector = true;
            if (rawType.IsArray)
            {
                rawItemType = rawType.GetElementType();
            }
            else if (rawType.IsGenericType && rawType.GetGenericTypeDefinition() == typeof(VBuffer <>))
            {
                rawItemType = rawType.GetGenericArguments()[0];
            }
            else
            {
                rawItemType = rawType;
                isVector    = false;
            }

            // Get the data kind, and the item's column type.
            if (rawItemType == typeof(string))
            {
                kind = DataKind.Text;
            }
            else if (!rawItemType.TryGetDataKind(out kind))
            {
                throw Contracts.ExceptParam(nameof(rawType), "Could not determine an IDataView type for member {0}", name);
            }
        }
示例#17
0
 private Key <T> Load <T>(DataKind kind, int ordinal, ulong?keyCount)
 {
     Contracts.CheckParam(ordinal >= 0, nameof(ordinal), "Should be non-negative");
     return(new MyKey <T>(_rec, kind, ordinal, keyCount));
 }
示例#18
0
 /// <summary>
 /// A view cannot be modified by adding a column.
 /// </summary>
 public int AddColumn(string name, DataKind kind, int?length)
 {
     throw new DataFrameViewException("A column cannot be added to a DataFrameView.");
 }
示例#19
0
 private protected StructuredType(Type rawType, DataKind rawKind)
     : base(rawType, rawKind)
 {
     Contracts.Assert(!IsPrimitive);
 }
        public bool Upsert(DataKind kind, string key, ItemDescriptor item)
        {
            var       serializedItem = Serialize(kind, item);
            bool      updated        = false;
            Exception failure        = null;

            try
            {
                updated = _core.Upsert(kind, key, serializedItem);
                ProcessError(null);
            }
            catch (Exception e)
            {
                // Normally, if the underlying store failed to do the update, we do not want to update the cache -
                // the idea being that it's better to stay in a consistent state of having old data than to act
                // like we have new data but then suddenly fall back to old data when the cache expires. However,
                // if the cache TTL is infinite, then it makes sense to update the cache always.
                ProcessError(e);
                if (!_caching.IsInfiniteTtl)
                {
                    throw;
                }
                failure = e;
            }
            if (_itemCache != null)
            {
                var cacheKey = new CacheKey(kind, key);
                if (failure is null)
                {
                    if (updated)
                    {
                        _itemCache.Set(cacheKey, item);
                    }
                    else
                    {
                        // there was a concurrent modification elsewhere - update the cache to get the new state
                        _itemCache.Remove(cacheKey);
                        _itemCache.Get(cacheKey);
                    }
                }
                else
                {
                    try
                    {
                        var oldItem = _itemCache.Get(cacheKey);
                        if (!oldItem.HasValue || oldItem.Value.Version < item.Version)
                        {
                            _itemCache.Set(cacheKey, item);
                        }
                    }
                    catch (Exception)
                    {
                        // An exception here means that the underlying database is down *and* there was no
                        // cached item; in that case we just go ahead and update the cache.
                        _itemCache.Set(cacheKey, item);
                    }
                }
            }
            if (_allCache != null)
            {
                // If the cache has a finite TTL, then we should remove the "all items" cache entry to force
                // a reread the next time All is called. However, if it's an infinite TTL, we need to just
                // update the item within the existing "all items" entry (since we want things to still work
                // even if the underlying store is unavailable).
                if (_caching.IsInfiniteTtl)
                {
                    try
                    {
                        var cachedAll = _allCache.Get(kind);
                        _allCache.Set(kind, cachedAll.SetItem(key, item));
                    }
                    catch (Exception) { }
                    // An exception here means that we did not have a cached value for All, so it tried to query
                    // the underlying store, which failed (not surprisingly since it just failed a moment ago
                    // when we tried to do an update). This should not happen in infinite-cache mode, but if it
                    // does happen, there isn't really anything we can do.
                }
                else
                {
                    _allCache.Remove(kind);
                }
            }
            if (failure != null)
            {
                throw failure;
            }
            return(updated);
        }
        public Dictionary <string, SerializedItemDescriptor> DataForPrefixAndKind(string prefix, DataKind kind)
        {
            var dfp = DataForPrefix(prefix);

            if (dfp.TryGetValue(kind, out var ret))
            {
                return(ret);
            }
            var d = new Dictionary <string, SerializedItemDescriptor>();

            dfp[kind] = d;
            return(d);
        }
 private ImmutableDictionary <string, ItemDescriptor> GetAllAndDeserialize(DataKind kind)
 {
     return(_core.GetAll(kind).Items.ToImmutableDictionary(
                kv => kv.Key,
                kv => Deserialize(kind, kv.Value)));
 }
        public bool Upsert(DataKind kind, string key, SerializedItemDescriptor newItem)
        {
            IDatabase db      = _redis.GetDatabase();
            string    baseKey = ItemsKey(kind);

            while (true)
            {
                string oldData;
                try
                {
                    oldData = db.HashGet(baseKey, key);
                }
                catch (RedisTimeoutException e)
                {
                    _log.Error("Timeout in update when reading {0} from {1}: {2}", key, baseKey, e.ToString());
                    throw;
                }
                // Here, unfortunately, we have to deserialize the old item (if any) just to find
                // out its version number (see implementation notes).
                var oldVersion = (oldData is null) ? 0 : kind.Deserialize(oldData).Version;
                if (oldVersion >= newItem.Version)
                {
                    _log.Debug("Attempted to {0} key: {1} version: {2} with a version that is" +
                               " the same or older: {3} in \"{4}\"",
                               newItem.Deleted ? "delete" : "update",
                               key, oldVersion, newItem.Version, kind.Name);
                    return(false);
                }

                // This hook is used only in unit tests
                _updateHook?.Invoke();

                // Note that transactions work a bit differently in StackExchange.Redis than in other
                // Redis clients. The same Redis connection is shared across all threads, so it can't
                // set a WATCH at the moment we start the transaction. Instead, it saves up all of
                // the actions we send during the transaction, and replays them all within a MULTI
                // when the transaction. AddCondition() is this client's way of doing a WATCH, and it
                // can only use an equality match on the whole value (which is unfortunate since a
                // serialized flag value could be fairly large).
                ITransaction txn = db.CreateTransaction();
                txn.AddCondition(oldData is null ? Condition.HashNotExists(baseKey, key) :
                                 Condition.HashEqual(baseKey, key, oldData));

                txn.HashSetAsync(baseKey, key, newItem.SerializedItem);

                try
                {
                    bool success = txn.Execute();
                    if (!success)
                    {
                        // The watch was triggered, we should retry
                        _log.Debug("Concurrent modification detected, retrying");
                        continue;
                    }
                }
                catch (RedisTimeoutException e)
                {
                    _log.Error("Timeout on update of {0} in {1}: {2}", key, baseKey, e.ToString());
                    throw;
                }
                return(true);
            }
        }
 private SerializedItemDescriptor Serialize(DataKind kind, ItemDescriptor itemDesc)
 {
     return(new SerializedItemDescriptor(itemDesc.Version,
                                         itemDesc.Item is null, kind.Serialize(itemDesc)));
 }
示例#25
0
 public FieldAttribute(
                 string targetName   = ANY_TARGET,
                 StoreFlag storeFlag = StoreFlag.LoadAndStore,
                 bool key            = false,
                 DataKind kind       = DataKind.Text,
                 bool required       = false,
                 bool visible        = true,
                 string valueList    = null,
                 object dflt         = null,
                 object min          = null,
                 object max          = null,
                 int minLength       = 0,
                 int maxLength       = 0,
                 CharCase charCase   = CharCase.AsIs,
                 string backendName  = null,
                 string description  = null,
                 string metadata = null,
                 bool nonUI = false
             ) : base(targetName, metadata)
 {
       StoreFlag = storeFlag;
       BackendName = backendName;
       Key = key;
       Kind = kind;
       Required = required;
       Visible = visible;
       Min = min;
       Max = max;
       Default = dflt;
       MinLength = minLength;
       MaxLength = maxLength;
       CharCase = charCase;
       ValueList = valueList;
       Description = description;
       NonUI = nonUI;
 }
 public CacheKey(DataKind kind, string key)
 {
     Kind = kind;
     Key  = key;
 }
示例#27
0
 internal PatchData(DataKind kind, string key, ItemDescriptor item)
 {
     Kind = kind;
     Key  = key;
     Item = item;
 }
示例#28
0
 protected virtual string MapCLRKindToJS(DataKind kind)
 {
   switch (kind)
   {
       case DataKind.DateTimeLocal: return "datetime-local";
       case DataKind.Telephone: return "tel";
       default: return kind.ToString().ToLowerInvariant();
   }
 }
示例#29
0
 internal static string PathNameForKind(DataKind kind) =>
 (kind == DataModel.Features) ? "flags" : kind.Name;
示例#30
0
        private string ReadString(DataKind kind)
        {
            switch (kind)
            {
                case DataKind.StringRef_B:
                    return (string)_dataMap.GetValue(_reader.ReadByte());

                case DataKind.StringRef_S:
                    return (string)_dataMap.GetValue(_reader.ReadUInt16());

                case DataKind.StringRef:
                    return (string)_dataMap.GetValue(_reader.ReadInt32());

                case DataKind.StringUtf16:
                case DataKind.StringUtf8:
                    return ReadStringLiteral(kind);

                default:
                    throw ExceptionUtilities.UnexpectedValue(kind);
            }
        }
 /// <summary>
 /// Create a <see cref="TypeConvertingEstimator"/>, which converts the type of the data to the type specified in <paramref name="outputKind"/>.
 /// </summary>
 /// <param name="catalog">The conversion transform's catalog.</param>
 /// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param>
 /// <param name="inputColumnName">Name of the column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.
 /// This transform operates over numeric, boolean, text, <see cref="System.DateTime"/> and key data types.</param>
 /// <param name="outputKind">The expected kind of the output column.</param>
 /// <example>
 /// <format type="text/markdown">
 /// <![CDATA[
 ///  [!code-csharp[ConvertType](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/Conversion/ConvertType.cs)]
 /// ]]></format>
 /// </example>
 public static TypeConvertingEstimator ConvertType(this TransformsCatalog.ConversionTransforms catalog, string outputColumnName, string inputColumnName = null,
                                                   DataKind outputKind = ConvertDefaults.DefaultOutputKind)
 => new TypeConvertingEstimator(CatalogUtils.GetEnvironment(catalog), new[] { new TypeConvertingEstimator.ColumnOptions(outputColumnName, outputKind, inputColumnName) });
示例#32
0
        private unsafe string ReadStringLiteral(DataKind kind)
        {
            int id = _dataMap.GetNextId();
            string value;
            if (kind == DataKind.StringUtf8)
            {
                value = _reader.ReadString();
            }
            else
            {
                // This is rare, just allocate UTF16 bytes for simplicity.

                int characterCount = (int)ReadCompressedUInt();
                byte[] bytes = _reader.ReadBytes(characterCount * sizeof(char));
                fixed (byte* bytesPtr = bytes)
                {
                    value = new string((char*)bytesPtr, 0, characterCount);
                }
            }

            _dataMap.AddValue(id, value);
            return value;
        }
示例#33
0
 private Scalar <T> Load <T>(DataKind kind, int ordinal)
 {
     Contracts.CheckParam(ordinal >= 0, nameof(ordinal), "Should be non-negative");
     return(new MyScalar <T>(_rec, kind, ordinal));
 }
示例#34
0
        private Array ReadArray(DataKind kind)
        {
            int length;
            switch (kind)
            {
                case DataKind.Array_0:
                    length = 0;
                    break;
                case DataKind.Array_1:
                    length = 1;
                    break;
                case DataKind.Array_2:
                    length = 2;
                    break;
                case DataKind.Array_3:
                    length = 3;
                    break;
                default:
                    length = (int)this.ReadCompressedUInt();
                    break;
            }

            Type elementType = this.ReadType();
            Array array = Array.CreateInstance(elementType, length);
            for (int i = 0; i < length; i++)
            {
                var value = this.ReadValue();
                array.SetValue(value, i);
            }

            return array;
        }
示例#35
0
 public MyScalar(Reconciler rec, DataKind kind, int ordinal)
     : base(rec, null)
 {
     _kind    = kind;
     _ordinal = ordinal;
 }
示例#36
0
        private Type ReadType(DataKind kind)
        {
            switch (kind)
            {
                case DataKind.TypeRef_B:
                    return (Type)_dataMap.GetValue(_reader.ReadByte());

                case DataKind.TypeRef_S:
                    return (Type)_dataMap.GetValue(_reader.ReadUInt16());

                case DataKind.TypeRef:
                    return (Type)_dataMap.GetValue(_reader.ReadInt32());

                case DataKind.Type:
                    int id = _dataMap.GetNextId();
                    var assemblyName = this.ReadString();
                    var typeName = this.ReadString();

                    if (_binder == null)
                    {
                        throw NoBinderException(typeName);
                    }

                    var type = _binder.GetType(assemblyName, typeName);
                    _dataMap.AddValue(id, type);
                    return type;

                default:
                    throw ExceptionUtilities.UnexpectedValue(kind);
            }
        }
示例#37
0
        private Type ReadType()
        {
            DataKind kind = (DataKind)reader.ReadByte();

            return(ReadType(kind));
        }
示例#38
0
        private object ReadObject(DataKind kind)
        {
            switch (kind)
            {
                case DataKind.ObjectRef_B:
                    return _dataMap.GetValue(_reader.ReadByte());

                case DataKind.ObjectRef_S:
                    return _dataMap.GetValue(_reader.ReadUInt16());

                case DataKind.ObjectRef:
                    return _dataMap.GetValue(_reader.ReadInt32());

                case DataKind.Object_W:
                    return this.ReadReadableObject();

                case DataKind.Array:
                    return this.ReadArray(kind);

                default:
                    throw ExceptionUtilities.UnexpectedValue(kind);
            }
        }
示例#39
0
 private protected PrimitiveType(Type rawType, DataKind rawKind)
     : base(rawType, rawKind)
 {
     Contracts.Assert(IsPrimitive);
     Contracts.Assert(!typeof(IDisposable).IsAssignableFrom(RawType));
 }
示例#40
0
        /// <summary>
        /// Try to map a System.Type to a corresponding DataKind value.
        /// </summary>
        public static bool TryGetDataKind(this Type type, out DataKind kind)
        {
            Contracts.CheckValueOrNull(type);

            // REVIEW: Make this more efficient. Should we have a global dictionary?
            if (type == typeof(DvInt1) || type == typeof(sbyte) || type == typeof(sbyte?))
            {
                kind = DataKind.I1;
            }
            else if (type == typeof(byte) || type == typeof(byte?))
            {
                kind = DataKind.U1;
            }
            else if (type == typeof(DvInt2) || type == typeof(short) || type == typeof(short?))
            {
                kind = DataKind.I2;
            }
            else if (type == typeof(ushort) || type == typeof(ushort?))
            {
                kind = DataKind.U2;
            }
            else if (type == typeof(DvInt4) || type == typeof(int) || type == typeof(int?))
            {
                kind = DataKind.I4;
            }
            else if (type == typeof(uint) || type == typeof(uint?))
            {
                kind = DataKind.U4;
            }
            else if (type == typeof(DvInt8) || type == typeof(long) || type == typeof(long?))
            {
                kind = DataKind.I8;
            }
            else if (type == typeof(ulong) || type == typeof(ulong?))
            {
                kind = DataKind.U8;
            }
            else if (type == typeof(Single) || type == typeof(Single?))
            {
                kind = DataKind.R4;
            }
            else if (type == typeof(Double) || type == typeof(Double?))
            {
                kind = DataKind.R8;
            }
            else if (type == typeof(DvText))
            {
                kind = DataKind.TX;
            }
            else if (type == typeof(DvBool) || type == typeof(bool) || type == typeof(bool?))
            {
                kind = DataKind.BL;
            }
            else if (type == typeof(DvTimeSpan))
            {
                kind = DataKind.TS;
            }
            else if (type == typeof(DvDateTime))
            {
                kind = DataKind.DT;
            }
            else if (type == typeof(DvDateTimeZone))
            {
                kind = DataKind.DZ;
            }
            else if (type == typeof(UInt128))
            {
                kind = DataKind.UG;
            }
            else
            {
                kind = default(DataKind);
                return(false);
            }

            return(true);
        }
示例#41
0
 private static Type ToRawType(DataKind kind)
 {
     Contracts.CheckParam(IsValidDataKind(kind), nameof(kind));
     return(kind.ToType());
 }
示例#42
0
 /// <summary>
 /// Maps a DataKind to a value suitable for indexing into an array of size KindCount.
 /// </summary>
 public static int ToIndex(this DataKind kind)
 {
     return(kind - KindMin);
 }
示例#43
0
        /// <summary>
        /// Try to map a System.Type to a corresponding DataKind value.
        /// </summary>
        public static bool TryGetDataKind(this Type type, out DataKind kind)
        {
            Contracts.CheckValueOrNull(type);

            // REVIEW: Make this more efficient. Should we have a global dictionary?
            if (type == typeof(sbyte))
            {
                kind = DataKind.I1;
            }
            else if (type == typeof(byte))
            {
                kind = DataKind.U1;
            }
            else if (type == typeof(short))
            {
                kind = DataKind.I2;
            }
            else if (type == typeof(ushort))
            {
                kind = DataKind.U2;
            }
            else if (type == typeof(int))
            {
                kind = DataKind.I4;
            }
            else if (type == typeof(uint))
            {
                kind = DataKind.U4;
            }
            else if (type == typeof(long))
            {
                kind = DataKind.I8;
            }
            else if (type == typeof(ulong))
            {
                kind = DataKind.U8;
            }
            else if (type == typeof(Single))
            {
                kind = DataKind.R4;
            }
            else if (type == typeof(Double))
            {
                kind = DataKind.R8;
            }
            else if (type == typeof(ReadOnlyMemory <char>) || type == typeof(string))
            {
                kind = DataKind.TX;
            }
            else if (type == typeof(bool))
            {
                kind = DataKind.BL;
            }
            else if (type == typeof(TimeSpan))
            {
                kind = DataKind.TS;
            }
            else if (type == typeof(DateTime))
            {
                kind = DataKind.DT;
            }
            else if (type == typeof(DateTimeOffset))
            {
                kind = DataKind.DZ;
            }
            else if (type == typeof(RowId))
            {
                kind = DataKind.UG;
            }
            else
            {
                kind = default(DataKind);
                return(false);
            }

            return(true);
        }
示例#44
0
 internal ExprData(DataKind type, int data)
 {
     Type = type;
     Data = data;
 }