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

Giorgi / DuckDB.NET / 22921736195

10 Mar 2026 07:24PM UTC coverage: 89.526% (+0.08%) from 89.45%
22921736195

push

github

Giorgi
Update global.json

1255 of 1463 branches covered (85.78%)

Branch coverage included in aggregate %.

2651 of 2900 relevant lines covered (91.41%)

447643.55 hits per line

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

96.91
/DuckDB.NET.Data/DataChunk/Reader/ListVectorDataReader.cs
1
namespace DuckDB.NET.Data.DataChunk.Reader;
2

3
internal sealed class ListVectorDataReader : VectorDataReaderBase
4
{
5
    private readonly ulong arraySize;
6
    private readonly VectorDataReaderBase listDataReader;
7

8
    public bool IsList => DuckDBType == DuckDBType.List;
13,836✔
9

10
    internal unsafe ListVectorDataReader(IntPtr vector, void* dataPointer, ulong* validityMaskPointer, DuckDBType columnType, DuckDBLogicalType logicalColumnType, string columnName) 
11
                    : base(dataPointer, validityMaskPointer, columnType, columnName)
4,494✔
12
    {
13
        using var childType = IsList ? NativeMethods.LogicalType.DuckDBListTypeChildType(logicalColumnType) : NativeMethods.LogicalType.DuckDBArrayTypeChildType(logicalColumnType);
4,494✔
14

15
        var childVector = IsList ? NativeMethods.Vectors.DuckDBListVectorGetChild(vector) : NativeMethods.Vectors.DuckDBArrayVectorGetChild(vector);
4,494✔
16

17
        arraySize = IsList ? 0 : (ulong)NativeMethods.LogicalType.DuckDBArrayVectorGetSize(logicalColumnType);
4,494✔
18
        listDataReader = VectorDataReaderFactory.CreateReader(childVector, childType, columnName);
4,494✔
19
    }
8,988✔
20

21
    protected override Type GetColumnType()
22
    {
23
        return typeof(List<>).MakeGenericType(listDataReader.ClrType);
30✔
24
    }
25

26
    protected override Type GetColumnProviderSpecificType()
27
    {
28
        return typeof(List<>).MakeGenericType(listDataReader.ProviderSpecificClrType);
18✔
29
    }
30

31
    internal override unsafe object GetValue(ulong offset, Type targetType)
32
    {
33
        switch (DuckDBType)
1,041,849!
34
        {
35
            case DuckDBType.List:
36
                {
37
                    var listData = (DuckDBListEntry*)DataPointer + offset;
1,035,687✔
38

39
                    return GetList(targetType, listData->Offset, listData->Length);
1,035,687✔
40
                }
41
            case DuckDBType.Array:
42
                return GetList(targetType, offset * arraySize, arraySize);
6,162✔
43
            default:
44
                return base.GetValue(offset, targetType);
×
45
        }
46
    }
47

48
    private object GetList(Type returnType, ulong listOffset, ulong length)
49
    {
50
        var listType = returnType.GetGenericArguments()[0];
1,041,849✔
51

52
        var allowNulls = listType.AllowsNullValue(out _, out var nullableType);
1,041,849✔
53

54
        var list = Activator.CreateInstance(returnType) as IList
1,041,849!
55
                   ?? throw new ArgumentException($"The type '{returnType.Name}' specified in parameter {nameof(returnType)} cannot be instantiated as an IList.");
1,041,849✔
56

57
        //Special case for specific types to avoid boxing
58
        return list switch
1,041,849✔
59
        {
1,041,849✔
60
            List<int> theList => BuildList(theList),
44,094✔
61
            List<int?> theList => BuildList(theList),
21,910✔
62
            List<float> theList => BuildList(theList),
21,823✔
63
            List<float?> theList => BuildList(theList),
21,746✔
64
            List<double> theList => BuildList(theList),
22,139✔
65
            List<double?> theList => BuildList(theList),
21,941✔
66
            List<decimal> theList => BuildList(theList),
51,841✔
67
            List<decimal?> theList => BuildList(theList),
22,064✔
68
            _ => BuildListCommon(list, nullableType ?? listType)
814,291✔
69
        };
1,041,849✔
70

71
        List<T> BuildList<T>(List<T> result)
72
        {
73
            for (ulong i = 0; i < length; i++)
12,944,726✔
74
            {
75
                var childOffset = listOffset + i;
6,244,811✔
76
                if (listDataReader.IsValid(childOffset))
6,244,811✔
77
                {
78
                    var item = listDataReader.GetValueStrict<T>(childOffset);
4,742,638✔
79
                    result.Add(item);
4,742,635✔
80
                }
81
                else
82
                {
83
                    result.Add(allowNulls ? default! : throw new InvalidCastException("The list contains null value"));
1,502,173✔
84
                }
85
            }
86
            return result;
227,552✔
87
        }
88

89
        IList BuildListCommon(IList result, Type targetType)
90
        {
91
            for (ulong i = 0; i < length; i++)
40,354,492✔
92
            {
93
                var childOffset = listOffset + i;
19,362,973✔
94
                if (listDataReader.IsValid(childOffset))
19,362,973✔
95
                {
96
                    var item = listDataReader.GetValue(childOffset, targetType);
15,631,080✔
97
                    result.Add(item);
15,631,065✔
98
                }
99
                else
100
                {
101
                    result.Add(allowNulls ? null : throw new InvalidCastException("The list contains null value"));
3,731,893✔
102
                }
103
            }
104
            return result;
814,273✔
105
        }
106
    }
107

108
    internal override void Reset(IntPtr vector)
109
    {
110
        base.Reset(vector);
354✔
111
        var childVector = IsList
354✔
112
            ? NativeMethods.Vectors.DuckDBListVectorGetChild(vector)
354✔
113
            : NativeMethods.Vectors.DuckDBArrayVectorGetChild(vector);
354✔
114
        listDataReader.Reset(childVector);
354✔
115
    }
354✔
116

117
    public override void Dispose()
118
    {
119
        listDataReader.Dispose();
360✔
120
        base.Dispose();
360✔
121
    }
360✔
122
}
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