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

Giorgi / DuckDB.NET / 40296324877

26 Oct 2026 09:00AM UTC coverage: 92.811% (+0.3%) from 92.531%
40296324877

push

github

Giorgi
Test the allocator grouping on whichever option the running DuckDB has

DuckDB's main branch replaced the block_allocator_memory setting with
enable_block_allocator (duckdb/duckdb#27520), so the nightly build failed to
find it. The grouping rule covers both, as both names have an allocator and a
block segment. The test now takes whichever option the running DuckDB has, so
it runs against DuckDB 2.0 and against the nightly builds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F9b3CGWkCMzmhoxge1QiZ8

2599 of 2865 branches covered (90.72%)

Branch coverage included in aggregate %.

4205 of 4466 relevant lines covered (94.16%)

1056578.13 hits per line

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

97.96
/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 Dictionary<Type, DuckDBType> ClrToDuckDBTypeMap = new()
3 ✔
9
    {
3 ✔
10
        { typeof(bool), DuckDBType.Boolean },
3 ✔
11
        { typeof(sbyte), DuckDBType.TinyInt },
3 ✔
12
        { typeof(short), DuckDBType.SmallInt },
3 ✔
13
        { typeof(int), DuckDBType.Integer },
3 ✔
14
        { typeof(long), DuckDBType.BigInt },
3 ✔
15
        { typeof(byte), DuckDBType.UnsignedTinyInt },
3 ✔
16
        { typeof(ushort), DuckDBType.UnsignedSmallInt },
3 ✔
17
        { typeof(uint), DuckDBType.UnsignedInteger },
3 ✔
18
        { typeof(ulong), DuckDBType.UnsignedBigInt },
3 ✔
19
        { typeof(float), DuckDBType.Float },
3 ✔
20
        { typeof(double), DuckDBType.Double},
3 ✔
21
        { typeof(Guid), DuckDBType.Uuid},
3 ✔
22
        { typeof(DateTime), DuckDBType.Timestamp},
3 ✔
23
        { typeof(TimeSpan), DuckDBType.Interval},
3 ✔
24
        { typeof(DateOnly), DuckDBType.Date},
3 ✔
25
        { typeof(TimeOnly), DuckDBType.Time},
3 ✔
26
        { typeof(DuckDBDateOnly), DuckDBType.Date},
3 ✔
27
        { typeof(DuckDBTimeOnly), DuckDBType.Time},
3 ✔
28
        { typeof(DateTimeOffset), DuckDBType.TimestampTz},
3 ✔
29
        { typeof(BigInteger), DuckDBType.HugeInt},
3 ✔
30
        { typeof(string), DuckDBType.Varchar},
3 ✔
31
        { typeof(byte[]), DuckDBType.Blob},
3 ✔
32
        { typeof(decimal), DuckDBType.Decimal},
3 ✔
33
        { typeof(object), DuckDBType.Any},
3 ✔
34
    };
3 ✔
35

36
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
37
    public static bool IsNull([NotNullWhen(false)] this object? value) => value is null or DBNull;
78,533 ✔
38

39
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
40
    public static Type UnderlyingTypeOrSelf(this Type type) => Nullable.GetUnderlyingType(type) ?? type;
3,222 ✔
41

42
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
43
    public static bool IsFloatingNumericType<T>()
44
    {
45
        return typeof(T) == typeof(decimal) || typeof(T) == typeof(float) || typeof(T) == typeof(double);
510,435 ✔
46
    }
47

48
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
49
    public static bool IsIntegralNumericType<T>()
50
    {
51
        return typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte) ||
4,255,527 ✔
52
               typeof(T) == typeof(short) || typeof(T) == typeof(ushort) ||
4,255,527 ✔
53
               typeof(T) == typeof(int) || typeof(T) == typeof(uint) ||
4,255,527 ✔
54
               typeof(T) == typeof(long) || typeof(T) == typeof(ulong) ||
4,255,527 ✔
55
               typeof(T) == typeof(BigInteger);
4,255,527 ✔
56
    }
57

58
    public static bool AllowsNullValue(this Type type, out bool isNullableValueType, out Type? underlyingType)
59
    {
60
        underlyingType = Nullable.GetUnderlyingType(type);
3,112,806 ✔
61
        isNullableValueType = underlyingType != null;
3,112,806 ✔
62

63
        var isNullable = isNullableValueType || !type.IsValueType;
3,112,806 ✔
64

65
        return isNullable;
846,465 ✔
66
    }
67

68
    // The constructed type of genericDefinition (List<>, Dictionary<,>) that the type is or derives from, or null.
69
    public static Type? FindGenericBase(this Type type, Type genericDefinition)
70
    {
71
        for (var current = type; current != null; current = current.BaseType)
6,265,578 ✔
72
        {
73
            if (current.IsGenericType && current.GetGenericTypeDefinition() == genericDefinition)
3,095,820 ✔
74
            {
75
                return current;
2,886,852 ✔
76
            }
77
        }
78

79
        return null;
36,969 ✔
80
    }
81

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

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

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

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

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

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

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

© 2026 Coveralls, Inc