Skip to content

Commit 6cd6c10

Browse files
committed
Merge branch 'Appender-Data-Chunk' (early part) into develop
2 parents 6270bac + 338e0d3 commit 6cd6c10

32 files changed

+833
-355
lines changed

DuckDB.NET.Bindings/DuckDBDateOnly.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,13 @@
44
namespace DuckDB.NET.Native;
55

66
[StructLayout(LayoutKind.Sequential)]
7-
public readonly struct DuckDBDateOnly
7+
public readonly struct DuckDBDateOnly(int year, byte month, byte day)
88
{
9-
public DuckDBDateOnly(int year, byte month, byte day)
10-
{
11-
Year = year;
12-
Month = month;
13-
Day = day;
14-
}
9+
public int Year { get; } = year;
1510

16-
public int Year { get; }
11+
public byte Month { get; } = month;
1712

18-
public byte Month { get; }
19-
20-
public byte Day { get; }
13+
public byte Day { get; } = day;
2114

2215
internal static readonly DuckDBDateOnly MinValue = FromDateTime(DateTime.MinValue);
2316

DuckDB.NET.Bindings/DuckDBInterval.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
namespace DuckDB.NET.Native;
66

77
[StructLayout(LayoutKind.Sequential)]
8-
public readonly struct DuckDBInterval
8+
public readonly struct DuckDBInterval(int months, int days, ulong micros)
99
{
1010
private const ulong MillisecondsByDay = (ulong)(24 * 60 * 60 * 1e6);
11-
public int Months { get; }
11+
public int Months { get; } = months;
1212

13-
public int Days { get; }
14-
public ulong Micros { get; }
15-
16-
public DuckDBInterval(int months, int days, ulong micros)
17-
=> (Months, Days, Micros) = (months, days, micros);
13+
public int Days { get; } = days;
14+
public ulong Micros { get; } = micros;
1815

1916
public static explicit operator TimeSpan(DuckDBInterval interval)
2017
{

DuckDB.NET.Bindings/DuckDBTimeOnly.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,19 @@
44
namespace DuckDB.NET.Native;
55

66
[StructLayout(LayoutKind.Sequential)]
7-
public readonly struct DuckDBTimeOnly
7+
public readonly struct DuckDBTimeOnly(byte hour, byte min, byte sec, int microsecond)
88
{
99
public DuckDBTimeOnly(byte hour, byte min, byte sec) : this(hour, min, sec, 0)
1010
{
1111
}
1212

13-
public DuckDBTimeOnly(byte hour, byte min, byte sec, int microsecond)
14-
{
15-
Hour = hour;
16-
Min = min;
17-
Sec = sec;
18-
Microsecond = microsecond;
19-
}
20-
21-
public byte Hour { get; }
13+
public byte Hour { get; } = hour;
2214

23-
public byte Min { get; }
15+
public byte Min { get; } = min;
2416

25-
public byte Sec { get; }
17+
public byte Sec { get; } = sec;
2618

27-
public int Microsecond { get; }
19+
public int Microsecond { get; } = microsecond;
2820

2921
public long Ticks => Utils.GetTicks(Hour, Min, Sec, Microsecond);
3022

DuckDB.NET.Bindings/DuckDBTimestamp.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@
44
namespace DuckDB.NET.Native;
55

66
[StructLayout(LayoutKind.Sequential)]
7-
public readonly struct DuckDBTimestamp
7+
public readonly struct DuckDBTimestamp(DuckDBDateOnly date, DuckDBTimeOnly time)
88
{
9-
public DuckDBTimestamp(DuckDBDateOnly date, DuckDBTimeOnly time)
10-
{
11-
Date = date;
12-
Time = time;
13-
}
14-
15-
public DuckDBDateOnly Date { get; }
16-
public DuckDBTimeOnly Time { get; }
9+
public DuckDBDateOnly Date { get; } = date;
10+
public DuckDBTimeOnly Time { get; } = time;
1711

1812
public DateTime ToDateTime()
1913
{

DuckDB.NET.Bindings/DuckDBWrapperObjects.cs

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,52 @@
22

33
namespace DuckDB.NET.Native;
44

5-
public class DuckDBDatabase : SafeHandleZeroOrMinusOneIsInvalid
5+
public class DuckDBDatabase() : SafeHandleZeroOrMinusOneIsInvalid(true)
66
{
7-
public DuckDBDatabase() : base(true)
8-
{
9-
}
10-
117
protected override bool ReleaseHandle()
128
{
139
NativeMethods.Startup.DuckDBClose(out handle);
1410
return true;
1511
}
1612
}
1713

18-
public class DuckDBNativeConnection : SafeHandleZeroOrMinusOneIsInvalid
14+
public class DuckDBNativeConnection() : SafeHandleZeroOrMinusOneIsInvalid(true)
1915
{
20-
public DuckDBNativeConnection() : base(true)
21-
{
22-
}
23-
2416
protected override bool ReleaseHandle()
2517
{
2618
NativeMethods.Startup.DuckDBDisconnect(out handle);
2719
return true;
2820
}
2921
}
3022

31-
public class DuckDBPreparedStatement : SafeHandleZeroOrMinusOneIsInvalid
23+
public class DuckDBPreparedStatement() : SafeHandleZeroOrMinusOneIsInvalid(true)
3224
{
33-
public DuckDBPreparedStatement() : base(true)
34-
{
35-
}
36-
3725
protected override bool ReleaseHandle()
3826
{
3927
NativeMethods.PreparedStatements.DuckDBDestroyPrepare(out handle);
4028
return true;
4129
}
4230
}
4331

44-
public class DuckDBConfig : SafeHandleZeroOrMinusOneIsInvalid
32+
public class DuckDBConfig() : SafeHandleZeroOrMinusOneIsInvalid(true)
4533
{
46-
public DuckDBConfig() : base(true)
47-
{
48-
49-
}
50-
5134
protected override bool ReleaseHandle()
5235
{
5336
NativeMethods.Configuration.DuckDBDestroyConfig(out handle);
5437
return true;
5538
}
5639
}
5740

58-
public class DuckDBAppender : SafeHandleZeroOrMinusOneIsInvalid
41+
public class DuckDBAppender() : SafeHandleZeroOrMinusOneIsInvalid(true)
5942
{
60-
public DuckDBAppender() : base(true)
61-
{
62-
}
63-
6443
protected override bool ReleaseHandle()
6544
{
6645
return NativeMethods.Appender.DuckDBDestroyAppender(out handle) == DuckDBState.Success;
6746
}
6847
}
6948

70-
public class DuckDBExtractedStatements : SafeHandleZeroOrMinusOneIsInvalid
49+
public class DuckDBExtractedStatements() : SafeHandleZeroOrMinusOneIsInvalid(true)
7150
{
72-
public DuckDBExtractedStatements() : base(true)
73-
{
74-
}
75-
7651
protected override bool ReleaseHandle()
7752
{
7853
NativeMethods.ExtractStatements.DuckDBDestroyExtracted(out handle);
@@ -81,25 +56,17 @@ protected override bool ReleaseHandle()
8156
}
8257
}
8358

84-
public class DuckDBLogicalType : SafeHandleZeroOrMinusOneIsInvalid
59+
public class DuckDBLogicalType() : SafeHandleZeroOrMinusOneIsInvalid(true)
8560
{
86-
public DuckDBLogicalType() : base(true)
87-
{
88-
}
89-
9061
protected override bool ReleaseHandle()
9162
{
9263
NativeMethods.LogicalType.DuckDBDestroyLogicalType(out handle);
9364
return true;
9465
}
9566
}
9667

97-
public class DuckDBDataChunk : SafeHandleZeroOrMinusOneIsInvalid
68+
public class DuckDBDataChunk() : SafeHandleZeroOrMinusOneIsInvalid(true)
9869
{
99-
public DuckDBDataChunk() : base(true)
100-
{
101-
}
102-
10370
protected override bool ReleaseHandle()
10471
{
10572
NativeMethods.DataChunks.DuckDBDestroyDataChunk(out handle);

DuckDB.NET.Bindings/NativeMethods/NativeMethods.Appender.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ public static class Appender
1414
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_appender_create")]
1515
public static extern DuckDBState DuckDBAppenderCreate(DuckDBNativeConnection connection, SafeUnmanagedMemoryHandle schema, SafeUnmanagedMemoryHandle table, out DuckDBAppender appender);
1616

17+
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_appender_column_count")]
18+
public static extern ulong DuckDBAppenderColumnCount(DuckDBAppender appender);
19+
20+
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_appender_column_type")]
21+
public static extern DuckDBLogicalType DuckDBAppenderColumnType(DuckDBAppender appender, ulong index);
22+
1723
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_appender_error")]
1824
public static extern IntPtr DuckDBAppenderError(DuckDBAppender appender);
1925

@@ -154,5 +160,11 @@ public static class Appender
154160
#endif
155161
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_null")]
156162
public static extern DuckDBState DuckDBAppendNull(DuckDBAppender appender);
163+
164+
#if NET5_0_OR_GREATER
165+
[SuppressGCTransition]
166+
#endif
167+
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_data_chunk")]
168+
public static extern DuckDBState DuckDBAppendDataChunk(DuckDBAppender appender, DuckDBDataChunk chunk);
157169
}
158170
}

DuckDB.NET.Bindings/NativeMethods/NativeMethods.DataChunks.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ namespace DuckDB.NET.Native;
55

66
public partial class NativeMethods
77
{
8+
//https://duckdb.org/docs/api/c/api#data-chunk-interface
89
public static class DataChunks
910
{
11+
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_create_data_chunk")]
12+
public static extern unsafe DuckDBDataChunk DuckDBCreateDataChunk(IntPtr[] types, ulong count);
13+
1014
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_destroy_data_chunk")]
1115
public static extern void DuckDBDestroyDataChunk(out IntPtr chunk);
1216

17+
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_data_chunk_reset")]
18+
public static extern void DuckDBDataChunkReset(DuckDBDataChunk chunk);
19+
1320
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_data_chunk_get_column_count")]
1421
public static extern long DuckDBDataChunkGetColumnCount(DuckDBDataChunk chunk);
1522

@@ -18,5 +25,8 @@ public static class DataChunks
1825

1926
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_data_chunk_get_size")]
2027
public static extern long DuckDBDataChunkGetSize(DuckDBDataChunk chunk);
28+
29+
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_data_chunk_set_size")]
30+
public static extern long DuckDBDataChunkSetSize(DuckDBDataChunk chunk, ulong size);
2131
}
2232
}

DuckDB.NET.Bindings/NativeMethods/NativeMethods.DateTime.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public static class DateTimeHelpers
1616
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_from_time")]
1717
public static extern DuckDBTimeOnly DuckDBFromTime(DuckDBTime time);
1818

19+
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_create_time_tz")]
20+
public static extern DuckDBTimeTzStruct DuckDBCreateTimeTz(long micros, int offset);
21+
1922
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_from_time_tz")]
2023
public static extern DuckDBTimeTz DuckDBFromTimeTz(DuckDBTimeTzStruct micros);
2124

DuckDB.NET.Bindings/NativeMethods/NativeMethods.Helpers.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ public static class Helpers
1212

1313
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_decimal_to_double")]
1414
public static extern double DuckDBDecimalToDouble(DuckDBDecimal val);
15+
16+
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_vector_size")]
17+
public static extern ulong DuckDBVectorSize();
1518
}
1619
}

DuckDB.NET.Bindings/NativeMethods/NativeMethods.LogicalType.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ public partial class NativeMethods
88
//https://duckdb.org/docs/api/c/api#logical-type-interface
99
public static class LogicalType
1010
{
11+
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_create_logical_type")]
12+
public static extern DuckDBLogicalType CreateLogicalType(DuckDBType type);
13+
1114
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_get_type_id")]
1215
public static extern DuckDBType DuckDBGetTypeId(DuckDBLogicalType type);
1316

0 commit comments

Comments
 (0)