Exemplo n.º 1
0
        private static void ConvertByteArray(ReadOnlySpan <byte[]> source, Span <short> defLevels, Span <ByteArray> destination, short nullLevel, ByteBuffer byteBuffer)
        {
            for (int i = 0, dst = 0; i != source.Length; ++i)
            {
                var value = source[i];
                if (value == null)
                {
                    if (defLevels == null)
                    {
                        throw new ArgumentException("encountered null value despite column schema node repetition being marked as required");
                    }

                    defLevels[i] = nullLevel;
                }
                else
                {
                    destination[dst++] = LogicalWrite.FromByteArray(value, byteBuffer);
                    defLevels[i]       = (short)(nullLevel + 1);
                }
            }
        }
Exemplo n.º 2
0
 private static void ConvertUuid(ReadOnlySpan <Guid?> source, Span <short> defLevels, Span <FixedLenByteArray> destination, short nullLevel, ByteBuffer byteBuffer)
 {
     for (int i = 0, dst = 0; i != source.Length; ++i)
     {
         var value = source[i];
         if (value == null)
         {
             defLevels[i] = nullLevel;
         }
         else
         {
             destination[dst++] = LogicalWrite.FromUuid(value.Value, byteBuffer);
             defLevels[i]       = (short)(nullLevel + 1);
         }
     }
 }
Exemplo n.º 3
0
 private static void ConvertDecimal128(ReadOnlySpan <decimal> source, Span <FixedLenByteArray> destination, decimal multiplier, ByteBuffer byteBuffer)
 {
     for (int i = 0; i != source.Length; ++i)
     {
         destination[i] = LogicalWrite.FromDecimal(source[i], multiplier, byteBuffer);
     }
 }
Exemplo n.º 4
0
 private static void ConvertUuid(ReadOnlySpan <Guid> source, Span <FixedLenByteArray> destination, ByteBuffer byteBuffer)
 {
     for (int i = 0; i != source.Length; ++i)
     {
         destination[i] = LogicalWrite.FromUuid(source[i], byteBuffer);
     }
 }
Exemplo n.º 5
0
        public static Converter GetConverter(LogicalType logicalType, int scale, ByteBuffer byteBuffer)
        {
            if (typeof(TLogical) == typeof(bool) ||
                typeof(TLogical) == typeof(int) ||
                typeof(TLogical) == typeof(long) ||
                typeof(TLogical) == typeof(Int96) ||
                typeof(TLogical) == typeof(float) ||
                typeof(TLogical) == typeof(double))
            {
                return((Converter)(Delegate)(LogicalWrite <TPhysical, TPhysical> .Converter)((s, dl, d, nl) => ConvertNative(s, d)));
            }

            if (typeof(TLogical) == typeof(bool?) ||
                typeof(TLogical) == typeof(int?) ||
                typeof(TLogical) == typeof(long?) ||
                typeof(TLogical) == typeof(Int96?) ||
                typeof(TLogical) == typeof(float?) ||
                typeof(TLogical) == typeof(double?))
            {
                return((Converter)(Delegate)(LogicalWrite <TPhysical?, TPhysical> .Converter)ConvertNative);
            }

            if (typeof(TLogical) == typeof(sbyte))
            {
                return((Converter)(Delegate)(LogicalWrite <sbyte, int> .Converter)((s, dl, d, nl) => ConvertInt8(s, d)));
            }

            if (typeof(TLogical) == typeof(sbyte?))
            {
                return((Converter)(Delegate)(LogicalWrite <sbyte?, int> .Converter)ConvertInt8);
            }

            if (typeof(TLogical) == typeof(byte))
            {
                return((Converter)(Delegate)(LogicalWrite <byte, int> .Converter)((s, dl, d, nl) => ConvertUInt8(s, d)));
            }

            if (typeof(TLogical) == typeof(byte?))
            {
                return((Converter)(Delegate)(LogicalWrite <byte?, int> .Converter)ConvertUInt8);
            }

            if (typeof(TLogical) == typeof(short))
            {
                return((Converter)(Delegate)(LogicalWrite <short, int> .Converter)((s, dl, d, nl) => ConvertInt16(s, d)));
            }

            if (typeof(TLogical) == typeof(short?))
            {
                return((Converter)(Delegate)(LogicalWrite <short?, int> .Converter)ConvertInt16);
            }

            if (typeof(TLogical) == typeof(ushort))
            {
                return((Converter)(Delegate)(LogicalWrite <ushort, int> .Converter)((s, dl, d, nl) => ConvertUInt16(s, d)));
            }

            if (typeof(TLogical) == typeof(ushort?))
            {
                return((Converter)(Delegate)(LogicalWrite <ushort?, int> .Converter)ConvertUInt16);
            }

            if (typeof(TLogical) == typeof(uint))
            {
                return((Converter)(Delegate)(LogicalWrite <uint, int> .Converter)((s, dl, d, nl) => ConvertNative(s, MemoryMarshal.Cast <int, uint>(d))));
            }

            if (typeof(TLogical) == typeof(uint?))
            {
                return((Converter)(Delegate)(LogicalWrite <uint?, int> .Converter)((s, dl, d, nl) => ConvertNative(s, dl, MemoryMarshal.Cast <int, uint>(d), nl)));
            }

            if (typeof(TLogical) == typeof(ulong))
            {
                return((Converter)(Delegate)(LogicalWrite <ulong, long> .Converter)((s, dl, d, nl) => ConvertNative(s, MemoryMarshal.Cast <long, ulong>(d))));
            }

            if (typeof(TLogical) == typeof(ulong?))
            {
                return((Converter)(Delegate)(LogicalWrite <ulong?, long> .Converter)((s, dl, d, nl) => ConvertNative(s, dl, MemoryMarshal.Cast <long, ulong>(d), nl)));
            }

            if (typeof(TLogical) == typeof(decimal))
            {
                var multiplier = Decimal128.GetScaleMultiplier(scale);
                return((Converter)(Delegate)(LogicalWrite <decimal, FixedLenByteArray> .Converter)((s, dl, d, nl) => ConvertDecimal128(s, d, multiplier, byteBuffer)));
            }

            if (typeof(TLogical) == typeof(decimal?))
            {
                var multiplier = Decimal128.GetScaleMultiplier(scale);
                return((Converter)(Delegate)(LogicalWrite <decimal?, FixedLenByteArray> .Converter)((s, dl, d, nl) => ConvertDecimal128(s, dl, d, multiplier, nl, byteBuffer)));
            }

            if (typeof(TLogical) == typeof(Guid))
            {
                return((Converter)(Delegate)(LogicalWrite <Guid, FixedLenByteArray> .Converter)((s, dl, d, nl) => ConvertUuid(s, d, byteBuffer)));
            }

            if (typeof(TLogical) == typeof(Guid?))
            {
                return((Converter)(Delegate)(LogicalWrite <Guid?, FixedLenByteArray> .Converter)((s, dl, d, nl) => ConvertUuid(s, dl, d, nl, byteBuffer)));
            }

            if (typeof(TLogical) == typeof(Date))
            {
                return((Converter)(Delegate)(LogicalWrite <Date, int> .Converter)((s, dl, d, nl) => ConvertNative(s, MemoryMarshal.Cast <int, Date>(d))));
            }

            if (typeof(TLogical) == typeof(Date?))
            {
                return((Converter)(Delegate)(LogicalWrite <Date?, int> .Converter)((s, dl, d, nl) => ConvertNative(s, dl, MemoryMarshal.Cast <int, Date>(d), nl)));
            }

            if (typeof(TLogical) == typeof(DateTime))
            {
                switch (((TimestampLogicalType)logicalType).TimeUnit)
                {
                case TimeUnit.Millis:
                    return((Converter)(Delegate)(LogicalWrite <DateTime, long> .Converter)((s, dl, d, nl) => ConvertDateTimeMillis(s, d)));

                case TimeUnit.Micros:
                    return((Converter)(Delegate)(LogicalWrite <DateTime, long> .Converter)((s, dl, d, nl) => ConvertDateTimeMicros(s, d)));
                }
            }

            if (typeof(TLogical) == typeof(DateTimeNanos))
            {
                return((Converter)(Delegate)(LogicalWrite <DateTimeNanos, long> .Converter)((s, dl, d, nl) => ConvertNative(s, MemoryMarshal.Cast <long, DateTimeNanos>(d))));
            }

            if (typeof(TLogical) == typeof(DateTime?))
            {
                switch (((TimestampLogicalType)logicalType).TimeUnit)
                {
                case TimeUnit.Millis:
                    return((Converter)(Delegate)(LogicalWrite <DateTime?, long> .Converter)ConvertDateTimeMillis);

                case TimeUnit.Micros:
                    return((Converter)(Delegate)(LogicalWrite <DateTime?, long> .Converter)ConvertDateTimeMicros);
                }
            }

            if (typeof(TLogical) == typeof(DateTimeNanos?))
            {
                return((Converter)(Delegate)(LogicalWrite <DateTimeNanos?, long> .Converter)((s, dl, d, nl) => ConvertNative(s, dl, MemoryMarshal.Cast <long, DateTimeNanos>(d), nl)));
            }

            if (typeof(TLogical) == typeof(TimeSpan))
            {
                switch (((TimeLogicalType)logicalType).TimeUnit)
                {
                case TimeUnit.Millis:
                    return((Converter)(Delegate)(LogicalWrite <TimeSpan, int> .Converter)((s, dl, d, nl) => ConvertTimeSpanMillis(s, d)));

                case TimeUnit.Micros:
                    return((Converter)(Delegate)(LogicalWrite <TimeSpan, long> .Converter)((s, dl, d, nl) => ConvertTimeSpanMicros(s, d)));
                }
            }

            if (typeof(TLogical) == typeof(TimeSpanNanos))
            {
                return((Converter)(Delegate)(LogicalWrite <TimeSpanNanos, long> .Converter)((s, dl, d, nl) => ConvertNative(s, MemoryMarshal.Cast <long, TimeSpanNanos>(d))));
            }

            if (typeof(TLogical) == typeof(TimeSpan?))
            {
                switch (((TimeLogicalType)logicalType).TimeUnit)
                {
                case TimeUnit.Millis:
                    return((Converter)(Delegate)(LogicalWrite <TimeSpan?, int> .Converter)ConvertTimeSpanMillis);

                case TimeUnit.Micros:
                    return((Converter)(Delegate)(LogicalWrite <TimeSpan?, long> .Converter)ConvertTimeSpanMicros);
                }
            }

            if (typeof(TLogical) == typeof(TimeSpanNanos?))
            {
                return((Converter)(Delegate)(LogicalWrite <TimeSpanNanos?, long> .Converter)((s, dl, d, nl) => ConvertNative(s, dl, MemoryMarshal.Cast <long, TimeSpanNanos>(d), nl)));
            }

            if (typeof(TLogical) == typeof(string))
            {
                return((Converter)(Delegate)(LogicalWrite <string, ByteArray> .Converter)((s, dl, d, nl) => ConvertString(s, dl, d, nl, byteBuffer)));
            }

            if (typeof(TLogical) == typeof(byte[]))
            {
                return((Converter)(Delegate)(LogicalWrite <byte[], ByteArray> .Converter)((s, dl, d, nl) => ConvertByteArray(s, dl, d, nl, byteBuffer)));
            }

            throw new NotSupportedException($"unsupported logical system type {typeof(TLogical)} with logical type {logicalType}");
        }