コード例 #1
0
        public override IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            IReadOnlyList <uint> preparedRows;

            switch (rows)
            {
            case IReadOnlyList <IPAddress> ipAddressRows:
                preparedRows = new MappedReadOnlyList <IPAddress, uint>(ipAddressRows, IpAddressToUInt32);
                break;

            case IReadOnlyList <string> stringRows:
                preparedRows = new MappedReadOnlyList <string, uint>(stringRows, IpAddressStringToUInt32);
                break;

            case IReadOnlyList <uint> uint32Rows:
                preparedRows = uint32Rows;
                break;

            case IReadOnlyList <int> int32Rows:
                preparedRows = new MappedReadOnlyList <int, uint>(int32Rows, v => unchecked ((uint)v));
                break;

            default:
                throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{typeof(T)}\" can't be converted to the ClickHouse type \"{ComplexTypeName}\".");
            }

            return(new IpV4Writer(columnName, TypeName, preparedRows));
        }
コード例 #2
0
        public override IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            if (!(rows is IReadOnlyList <int> intRows))
            {
                if (rows is IReadOnlyList <short> shortRows)
                {
                    intRows = new MappedReadOnlyList <short, int>(shortRows, v => v);
                }
                else if (rows is IReadOnlyList <ushort> ushortRows)
                {
                    intRows = new MappedReadOnlyList <ushort, int>(ushortRows, v => v);
                }
                else if (rows is IReadOnlyList <sbyte> sbyteRows)
                {
                    intRows = new MappedReadOnlyList <sbyte, int>(sbyteRows, v => v);
                }
                else if (rows is IReadOnlyList <byte> byteRows)
                {
                    intRows = new MappedReadOnlyList <byte, int>(byteRows, v => v);
                }
                else
                {
                    throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{typeof(T)}\" can't be converted to the ClickHouse type \"{ComplexTypeName}\".");
                }
            }

            return(new Int32Writer(columnName, ComplexTypeName, intRows));
        }
コード例 #3
0
        public override IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            var type = typeof(T);
            IReadOnlyList <ulong> ulongRows;

            if (type == typeof(ulong))
            {
                ulongRows = (IReadOnlyList <ulong>)rows;
            }
            else if (type == typeof(uint))
            {
                ulongRows = MappedReadOnlyList <uint, ulong> .Map((IReadOnlyList <uint>) rows, v => v);
            }
            else if (type == typeof(ushort))
            {
                ulongRows = MappedReadOnlyList <ushort, ulong> .Map((IReadOnlyList <ushort>) rows, v => v);
            }
            else if (type == typeof(byte))
            {
                ulongRows = MappedReadOnlyList <byte, ulong> .Map((IReadOnlyList <byte>) rows, v => v);
            }
            else
            {
                throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{typeof(T)}\" can't be converted to the ClickHouse type \"{ComplexTypeName}\".");
            }

            return(new UInt64Writer(columnName, ComplexTypeName, ulongRows));
        }
コード例 #4
0
        public IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            if (_precision == null && _scale == null)
            {
                var specifiedType = CloneWithOptions(string.Format(CultureInfo.InvariantCulture, "Decimal128({0})", DefaultScale), DefaultPrecision, DefaultScale);
                return(specifiedType.CreateColumnWriter(columnName, rows, columnSettings));
            }

            if (_scale == null)
            {
                throw new ClickHouseException(ClickHouseErrorCodes.TypeNotFullySpecified, $"Scale is required for the type \"{TypeName}\".");
            }

            if (_precision == null)
            {
                throw new ClickHouseException(ClickHouseErrorCodes.TypeNotFullySpecified, $"Precision is required for the type \"{TypeName}\".");
            }

            if (!(rows is IReadOnlyList <decimal> decimalRows))
            {
                if (rows is IReadOnlyList <long> longRows)
                {
                    decimalRows = new MappedReadOnlyList <long, decimal>(longRows, v => v);
                }
                else if (rows is IReadOnlyList <ulong> ulongRows)
                {
                    decimalRows = new MappedReadOnlyList <ulong, decimal>(ulongRows, v => v);
                }
                else if (rows is IReadOnlyList <int> intRows)
                {
                    decimalRows = new MappedReadOnlyList <int, decimal>(intRows, v => v);
                }
                else if (rows is IReadOnlyList <uint> uintRows)
                {
                    decimalRows = new MappedReadOnlyList <uint, decimal>(uintRows, v => v);
                }
                else if (rows is IReadOnlyList <short> shortRows)
                {
                    decimalRows = new MappedReadOnlyList <short, decimal>(shortRows, v => v);
                }
                else if (rows is IReadOnlyList <ushort> ushortRows)
                {
                    decimalRows = new MappedReadOnlyList <ushort, decimal>(ushortRows, v => v);
                }
                else if (rows is IReadOnlyList <sbyte> sbyteRows)
                {
                    decimalRows = new MappedReadOnlyList <sbyte, decimal>(sbyteRows, v => v);
                }
                else if (rows is IReadOnlyList <byte> byteRows)
                {
                    decimalRows = new MappedReadOnlyList <byte, decimal>(byteRows, v => v);
                }
                else
                {
                    throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{typeof(T)}\" can't be converted to the ClickHouse type \"{ComplexTypeName}\".");
                }
            }

            return(new DecimalWriter(columnName, ComplexTypeName, _precision.Value, _scale.Value, decimalRows));
        }
コード例 #5
0
        public override IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            var type = typeof(T);
            IReadOnlyList <uint> preparedRows;

            if (typeof(IPAddress).IsAssignableFrom(type))
            {
                preparedRows = MappedReadOnlyList <IPAddress, uint> .Map((IReadOnlyList <IPAddress>) rows, IpAddressToUInt32);
            }
            else if (type == typeof(string))
            {
                preparedRows = MappedReadOnlyList <string, uint> .Map((IReadOnlyList <string>) rows, IpAddressStringToUInt32);
            }
            else if (type == typeof(uint))
            {
                preparedRows = (IReadOnlyList <uint>)rows;
            }
            else if (type == typeof(int))
            {
                preparedRows = MappedReadOnlyList <int, uint> .Map((IReadOnlyList <int>) rows, v => unchecked ((uint)v));
            }
            else
            {
                throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{typeof(T)}\" can't be converted to the ClickHouse type \"{ComplexTypeName}\".");
            }

            return(new IpV4Writer(columnName, TypeName, preparedRows));
        }
コード例 #6
0
            public IClickHouseColumnWriter Dispatch(string columnName, object rows, ClickHouseColumnSettings?columnSettings, IClickHouseColumnTypeInfo underlyingTypeInfo)
            {
                var genericList = (IReadOnlyList <TValue?>)rows;
                var listWrapper = MappedReadOnlyList <TValue?, TValue> .Map(genericList, item => item ?? default);

                return(underlyingTypeInfo.CreateColumnWriter(columnName, listWrapper, columnSettings));
            }
コード例 #7
0
            public IClickHouseColumnWriter Dispatch <T>()
            {
                var mappedRows          = new MappedReadOnlyList <Array, IReadOnlyList <T> >(_rows, arr => (IReadOnlyList <T>)_dispatchArray(arr));
                var linearizedList      = new ArrayLinearizedList <T>(mappedRows);
                var elementColumnWriter = _elementTypeInfo.CreateColumnWriter(_columnName, linearizedList, _columnSettings);

                return(new ArrayColumnWriter <T>(_columnType, linearizedList, elementColumnWriter));
            }
コード例 #8
0
        public sealed override IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            var type = typeof(T);
            IReadOnlyList <BigInteger>?bigIntegerRows = null;

            if (type == typeof(BigInteger))
            {
                bigIntegerRows = (IReadOnlyList <BigInteger>)rows;
            }
            else if (type == typeof(ulong))
            {
                bigIntegerRows = MappedReadOnlyList <ulong, BigInteger> .Map((IReadOnlyList <ulong>) rows, v => v);
            }
            else if (type == typeof(uint))
            {
                bigIntegerRows = MappedReadOnlyList <uint, BigInteger> .Map((IReadOnlyList <uint>) rows, v => v);
            }
            else if (type == typeof(ushort))
            {
                bigIntegerRows = MappedReadOnlyList <ushort, BigInteger> .Map((IReadOnlyList <ushort>) rows, v => v);
            }
            else if (type == typeof(byte))
            {
                bigIntegerRows = MappedReadOnlyList <byte, BigInteger> .Map((IReadOnlyList <byte>) rows, v => v);
            }
            else if (!_isUnsigned)
            {
                if (type == typeof(long))
                {
                    bigIntegerRows = MappedReadOnlyList <long, BigInteger> .Map((IReadOnlyList <long>) rows, v => v);
                }
                else if (type == typeof(int))
                {
                    bigIntegerRows = MappedReadOnlyList <int, BigInteger> .Map((IReadOnlyList <int>) rows, v => v);
                }
                else if (type == typeof(short))
                {
                    bigIntegerRows = MappedReadOnlyList <short, BigInteger> .Map((IReadOnlyList <short>) rows, v => v);
                }
                else if (type == typeof(sbyte))
                {
                    bigIntegerRows = MappedReadOnlyList <sbyte, BigInteger> .Map((IReadOnlyList <sbyte>) rows, v => v);
                }
            }

            if (bigIntegerRows == null)
            {
                throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{type}\" can't be converted to the ClickHouse type \"{ComplexTypeName}\".");
            }

            return(new BigIntegerColumnWriter(columnName, ComplexTypeName, _elementByteSize, bigIntegerRows, _isUnsigned));
        }
コード例 #9
0
        public override IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            if (!(rows is IReadOnlyList <double> doubleRows))
            {
                if (rows is IReadOnlyList <float> floatRows)
                {
                    doubleRows = new MappedReadOnlyList <float, double>(floatRows, v => v);
                }
                else
                {
                    throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{typeof(T)}\" can't be converted to the ClickHouse type \"{ComplexTypeName}\".");
                }
            }

            return(new Float64Writer(columnName, ComplexTypeName, doubleRows));
        }
コード例 #10
0
        public override IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            if (typeof(T) == typeof(string))
            {
                return(new StringColumnWriter(columnName, ComplexTypeName, (IReadOnlyList <string>)rows, columnSettings?.StringEncoding ?? Encoding.UTF8));
            }

            if (typeof(T) == typeof(char[]))
            {
                var mappedList = MappedReadOnlyList <char[]?, ReadOnlyMemory <char> > .Map((IReadOnlyList <char[]?>) rows, m => m.AsMemory());

                return(new StringSpanColumnWriter(columnName, ComplexTypeName, mappedList, columnSettings?.StringEncoding ?? Encoding.UTF8));
            }

            if (typeof(T) == typeof(ReadOnlyMemory <char>))
            {
                return(new StringSpanColumnWriter(columnName, ComplexTypeName, (IReadOnlyList <ReadOnlyMemory <char> >)rows, columnSettings?.StringEncoding ?? Encoding.UTF8));
            }

            if (typeof(T) == typeof(Memory <char>))
            {
                var mappedList = MappedReadOnlyList <Memory <char>, ReadOnlyMemory <char> > .Map((IReadOnlyList <Memory <char> >) rows, m => m);

                return(new StringSpanColumnWriter(columnName, ComplexTypeName, mappedList, columnSettings?.StringEncoding ?? Encoding.UTF8));
            }

            if (typeof(T) == typeof(byte[]))
            {
                return(new BinaryStringColumnWriter(columnName, ComplexTypeName, (IReadOnlyList <byte[]>)rows));
            }

            if (typeof(T) == typeof(ReadOnlyMemory <byte>))
            {
                return(new BinaryStringSpanColumnWriter(columnName, ComplexTypeName, (IReadOnlyList <ReadOnlyMemory <byte> >)rows));
            }

            if (typeof(T) == typeof(Memory <byte>))
            {
                var mappedList = MappedReadOnlyList <Memory <byte>, ReadOnlyMemory <byte> > .Map((IReadOnlyList <Memory <byte> >) rows, m => m);

                return(new BinaryStringSpanColumnWriter(columnName, ComplexTypeName, mappedList));
            }

            throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{typeof(T)}\" can't be converted to the ClickHouse type \"{ComplexTypeName}\".");
        }
コード例 #11
0
        public IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            if (_enumMap == null)
            {
                throw new ClickHouseException(ClickHouseErrorCodes.TypeNotFullySpecified, "The list of items is not specified.");
            }

            if (typeof(T) == typeof(string))
            {
                var list = MappedReadOnlyList <string, TValue> .Map(
                    (IReadOnlyList <string>) rows,
                    key => _enumMap.TryGetValue(key, out var value)?value : throw new InvalidCastException($"The value \"{key}\" can't be converted to {ComplexTypeName}."));

                return(CreateInternalColumnWriter(columnName, list));
            }

            return(CreateInternalColumnWriter(columnName, rows));
        }
コード例 #12
0
        public override IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            IReadOnlyList <byte> byteRows;

            if (typeof(T) == typeof(byte))
            {
                byteRows = (IReadOnlyList <byte>)rows;
            }
            else if (typeof(T) == typeof(bool))
            {
                byteRows = MappedReadOnlyList <bool, byte> .Map((IReadOnlyList <bool>) rows, v => v?(byte)1 : (byte)0);
            }
            else
            {
                throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{typeof(T)}\" can't be converted to the ClickHouse type \"{ComplexTypeName}\".");
            }

            return(new UInt8Writer(columnName, ComplexTypeName, byteRows));
        }
コード例 #13
0
        public override IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            var type = typeof(T);
            IReadOnlyList <IPAddress?> preparedRows;

            if (typeof(IPAddress).IsAssignableFrom(type))
            {
                preparedRows = (IReadOnlyList <IPAddress?>)rows;
            }
            else if (type == typeof(string))
            {
                preparedRows = MappedReadOnlyList <string?, IPAddress?> .Map((IReadOnlyList <string?>) rows, ParseIpAddress);
            }
            else
            {
                throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{type}\" can't be converted to the ClickHouse type \"{ComplexTypeName}\".");
            }

            return(new IpV6Writer(columnName, TypeName, preparedRows));
        }
コード例 #14
0
        public override IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            IReadOnlyList <IPAddress?> preparedRows;

            switch (rows)
            {
            case IReadOnlyList <IPAddress?> ipAddressRows:
                preparedRows = ipAddressRows;
                break;

            case IReadOnlyList <string?> stringRows:
                preparedRows = new MappedReadOnlyList <string?, IPAddress?>(stringRows, ParseIpAddress);
                break;

            default:
                throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{typeof(T)}\" can't be converted to the ClickHouse type \"{ComplexTypeName}\".");
            }

            return(new IpV6Writer(columnName, TypeName, preparedRows));
        }
コード例 #15
0
        protected override IClickHouseColumnWriter CreateInternalColumnWriter <T>(string columnName, IReadOnlyList <T> rows)
        {
            if (!(rows is IReadOnlyList <short> shortRows))
            {
                if (rows is IReadOnlyList <byte> byteRows)
                {
                    shortRows = new MappedReadOnlyList <byte, short>(byteRows, v => v);
                }
                else if (rows is IReadOnlyList <sbyte> sbyteRows)
                {
                    shortRows = new MappedReadOnlyList <sbyte, short>(sbyteRows, v => v);
                }
                else
                {
                    throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{typeof(T)}\" can't be converted to the ClickHouse type \"{TypeName}\".");
                }
            }

            return(new Int16TypeInfo.Int16Writer(columnName, ComplexTypeName, shortRows));
        }
コード例 #16
0
        public IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            if (!(rows is IReadOnlyList <byte[]> byteRows))
            {
                if (rows is IReadOnlyList <string?> stringRows)
                {
                    var columnEncoding = columnSettings?.StringEncoding ?? Encoding.UTF8;
                    byteRows = new MappedReadOnlyList <string?, byte[]>(stringRows, str => str == null ? new byte[0] : columnEncoding.GetBytes(str));
                }
                else
                {
                    throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{typeof(T)}\" can't be converted to the ClickHouse type \"{ComplexTypeName}\".");
                }
            }

            if (_length == null)
            {
                throw new ClickHouseException(ClickHouseErrorCodes.TypeNotFullySpecified, "The length of the fixed string is not specified.");
            }

            return(new FixedStringWriter(columnName, ComplexTypeName, byteRows, _length.Value));
        }
コード例 #17
0
        protected override IClickHouseColumnWriter CreateInternalColumnWriter <T>(string columnName, IReadOnlyList <T> rows)
        {
            var type = typeof(T);
            IReadOnlyList <short> shortRows;

            if (type == typeof(short))
            {
                shortRows = (IReadOnlyList <short>)rows;
            }
            else if (type == typeof(byte))
            {
                shortRows = MappedReadOnlyList <byte, short> .Map((IReadOnlyList <byte>) rows, v => v);
            }
            else if (type == typeof(sbyte))
            {
                shortRows = MappedReadOnlyList <sbyte, short> .Map((IReadOnlyList <sbyte>) rows, v => v);
            }
            else
            {
                throw new ClickHouseException(ClickHouseErrorCodes.TypeNotSupported, $"The type \"{type}\" can't be converted to the ClickHouse type \"{TypeName}\".");
            }

            return(new Int16TypeInfo.Int16Writer(columnName, ComplexTypeName, shortRows));
        }
コード例 #18
0
 public FixedStringStringColumnWriter(string columnName, string columnType, IReadOnlyList <string?> rows, int length, Encoding?stringEncoding)
     : this(columnName, columnType, MappedReadOnlyList <string?, ReadOnlyMemory <char> > .Map(rows, str => str.AsMemory()), length, stringEncoding)
 {
 }
コード例 #19
0
 public FixedStringBytesColumnWriter(string columnName, string columnType, IReadOnlyList <byte[]?> rows, int length)
     : this(columnName, columnType, MappedReadOnlyList <byte[]?, ReadOnlyMemory <byte> > .Map(rows, b => b.AsMemory()), length)
 {
 }
コード例 #20
0
 public FixedStringBytesColumnWriter(string columnName, string columnType, IReadOnlyList <Memory <byte> > rows, int length)
     : this(columnName, columnType, MappedReadOnlyList <Memory <byte>, ReadOnlyMemory <byte> > .Map(rows, m => m), length)
 {
 }