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

Giorgi / DuckDB.NET / 22323392380

23 Feb 2026 07:25PM UTC coverage: 89.658% (-0.008%) from 89.666%
22323392380

push

github

Giorgi
Throw on invalid enum internal type instead of returning -1

1237 of 1437 branches covered (86.08%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

6 existing lines in 2 files now uncovered.

2543 of 2779 relevant lines covered (91.51%)

471972.16 hits per line

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

86.21
/DuckDB.NET.Data/DataChunk/Reader/EnumVectorDataReader.cs
1
using System.Runtime.CompilerServices;
2

3
namespace DuckDB.NET.Data.DataChunk.Reader;
4

5
internal sealed class EnumVectorDataReader : VectorDataReaderBase
6
{
7
    private readonly DuckDBType enumType;
8
    private readonly DuckDBLogicalType logicalType;
9
    private readonly Dictionary<long, string> cachedNames = new(8);
534✔
10

11
    internal unsafe EnumVectorDataReader(IntPtr vector, void* dataPointer, ulong* validityMaskPointer, DuckDBType columnType, string columnName) : base(dataPointer, validityMaskPointer, columnType, columnName)
534✔
12
    {
13
        logicalType = NativeMethods.Vectors.DuckDBVectorGetColumnType(vector);
534✔
14
        enumType = NativeMethods.LogicalType.DuckDBEnumInternalType(logicalType);
534✔
15
    }
534✔
16

17
    protected override T GetValidValue<T>(ulong offset, Type targetType)
18
    {
19
        if (DuckDBType != DuckDBType.Enum)
36!
20
        {
21
            return base.GetValidValue<T>(offset, targetType);
×
22
        }
23

24
        switch (enumType)
36!
25
        {
26
            case DuckDBType.UnsignedTinyInt:
27
            {
28
                var enumValue = GetFieldData<byte>(offset);
24✔
29
                return ToEnumOrString(enumValue);
24✔
30
            }
31
            case DuckDBType.UnsignedSmallInt:
32
            {
33
                var enumValue = GetFieldData<ushort>(offset);
6✔
34
                return ToEnumOrString(enumValue);
6✔
35
            }
36
            case DuckDBType.UnsignedInteger:
37
            {
38
                var enumValue = GetFieldData<uint>(offset);
6✔
39
                return ToEnumOrString(enumValue);
6✔
40
            }
41
            default:
42
                throw new DuckDBException($"Invalid type {DuckDBType} ({(int)DuckDBType}) for column {ColumnName}");
×
43
        }
44

45
        T ToEnumOrString<TSource>(TSource enumValue) where TSource: IBinaryNumber<TSource>
46
        {
47
            if (typeof(T) == typeof(string))
36✔
48
            {
49
                var index = long.CreateChecked(enumValue);
24✔
50
                if (!cachedNames.TryGetValue(index, out var name))
24✔
51
                {
52
                    cachedNames[index] = name = NativeMethods.LogicalType.DuckDBEnumDictionaryValue(logicalType, index);
3✔
53
                }
54

55
                return (T)(object)name;
24✔
56
            }
57
            return Unsafe.As<TSource, T>(ref enumValue);
12✔
58
        }
59
    }
60

61
    internal override object GetValue(ulong offset, Type targetType)
62
    {
63
        if (DuckDBType == DuckDBType.Enum)
1,127,304!
64
        {
65
            long enumValue = enumType switch
1,127,304!
66
            {
1,127,304✔
67
                DuckDBType.UnsignedTinyInt => GetFieldData<byte>(offset),
1,127,280✔
68
                DuckDBType.UnsignedSmallInt => GetFieldData<ushort>(offset),
12✔
69
                DuckDBType.UnsignedInteger => GetFieldData<uint>(offset),
12✔
NEW
70
                _ => throw new DuckDBException($"Invalid type {DuckDBType} ({(int)DuckDBType}) for column {ColumnName}")
×
71
            };
1,127,304✔
72

73
            if (targetType == typeof(string))
1,127,304✔
74
            {
75
                if (!cachedNames.TryGetValue(enumValue, out var name))
566,162✔
76
                {
77
                    cachedNames[enumValue] = name = NativeMethods.LogicalType.DuckDBEnumDictionaryValue(logicalType, enumValue);
66✔
78
                }
79

80
                return name;
566,162✔
81
            }
82

83
            return Enum.ToObject(targetType, enumValue);
561,142✔
84
        }
85

86
        return base.GetValue(offset, targetType);
×
87
    }
88

89
    public override void Dispose()
90
    {
91
        logicalType.Dispose();
45✔
92
        base.Dispose();
45✔
93
    }
45✔
94
}
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