Skip to content

Commit ea49632

Browse files
committed
Refactoring
1 parent 5b8f65a commit ea49632

File tree

3 files changed

+20
-40
lines changed

3 files changed

+20
-40
lines changed

DuckDB.NET.Data/Internal/Reader/DateTimeVectorDataReader.cs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,15 @@ protected override T GetValidValue<T>(ulong offset, Type targetType)
8080
return (T)(object)timeTz;
8181
}
8282

83-
if (DuckDBType == DuckDBType.Timestamp || DuckDBType == DuckDBType.TimestampTz)
84-
{
85-
return ReadTimestamp<T>(offset, targetType);
86-
}
87-
88-
if (DuckDBType == DuckDBType.TimestampS)
89-
{
90-
return ReadTimestamp<T>(offset, targetType, 1000000);
91-
}
92-
93-
if (DuckDBType == DuckDBType.TimestampMs)
94-
{
95-
return ReadTimestamp<T>(offset, targetType, 1000);
96-
}
97-
98-
if (DuckDBType == DuckDBType.TimestampNs)
83+
return DuckDBType switch
9984
{
100-
return ReadTimestamp<T>(offset, targetType, 1, 1000);
101-
}
102-
103-
return base.GetValidValue<T>(offset, targetType);
85+
DuckDBType.Timestamp => ReadTimestamp<T>(offset, targetType),
86+
DuckDBType.TimestampTz => ReadTimestamp<T>(offset, targetType),
87+
DuckDBType.TimestampS => ReadTimestamp<T>(offset, targetType, 1000000),
88+
DuckDBType.TimestampMs => ReadTimestamp<T>(offset, targetType, 1000),
89+
DuckDBType.TimestampNs => ReadTimestamp<T>(offset, targetType, 1, 1000),
90+
_ => base.GetValidValue<T>(offset, targetType)
91+
};
10492
}
10593

10694
private T ReadTimestamp<T>(ulong offset, Type targetType, int factor = 1, int divisor = 1)

DuckDB.NET.Data/Internal/Reader/ListVectorDataReader.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,7 @@ private unsafe object GetList(Type returnType, ulong listOffset, ulong length)
9393
}
9494
else
9595
{
96-
if (allowNulls)
97-
{
98-
list.Add(null);
99-
}
100-
else
101-
{
102-
throw new InvalidCastException("The list contains null value");
103-
}
96+
list.Add(allowNulls ? null : throw new InvalidCastException("The list contains null value"));
10497
}
10598
}
10699

@@ -118,14 +111,7 @@ List<T> BuildList<T>(List<T> result)
118111
}
119112
else
120113
{
121-
if (allowNulls)
122-
{
123-
result.Add(default!);
124-
}
125-
else
126-
{
127-
throw new InvalidCastException("The list contains null value");
128-
}
114+
result.Add(allowNulls ? default! : throw new InvalidCastException("The list contains null value"));
129115
}
130116
}
131117
return result;

DuckDB.NET.Test/DuckDBConnectionTests.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ public async Task NoExceptionOnDoubleDispose()
171171
await using var duckDBConnection = new DuckDBConnection(dbInfo.ConnectionString);
172172
await duckDBConnection.OpenAsync();
173173

174-
await duckDBConnection.DisposeAsync();
175-
await duckDBConnection.DisposeAsync();
174+
await duckDBConnection.Invoking(async connection =>
175+
{
176+
await connection.DisposeAsync();
177+
await connection.DisposeAsync();
178+
}).Should().NotThrowAsync();
176179
}
177180

178181
[Fact]
@@ -183,8 +186,11 @@ public async Task NoExceptionCloseThenDispose()
183186
await using var duckDBConnection = new DuckDBConnection(dbInfo.ConnectionString);
184187
await duckDBConnection.OpenAsync();
185188

186-
await duckDBConnection.CloseAsync();
187-
await duckDBConnection.DisposeAsync();
189+
await duckDBConnection.Invoking(async connection =>
190+
{
191+
await connection.CloseAsync();
192+
await connection.DisposeAsync();
193+
}).Should().NotThrowAsync();
188194
}
189195

190196
[Fact]

0 commit comments

Comments
 (0)