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

Giorgi / DuckDB.NET / 21786556530

07 Feb 2026 08:39PM UTC coverage: 89.155% (-0.07%) from 89.223%
21786556530

push

github

Giorgi
Added support for clearing in-progress adapter

Requires DuckDB 1.5

1199 of 1393 branches covered (86.07%)

Branch coverage included in aggregate %.

6 of 8 new or added lines in 1 file covered. (75.0%)

193 existing lines in 43 files now uncovered.

2336 of 2572 relevant lines covered (90.82%)

557295.56 hits per line

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

76.12
/DuckDB.NET.Data/DataChunk/Writer/EnumVectorDataWriter.cs
1
namespace DuckDB.NET.Data.DataChunk.Writer;
2

3
internal sealed unsafe class EnumVectorDataWriter(IntPtr vector, void* vectorData, DuckDBLogicalType logicalType, DuckDBType columnType) : VectorDataWriterBase(vector, vectorData, columnType)
45✔
4
{
5
    private readonly DuckDBType enumType = NativeMethods.LogicalType.DuckDBEnumInternalType(logicalType);
45✔
6

7
    private readonly uint enumDictionarySize = NativeMethods.LogicalType.DuckDBEnumDictionarySize(logicalType);
45✔
8

9
    private readonly Dictionary<string, uint> enumValues = [];
45✔
10

11
    internal override bool AppendString(string value, ulong rowIndex)
12
    {
13
        if (enumValues.Count == 0)
559,897✔
14
        {
15
            for (uint index = 0; index < enumDictionarySize; index++)
606,690✔
16
            {
17
                var enumValueName = NativeMethods.LogicalType.DuckDBEnumDictionaryValue(logicalType, index).ToManagedString();
303,327✔
18
                enumValues.Add(enumValueName, index);
303,327✔
19
            }
20
        }
21

22
        if (enumValues.TryGetValue(value, out var enumValue))
559,897✔
23
        {
24
            // The following casts to byte and ushort are safe because we ensure in the constructor that the value enumDictionarySize is not too high.
25
            return enumType switch
559,894!
26
            {
559,894✔
27
                DuckDBType.UnsignedTinyInt => AppendValueInternal((byte)enumValue, rowIndex),
559,888✔
28
                DuckDBType.UnsignedSmallInt => AppendValueInternal((ushort)enumValue, rowIndex),
3✔
29
                DuckDBType.UnsignedInteger => AppendValueInternal(enumValue, rowIndex),
3✔
UNCOV
30
                _ => throw new InvalidOperationException($"Failed to write Enum column because the internal enum type must be utinyint, usmallint, or uinteger."),
×
31
            };
559,894✔
32
        }
33

34
        throw new InvalidOperationException($"Failed to write Enum column because the value \"{value}\" is not valid.");
3✔
35
    }
36

37
    internal override bool AppendEnum<TEnum>(TEnum value, ulong rowIndex)
38
    {
39
        var enumValue = ConvertEnumValueToUInt64(value);
564,407✔
40
        if (enumValue < enumDictionarySize)
564,407✔
41
        {
42
            // The following casts to byte, ushort and uint are safe because we ensure in the constructor that the value enumDictionarySize is not too high.
43
            return enumType switch
564,404!
44
            {
564,404✔
45
                DuckDBType.UnsignedTinyInt => AppendValueInternal((byte)enumValue, rowIndex),
564,398✔
46
                DuckDBType.UnsignedSmallInt => AppendValueInternal((ushort)enumValue, rowIndex),
3✔
47
                DuckDBType.UnsignedInteger => AppendValueInternal((uint)enumValue, rowIndex),
3✔
UNCOV
48
                _ => throw new InvalidOperationException($"Failed to write Enum column because the internal enum type must be utinyint, usmallint, or uinteger."),
×
49
            };
564,404✔
50
        }
51

52
        throw new InvalidOperationException($"Failed to write Enum column because the value is outside the range (0-{enumDictionarySize - 1}).");
3✔
53
    }
54

55
    private static ulong ConvertEnumValueToUInt64<TEnum>(TEnum value) where TEnum : Enum
56
    {
57
        return value.GetTypeCode() switch
564,407!
58
        {
564,407✔
UNCOV
59
            TypeCode.SByte => (ulong)Convert.ToSByte(value),
×
UNCOV
60
            TypeCode.Byte => Convert.ToByte(value),
×
61
            TypeCode.Int16 => (ulong)Convert.ToInt16(value),
3✔
UNCOV
62
            TypeCode.UInt16 => Convert.ToUInt16(value),
×
63
            TypeCode.Int32 => (ulong)Convert.ToInt32(value),
564,401✔
64
            TypeCode.UInt32 => Convert.ToUInt32(value),
×
UNCOV
65
            TypeCode.Int64 => (ulong)Convert.ToInt64(value),
×
66
            TypeCode.UInt64 => Convert.ToUInt64(value),
3✔
UNCOV
67
            _ => throw new InvalidOperationException($"Failed to convert the enum value {value} to ulong."),
×
68
        };
564,407✔
69
    }
70

71
    public override void Dispose()
72
    {
73
        logicalType.Dispose();
45✔
74
        base.Dispose();
45✔
75
    }
45✔
76
}
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