• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Giorgi / DuckDB.NET / 28102732334

24 Jun 2026 01:39PM UTC coverage: 89.358% (-0.1%) from 89.474%
28102732334

Pull #334

github

web-flow
Merge 0037674ea into 38ddceb66
Pull Request #334: Add Apache Arrow result streaming to DuckDBCommand

1359 of 1583 branches covered (85.85%)

Branch coverage included in aggregate %.

84 of 94 new or added lines in 4 files covered. (89.36%)

6 existing lines in 2 files now uncovered.

2856 of 3134 relevant lines covered (91.13%)

421088.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.0
/DuckDB.NET.Data/Extensions/TypeExtensions.cs
1
using System.Diagnostics.CodeAnalysis;
2
using System.Runtime.CompilerServices;
3

4
namespace DuckDB.NET.Data.Extensions;
5

6
internal static class TypeExtensions
7
{
8
    private static readonly HashSet<Type> FloatingNumericTypes = [typeof(decimal), typeof(float), typeof(double)];
3✔
9

10
    private static readonly HashSet<Type> IntegralNumericTypes =
3✔
11
    [
3✔
12
        typeof(byte), typeof(sbyte),
3✔
13
        typeof(short), typeof(ushort),
3✔
14
        typeof(int), typeof(uint),
3✔
15
        typeof(long), typeof(ulong),
3✔
16
        typeof(BigInteger)
3✔
17
    ];
3✔
18

19
    private static readonly Dictionary<Type, DuckDBType> ClrToDuckDBTypeMap = new()
3✔
20
    {
3✔
21
        { typeof(bool), DuckDBType.Boolean },
3✔
22
        { typeof(sbyte), DuckDBType.TinyInt },
3✔
23
        { typeof(short), DuckDBType.SmallInt },
3✔
24
        { typeof(int), DuckDBType.Integer },
3✔
25
        { typeof(long), DuckDBType.BigInt },
3✔
26
        { typeof(byte), DuckDBType.UnsignedTinyInt },
3✔
27
        { typeof(ushort), DuckDBType.UnsignedSmallInt },
3✔
28
        { typeof(uint), DuckDBType.UnsignedInteger },
3✔
29
        { typeof(ulong), DuckDBType.UnsignedBigInt },
3✔
30
        { typeof(float), DuckDBType.Float },
3✔
31
        { typeof(double), DuckDBType.Double},
3✔
32
        { typeof(Guid), DuckDBType.Uuid},
3✔
33
        { typeof(DateTime), DuckDBType.Timestamp},
3✔
34
        { typeof(TimeSpan), DuckDBType.Interval},
3✔
35
        { typeof(DateOnly), DuckDBType.Date},
3✔
36
        { typeof(TimeOnly), DuckDBType.Time},
3✔
37
        { typeof(DateTimeOffset), DuckDBType.TimestampTz},
3✔
38
        { typeof(BigInteger), DuckDBType.HugeInt},
3✔
39
        { typeof(string), DuckDBType.Varchar},
3✔
40
        { typeof(byte[]), DuckDBType.Blob},
3✔
41
        { typeof(decimal), DuckDBType.Decimal},
3✔
42
        { typeof(object), DuckDBType.Any},
3✔
43
    };
3✔
44

45
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
46
    public static bool IsNull([NotNullWhen(false)] this object? value) => value is null or DBNull;
12,483✔
47

48
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
49
    public static Type UnderlyingTypeOrSelf(this Type type) => Nullable.GetUnderlyingType(type) ?? type;
1,446✔
50

51
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
52
    public static bool IsFloatingNumericType<T>()
53
    {
54
        return typeof(T) == typeof(decimal) || typeof(T) == typeof(float) || typeof(T) == typeof(double);
4,039,452✔
55
    }
56

57
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
58
    public static bool IsIntegralNumericType<T>()
59
    {
60
        return typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte) ||
4,039,452✔
61
               typeof(T) == typeof(short) || typeof(T) == typeof(ushort) ||
4,039,452✔
62
               typeof(T) == typeof(int) || typeof(T) == typeof(uint) ||
4,039,452✔
63
               typeof(T) == typeof(long) || typeof(T) == typeof(ulong) ||
4,039,452✔
64
               typeof(T) == typeof(BigInteger);
4,039,452✔
65
    }
66

67
    public static bool IsNumeric(this Type type)
68
    {
69
        return IntegralNumericTypes.Contains(type) || FloatingNumericTypes.Contains(type);
9,609,273✔
70
    }
71

72
    public static bool AllowsNullValue(this Type type, out bool isNullableValueType, out Type? underlyingType)
73
    {
74
        underlyingType = Nullable.GetUnderlyingType(type);
1,042,244✔
75
        isNullableValueType = underlyingType != null;
1,042,244✔
76

77
        var isNullable = isNullableValueType || !type.IsValueType;
1,042,244✔
78

79
        return isNullable;
308,129✔
80
    }
81

82
    public static DuckDBLogicalType GetLogicalType<T>() => typeof(T).GetLogicalType();
246✔
83

84
    public static DuckDBLogicalType GetLogicalType(this Type type)
85
    {
86
        type = type.UnderlyingTypeOrSelf();
1,413✔
87

88
        if (type == typeof(decimal))
1,413✔
89
        {
90
            return NativeMethods.LogicalType.DuckDBCreateDecimalType(38, 18);
93✔
91
        }
92

93
        if (type.IsAssignableTo(typeof(IList)) && type.IsGenericType)
1,320✔
94
        {
95
            var genericTypeParameter = type.GetGenericArguments()[0];
42✔
96
            using var nestedType = genericTypeParameter.GetLogicalType();
42✔
97
            return NativeMethods.LogicalType.DuckDBCreateListType(nestedType);
42✔
98
        }
99

100
        if (ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType))
1,278!
101
        {
102
            return NativeMethods.LogicalType.DuckDBCreateLogicalType(duckDBType);
1,278✔
103
        }
104

UNCOV
105
        throw new InvalidOperationException($"Cannot map type {type.FullName} to DuckDBType.");
×
106
    }
42✔
107

108
    public static DuckDBType GetDuckDBType(this Type type) => ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType) ? duckDBType : DuckDBType.Invalid;
33!
109
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc