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));
        }
        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));
        }
            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));
            }
        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));
        }
Beispiel #5
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}\".");
        }
        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));
        }
        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));
        }
Beispiel #8
0
        public override IClickHouseColumnWriter CreateColumnWriter <T>(string columnName, IReadOnlyList <T> rows, ClickHouseColumnSettings?columnSettings)
        {
            IReadOnlyList <double> doubleRows;

            if (typeof(T) == typeof(double))
            {
                doubleRows = (IReadOnlyList <double>)rows;
            }
            else if (typeof(T) == typeof(float))
            {
                doubleRows = MappedReadOnlyList <float, double> .Map((IReadOnlyList <float>) rows, 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));
        }
Beispiel #9
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));
        }
        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));
        }
Beispiel #11
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)
 {
 }
Beispiel #12
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)
 {
 }
Beispiel #13
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)
 {
 }
        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}\".");
            }

            var type = typeof(T);
            IReadOnlyList <decimal> decimalRows;

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

            return(new DecimalWriter(columnName, ComplexTypeName, _precision.Value, _scale.Value, decimalRows));
        }