Exemple #1
0
        protected internal override void Write(Datum aggregatedDatum, object batchContext, object typeContext)
        {
            if (!Running)
            {
                return;
            }
            if (aggregatedDatum == null)
            {
                return;
            }
            if (m_IAmRootHost)
            {
                return;
            }

            var t = aggregatedDatum.GetType();

            BySrc bySrc;

            if (!m_ByType.TryGetValue(t, out bySrc))
            {
                bySrc       = new BySrc();
                m_ByType[t] = bySrc;
            }

            Chunk chunk;

            if (!bySrc.TryGetValue(aggregatedDatum.Source, out chunk))
            {
                chunk = new Chunk();
                bySrc[aggregatedDatum.Source] = chunk;
            }

            chunk.Push(aggregatedDatum);
            if (m_Uploading != null)
            {
                return;
            }


            var toUpload = new List <Datum>();

            foreach (var kvpT in m_ByType)
            {
                foreach (var kvpS in kvpT.Value)
                {
                    var reaggr = kvpS.Value.Reaggregate();
                    if (reaggr == null)
                    {
                        continue;
                    }
                    toUpload.Add(reaggr);
                }
            }

            m_Uploading = toUpload;
        }
Exemple #2
0
#pragma warning disable CA1043
        internal TypeHandler this[Type type]
#pragma warning restore CA1043
        {
            get
            {
                if (ByType.TryGetValue(type, out var handler))
                {
                    return(handler);
                }

                // Try to find the backend type by a simple lookup on the given CLR type, this will handle base types.
                if (_postgresTypes.ByClrType.TryGetValue(type, out var postgresType))
                {
                    return(postgresType.Activate(this));
                }

                // Try to see if it is an array type
                var arrayElementType = GetArrayElementType(type);
                if (arrayElementType != null)
                {
                    if (ByType.TryGetValue(arrayElementType, out var elementHandler) &&
                        elementHandler.PostgresType.NpgsqlDbType.HasValue &&
                        ByNpgsqlDbType.TryGetValue(NpgsqlDbType.Array | elementHandler.PostgresType.NpgsqlDbType.Value, out handler))
                    {
                        return(handler);
                    }

                    // Enum and composite types go through the special _arrayHandlerByType
                    if (ArrayHandlerByType != null && ArrayHandlerByType.TryGetValue(arrayElementType, out handler))
                    {
                        return(handler);
                    }

                    // Unactivated array

                    // Special check for byte[] - bytea not array of int2
                    if (type == typeof(byte[]))
                    {
                        if (!_postgresTypes.ByClrType.TryGetValue(typeof(byte[]), out var byteaPostgresType))
                        {
                            throw new NpgsqlException("The PostgreSQL 'bytea' type is missing");
                        }
                        return(byteaPostgresType.Activate(this));
                    }

                    // Get the elements backend type and activate its array backend type
                    if (!_postgresTypes.ByClrType.TryGetValue(arrayElementType, out var elementPostgresType))
                    {
                        if (arrayElementType.GetTypeInfo().IsEnum)
                        {
                            throw new NotSupportedException($"The CLR enum type {arrayElementType.Name} must be mapped with Npgsql before usage, please refer to the documentation.");
                        }
                        throw new NotSupportedException($"The CLR type {arrayElementType} isn't supported by Npgsql or your PostgreSQL. " +
                                                        "If you wish to map it to a PostgreSQL composite type you need to register it before usage, please refer to the documentation.");
                    }

                    if (elementPostgresType == null)
                    {
                        throw new NotSupportedException($"The PostgreSQL {arrayElementType.Name} does not have an array type in the database");
                    }

                    return(elementPostgresType.Array.Activate(this));
                }

                // Range type which hasn't yet been set up
                if (type.GetTypeInfo().IsGenericType&& type.GetGenericTypeDefinition() == typeof(NpgsqlRange <>))
                {
                    if (!_postgresTypes.ByClrType.TryGetValue(type.GetGenericArguments()[0], out var subtypePostgresType) ||
                        subtypePostgresType.Range == null)
                    {
                        throw new NpgsqlException($"The .NET range type {type.Name} isn't supported in your PostgreSQL, use CREATE TYPE AS RANGE");
                    }

                    return(subtypePostgresType.Range.Activate(this));
                }

                // Nothing worked
                if (type.GetTypeInfo().IsEnum)
                {
                    throw new NotSupportedException($"The CLR enum type {type.Name} must be registered with Npgsql before usage, please refer to the documentation.");
                }

                if (typeof(IEnumerable).IsAssignableFrom(type))
                {
                    throw new NotSupportedException("Npgsql 3.x removed support for writing a parameter with an IEnumerable value, use .ToList()/.ToArray() instead");
                }

                throw new NotSupportedException($"The CLR type {type} isn't supported by Npgsql or your PostgreSQL. " +
                                                "If you wish to map it to a PostgreSQL composite type you need to register it before usage, please refer to the documentation.");
            }
        }