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

Giorgi / DuckDB.NET / 8331073809

18 Mar 2024 05:34PM UTC coverage: 89.771% (+0.06%) from 89.716%
8331073809

push

github

Giorgi
Update to DuckDB 0.10.1

584 of 680 branches covered (85.88%)

Branch coverage included in aggregate %.

1373 of 1500 relevant lines covered (91.53%)

12610.11 hits per line

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

96.81
/DuckDB.NET.Data/Internal/Reader/ListVectorDataReader.cs
1
using System;
2
using System.Collections;
3
using System.Collections.Generic;
4
using DuckDB.NET.Data.Extensions;
5
using DuckDB.NET.Native;
6

7
namespace DuckDB.NET.Data.Internal.Reader;
8

9
internal class ListVectorDataReader : VectorDataReaderBase
10
{
11
    private readonly ulong arraySize;
12
    private readonly VectorDataReaderBase listDataReader;
13

14
    public bool IsList => DuckDBType == DuckDBType.List;
11,136✔
15

16
    internal unsafe ListVectorDataReader(IntPtr vector, void* dataPointer, ulong* validityMaskPointer, DuckDBType columnType, string columnName) : base(dataPointer, validityMaskPointer, columnType, columnName)
3,712✔
17
    {
18
        using var logicalType = NativeMethods.DataChunks.DuckDBVectorGetColumnType(vector);
3,712✔
19
        using var childType = IsList ? NativeMethods.LogicalType.DuckDBListTypeChildType(logicalType) : NativeMethods.LogicalType.DuckDBArrayTypeChildType(logicalType);
3,712✔
20

21
        var type = NativeMethods.LogicalType.DuckDBGetTypeId(childType);
3,712✔
22

23
        var childVector = IsList ? NativeMethods.DataChunks.DuckDBListVectorGetChild(vector) : NativeMethods.DataChunks.DuckDBArrayVectorGetChild(vector);
3,712✔
24

25
        var childVectorData = NativeMethods.DataChunks.DuckDBVectorGetData(childVector);
3,712✔
26
        var childVectorValidity = NativeMethods.DataChunks.DuckDBVectorGetValidity(childVector);
3,712✔
27

28
        arraySize = IsList ? 0 : (ulong)NativeMethods.DataChunks.DuckDBArrayVectorGetSize(logicalType);
3,712✔
29
        listDataReader = VectorDataReaderFactory.CreateReader(childVector, childVectorData, childVectorValidity, type, columnName);
3,712✔
30
    }
7,424✔
31

32
    protected override Type GetColumnType()
33
    {
34
        return typeof(List<>).MakeGenericType(listDataReader.ClrType);
27✔
35
    }
36

37
    protected override Type GetColumnProviderSpecificType()
38
    {
39
        return typeof(List<>).MakeGenericType(listDataReader.ProviderSpecificClrType);
12✔
40
    }
41

42
    internal override unsafe object GetValue(ulong offset, Type targetType)
43
    {
44
        switch (DuckDBType)
366!
45
        {
46
            case DuckDBType.List:
47
            {
48
                var listData = (DuckDBListEntry*)DataPointer + offset;
270✔
49

50
                return GetList(offset, targetType, listData->Offset, listData->Length);
270✔
51
            }
52
            case DuckDBType.Array:
53
                return GetList(offset, targetType, offset * arraySize, arraySize);
96✔
54
            default:
55
                return base.GetValue(offset, targetType);
×
56
        }
57
    }
58

59
    private unsafe object GetList(ulong offset, Type returnType, ulong listOffset, ulong length)
60
    {
61
        var listType = returnType.GetGenericArguments()[0];
366✔
62

63
        var allowNulls = listType.AllowsNullValue(out var _, out var nullableType);
366✔
64

65
        var list = Activator.CreateInstance(returnType) as IList
366!
66
                   ?? throw new ArgumentException($"The type '{returnType.Name}' specified in parameter {nameof(returnType)} cannot be instantiated as an IList.");
366✔
67

68
        //Special case for specific types to avoid boxing
69
        switch (list)
70
        {
71
            case List<int> theList:
72
                return BuildList<int>(theList);
42✔
73
            case List<int?> theList:
74
                return BuildList<int?>(theList);
96✔
75
            case List<float> theList:
76
                return BuildList<float>(theList);
6✔
77
            case List<float?> theList:
78
                return BuildList<float?>(theList);
3✔
79
            case List<double> theList:
80
                return BuildList<double>(theList);
9✔
81
            case List<double?> theList:
82
                return BuildList<double?>(theList);
6✔
83
            case List<decimal> theList:
84
                return BuildList<decimal>(theList);
9✔
85
            case List<decimal?> theList:
86
                return BuildList<decimal?>(theList);
6✔
87
        }
88

89
        var targetType = nullableType ?? listType;
189✔
90

91
        for (ulong i = 0; i < length; i++)
1,332✔
92
        {
93
            var childOffset = listOffset + i;
495✔
94
            if (listDataReader.IsValid(childOffset))
495✔
95
            {
96
                var item = listDataReader.GetValue(childOffset, targetType);
432✔
97
                list.Add(item);
417✔
98
            }
99
            else
100
            {
101
                if (allowNulls)
63✔
102
                {
103
                    list.Add(null);
60✔
104
                }
105
                else
106
                {
107
                    throw new NullReferenceException("The list contains null value");
3✔
108
                }
109
            }
110
        }
111

112
        return list;
171✔
113

114
        List<T> BuildList<T>(List<T> result)
115
        {
116
            for (ulong i = 0; i < length; i++)
1,230✔
117
            {
118
                var childOffset = listOffset + i;
444✔
119
                if (listDataReader.IsValid(childOffset))
444✔
120
                {
121
                    var item = listDataReader.GetValue<T>(childOffset);
357✔
122
                    result.Add(item);
354✔
123
                }
124
                else
125
                {
126
                    if (allowNulls)
87✔
127
                    {
128
                        result.Add(default!);
84✔
129
                    }
130
                    else
131
                    {
132
                        throw new NullReferenceException("The list contains null value");
3✔
133
                    }
134
                }
135
            }
136
            return result;
171✔
137
        }
138
    }
139

140
    public override void Dispose()
141
    {
142
        listDataReader.Dispose();
100✔
143
        base.Dispose();
100✔
144
    }
100✔
145
}
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