duckdb 0.8.2-dev2842.0 → 0.8.2-dev3007.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.gyp +1 -0
- package/package.json +1 -1
- package/src/duckdb/extension/json/include/json_deserializer.hpp +1 -1
- package/src/duckdb/extension/json/include/json_serializer.hpp +1 -1
- package/src/duckdb/extension/json/json_deserializer.cpp +7 -5
- package/src/duckdb/extension/json/json_serializer.cpp +2 -3
- package/src/duckdb/src/common/adbc/adbc.cpp +400 -145
- package/src/duckdb/src/common/adbc/driver_manager.cpp +79 -31
- package/src/duckdb/src/common/adbc/nanoarrow/allocator.cpp +57 -0
- package/src/duckdb/src/common/adbc/nanoarrow/metadata.cpp +121 -0
- package/src/duckdb/src/common/adbc/nanoarrow/schema.cpp +474 -0
- package/src/duckdb/src/common/adbc/nanoarrow/single_batch_array_stream.cpp +84 -0
- package/src/duckdb/src/common/arrow/arrow_converter.cpp +4 -2
- package/src/duckdb/src/common/multi_file_reader.cpp +6 -0
- package/src/duckdb/src/execution/window_executor.cpp +5 -8
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/include/duckdb/common/adbc/adbc.h +1 -0
- package/src/duckdb/src/include/duckdb/common/adbc/adbc.hpp +3 -3
- package/src/duckdb/src/include/duckdb/common/adbc/single_batch_array_stream.hpp +16 -0
- package/src/duckdb/src/include/duckdb/common/arrow/arrow_appender.hpp +1 -2
- package/src/duckdb/src/include/duckdb/common/arrow/arrow_converter.hpp +0 -2
- package/src/duckdb/src/include/duckdb/common/arrow/nanoarrow/nanoarrow.h +462 -0
- package/src/duckdb/src/include/duckdb/common/arrow/nanoarrow/nanoarrow.hpp +14 -0
- package/src/duckdb/src/include/duckdb/common/types/data_chunk.hpp +0 -2
- package/src/duckdb/src/include/duckdb/main/chunk_scan_state.hpp +2 -4
- package/src/duckdb/src/include/duckdb.h +16 -0
- package/src/duckdb/src/main/capi/arrow-c.cpp +41 -0
- package/src/duckdb/src/main/capi/prepared-c.cpp +60 -30
- package/src/duckdb/src/main/chunk_scan_state.cpp +6 -0
- package/src/duckdb/src/main/client_context.cpp +1 -1
- package/src/duckdb/src/optimizer/topn_optimizer.cpp +7 -0
- package/src/duckdb/src/parser/transform/constraint/transform_constraint.cpp +55 -38
- package/src/duckdb/src/storage/compression/bitpacking.cpp +1 -1
- package/src/duckdb/ub_src_common_adbc_nanoarrow.cpp +8 -0
- package/src/duckdb_node.hpp +1 -0
- package/src/statement.cpp +1 -1
@@ -0,0 +1,462 @@
|
|
1
|
+
// Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
// or more contributor license agreements. See the NOTICE file
|
3
|
+
// distributed with this work for additional information
|
4
|
+
// regarding copyright ownership. The ASF licenses this file
|
5
|
+
// to you under the Apache License, Version 2.0 (the
|
6
|
+
// "License"); you may not use this file except in compliance
|
7
|
+
// with the License. You may obtain a copy of the License at
|
8
|
+
//
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
//
|
11
|
+
// Unless required by applicable law or agreed to in writing,
|
12
|
+
// software distributed under the License is distributed on an
|
13
|
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
// KIND, either express or implied. See the License for the
|
15
|
+
// specific language governing permissions and limitations
|
16
|
+
// under the License.
|
17
|
+
|
18
|
+
#ifndef NANOARROW_H_INCLUDED
|
19
|
+
#define NANOARROW_H_INCLUDED
|
20
|
+
|
21
|
+
#include <stddef.h>
|
22
|
+
#include <stdint.h>
|
23
|
+
#include <stdlib.h>
|
24
|
+
|
25
|
+
#include "duckdb/common/arrow/arrow.hpp"
|
26
|
+
|
27
|
+
namespace duckdb_nanoarrow {
|
28
|
+
|
29
|
+
/// \file Arrow C Implementation
|
30
|
+
///
|
31
|
+
/// EXPERIMENTAL. Interface subject to change.
|
32
|
+
|
33
|
+
/// \page object-model Object Model
|
34
|
+
///
|
35
|
+
/// Except where noted, objects are not thread-safe and clients should
|
36
|
+
/// take care to serialize accesses to methods.
|
37
|
+
///
|
38
|
+
/// Because this library is intended to be vendored, it provides full type
|
39
|
+
/// definitions and encourages clients to stack or statically allocate
|
40
|
+
/// where convenient.
|
41
|
+
|
42
|
+
/// \defgroup nanoarrow-malloc Memory management
|
43
|
+
///
|
44
|
+
/// Non-buffer members of a struct ArrowSchema and struct ArrowArray
|
45
|
+
/// must be allocated using ArrowMalloc() or ArrowRealloc() and freed
|
46
|
+
/// using ArrowFree for schemas and arrays allocated here. Buffer members
|
47
|
+
/// are allocated using an ArrowBufferAllocator.
|
48
|
+
|
49
|
+
/// \brief Allocate like malloc()
|
50
|
+
void *ArrowMalloc(int64_t size);
|
51
|
+
|
52
|
+
/// \brief Reallocate like realloc()
|
53
|
+
void *ArrowRealloc(void *ptr, int64_t size);
|
54
|
+
|
55
|
+
/// \brief Free a pointer allocated using ArrowMalloc() or ArrowRealloc().
|
56
|
+
void ArrowFree(void *ptr);
|
57
|
+
|
58
|
+
/// \brief Array buffer allocation and deallocation
|
59
|
+
///
|
60
|
+
/// Container for allocate, reallocate, and free methods that can be used
|
61
|
+
/// to customize allocation and deallocation of buffers when constructing
|
62
|
+
/// an ArrowArray.
|
63
|
+
struct ArrowBufferAllocator {
|
64
|
+
/// \brief Allocate a buffer or return NULL if it cannot be allocated
|
65
|
+
uint8_t *(*allocate)(struct ArrowBufferAllocator *allocator, int64_t size);
|
66
|
+
|
67
|
+
/// \brief Reallocate a buffer or return NULL if it cannot be reallocated
|
68
|
+
uint8_t *(*reallocate)(struct ArrowBufferAllocator *allocator, uint8_t *ptr, int64_t old_size, int64_t new_size);
|
69
|
+
|
70
|
+
/// \brief Deallocate a buffer allocated by this allocator
|
71
|
+
void (*free)(struct ArrowBufferAllocator *allocator, uint8_t *ptr, int64_t size);
|
72
|
+
|
73
|
+
/// \brief Opaque data specific to the allocator
|
74
|
+
void *private_data;
|
75
|
+
};
|
76
|
+
|
77
|
+
/// \brief Return the default allocator
|
78
|
+
///
|
79
|
+
/// The default allocator uses ArrowMalloc(), ArrowRealloc(), and
|
80
|
+
/// ArrowFree().
|
81
|
+
struct ArrowBufferAllocator *ArrowBufferAllocatorDefault();
|
82
|
+
|
83
|
+
/// }@
|
84
|
+
|
85
|
+
/// \defgroup nanoarrow-errors Error handling primitives
|
86
|
+
/// Functions generally return an errno-compatible error code; functions that
|
87
|
+
/// need to communicate more verbose error information accept a pointer
|
88
|
+
/// to an ArrowError. This can be stack or statically allocated. The
|
89
|
+
/// content of the message is undefined unless an error code has been
|
90
|
+
/// returned.
|
91
|
+
|
92
|
+
/// \brief Error type containing a UTF-8 encoded message.
|
93
|
+
struct ArrowError {
|
94
|
+
char message[1024];
|
95
|
+
};
|
96
|
+
|
97
|
+
/// \brief Return code for success.
|
98
|
+
#define NANOARROW_OK 0
|
99
|
+
|
100
|
+
/// \brief Represents an errno-compatible error code
|
101
|
+
typedef int ArrowErrorCode;
|
102
|
+
|
103
|
+
/// \brief Set the contents of an error using printf syntax
|
104
|
+
ArrowErrorCode ArrowErrorSet(struct ArrowError *error, const char *fmt, ...);
|
105
|
+
|
106
|
+
/// \brief Get the contents of an error
|
107
|
+
const char *ArrowErrorMessage(struct ArrowError *error);
|
108
|
+
|
109
|
+
/// }@
|
110
|
+
|
111
|
+
/// \defgroup nanoarrow-utils Utility data structures
|
112
|
+
|
113
|
+
/// \brief An non-owning view of a string
|
114
|
+
struct ArrowStringView {
|
115
|
+
/// \brief A pointer to the start of the string
|
116
|
+
///
|
117
|
+
/// If n_bytes is 0, this value may be NULL.
|
118
|
+
const char *data;
|
119
|
+
|
120
|
+
/// \brief The size of the string in bytes,
|
121
|
+
///
|
122
|
+
/// (Not including the null terminator.)
|
123
|
+
int64_t n_bytes;
|
124
|
+
};
|
125
|
+
|
126
|
+
/// \brief Arrow type enumerator
|
127
|
+
///
|
128
|
+
/// These names are intended to map to the corresponding arrow::Type::type
|
129
|
+
/// enumerator; however, the numeric values are specifically not equal
|
130
|
+
/// (i.e., do not rely on numeric comparison).
|
131
|
+
enum ArrowType {
|
132
|
+
NANOARROW_TYPE_UNINITIALIZED = 0,
|
133
|
+
NANOARROW_TYPE_NA = 1,
|
134
|
+
NANOARROW_TYPE_BOOL,
|
135
|
+
NANOARROW_TYPE_UINT8,
|
136
|
+
NANOARROW_TYPE_INT8,
|
137
|
+
NANOARROW_TYPE_UINT16,
|
138
|
+
NANOARROW_TYPE_INT16,
|
139
|
+
NANOARROW_TYPE_UINT32,
|
140
|
+
NANOARROW_TYPE_INT32,
|
141
|
+
NANOARROW_TYPE_UINT64,
|
142
|
+
NANOARROW_TYPE_INT64,
|
143
|
+
NANOARROW_TYPE_HALF_FLOAT,
|
144
|
+
NANOARROW_TYPE_FLOAT,
|
145
|
+
NANOARROW_TYPE_DOUBLE,
|
146
|
+
NANOARROW_TYPE_STRING,
|
147
|
+
NANOARROW_TYPE_BINARY,
|
148
|
+
NANOARROW_TYPE_FIXED_SIZE_BINARY,
|
149
|
+
NANOARROW_TYPE_DATE32,
|
150
|
+
NANOARROW_TYPE_DATE64,
|
151
|
+
NANOARROW_TYPE_TIMESTAMP,
|
152
|
+
NANOARROW_TYPE_TIME32,
|
153
|
+
NANOARROW_TYPE_TIME64,
|
154
|
+
NANOARROW_TYPE_INTERVAL_MONTHS,
|
155
|
+
NANOARROW_TYPE_INTERVAL_DAY_TIME,
|
156
|
+
NANOARROW_TYPE_DECIMAL128,
|
157
|
+
NANOARROW_TYPE_DECIMAL256,
|
158
|
+
NANOARROW_TYPE_LIST,
|
159
|
+
NANOARROW_TYPE_STRUCT,
|
160
|
+
NANOARROW_TYPE_SPARSE_UNION,
|
161
|
+
NANOARROW_TYPE_DENSE_UNION,
|
162
|
+
NANOARROW_TYPE_DICTIONARY,
|
163
|
+
NANOARROW_TYPE_MAP,
|
164
|
+
NANOARROW_TYPE_EXTENSION,
|
165
|
+
NANOARROW_TYPE_FIXED_SIZE_LIST,
|
166
|
+
NANOARROW_TYPE_DURATION,
|
167
|
+
NANOARROW_TYPE_LARGE_STRING,
|
168
|
+
NANOARROW_TYPE_LARGE_BINARY,
|
169
|
+
NANOARROW_TYPE_LARGE_LIST,
|
170
|
+
NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO
|
171
|
+
};
|
172
|
+
|
173
|
+
/// \brief Arrow time unit enumerator
|
174
|
+
///
|
175
|
+
/// These names and values map to the corresponding arrow::TimeUnit::type
|
176
|
+
/// enumerator.
|
177
|
+
enum ArrowTimeUnit {
|
178
|
+
NANOARROW_TIME_UNIT_SECOND = 0,
|
179
|
+
NANOARROW_TIME_UNIT_MILLI = 1,
|
180
|
+
NANOARROW_TIME_UNIT_MICRO = 2,
|
181
|
+
NANOARROW_TIME_UNIT_NANO = 3
|
182
|
+
};
|
183
|
+
|
184
|
+
/// }@
|
185
|
+
|
186
|
+
/// \defgroup nanoarrow-schema Schema producer helpers
|
187
|
+
/// These functions allocate, copy, and destroy ArrowSchema structures
|
188
|
+
|
189
|
+
/// \brief Initialize the fields of a schema
|
190
|
+
///
|
191
|
+
/// Initializes the fields and release callback of schema_out. Caller
|
192
|
+
/// is responsible for calling the schema->release callback if
|
193
|
+
/// NANOARROW_OK is returned.
|
194
|
+
ArrowErrorCode ArrowSchemaInit(struct ArrowSchema *schema, enum ArrowType type);
|
195
|
+
|
196
|
+
/// \brief Initialize the fields of a fixed-size schema
|
197
|
+
///
|
198
|
+
/// Returns EINVAL for fixed_size <= 0 or for data_type that is not
|
199
|
+
/// NANOARROW_TYPE_FIXED_SIZE_BINARY or NANOARROW_TYPE_FIXED_SIZE_LIST.
|
200
|
+
ArrowErrorCode ArrowSchemaInitFixedSize(struct ArrowSchema *schema, enum ArrowType data_type, int32_t fixed_size);
|
201
|
+
|
202
|
+
/// \brief Initialize the fields of a decimal schema
|
203
|
+
///
|
204
|
+
/// Returns EINVAL for scale <= 0 or for data_type that is not
|
205
|
+
/// NANOARROW_TYPE_DECIMAL128 or NANOARROW_TYPE_DECIMAL256.
|
206
|
+
ArrowErrorCode ArrowSchemaInitDecimal(struct ArrowSchema *schema, enum ArrowType data_type, int32_t decimal_precision,
|
207
|
+
int32_t decimal_scale);
|
208
|
+
|
209
|
+
/// \brief Initialize the fields of a time, timestamp, or duration schema
|
210
|
+
///
|
211
|
+
/// Returns EINVAL for data_type that is not
|
212
|
+
/// NANOARROW_TYPE_TIME32, NANOARROW_TYPE_TIME64,
|
213
|
+
/// NANOARROW_TYPE_TIMESTAMP, or NANOARROW_TYPE_DURATION. The
|
214
|
+
/// timezone parameter must be NULL for a non-timestamp data_type.
|
215
|
+
ArrowErrorCode ArrowSchemaInitDateTime(struct ArrowSchema *schema, enum ArrowType data_type,
|
216
|
+
enum ArrowTimeUnit time_unit, const char *timezone);
|
217
|
+
|
218
|
+
/// \brief Make a (recursive) copy of a schema
|
219
|
+
///
|
220
|
+
/// Allocates and copies fields of schema into schema_out.
|
221
|
+
ArrowErrorCode ArrowSchemaDeepCopy(struct ArrowSchema *schema, struct ArrowSchema *schema_out);
|
222
|
+
|
223
|
+
/// \brief Copy format into schema->format
|
224
|
+
///
|
225
|
+
/// schema must have been allocated using ArrowSchemaInit or
|
226
|
+
/// ArrowSchemaDeepCopy.
|
227
|
+
ArrowErrorCode ArrowSchemaSetFormat(struct ArrowSchema *schema, const char *format);
|
228
|
+
|
229
|
+
/// \brief Copy name into schema->name
|
230
|
+
///
|
231
|
+
/// schema must have been allocated using ArrowSchemaInit or
|
232
|
+
/// ArrowSchemaDeepCopy.
|
233
|
+
ArrowErrorCode ArrowSchemaSetName(struct ArrowSchema *schema, const char *name);
|
234
|
+
|
235
|
+
/// \brief Copy metadata into schema->metadata
|
236
|
+
///
|
237
|
+
/// schema must have been allocated using ArrowSchemaInit or
|
238
|
+
/// ArrowSchemaDeepCopy.
|
239
|
+
ArrowErrorCode ArrowSchemaSetMetadata(struct ArrowSchema *schema, const char *metadata);
|
240
|
+
|
241
|
+
/// \brief Allocate the schema->children array
|
242
|
+
///
|
243
|
+
/// Includes the memory for each child struct ArrowSchema.
|
244
|
+
/// schema must have been allocated using ArrowSchemaInit or
|
245
|
+
/// ArrowSchemaDeepCopy.
|
246
|
+
ArrowErrorCode ArrowSchemaAllocateChildren(struct ArrowSchema *schema, int64_t n_children);
|
247
|
+
|
248
|
+
/// \brief Allocate the schema->dictionary member
|
249
|
+
///
|
250
|
+
/// schema must have been allocated using ArrowSchemaInit or
|
251
|
+
/// ArrowSchemaDeepCopy.
|
252
|
+
ArrowErrorCode ArrowSchemaAllocateDictionary(struct ArrowSchema *schema);
|
253
|
+
|
254
|
+
/// \brief Reader for key/value pairs in schema metadata
|
255
|
+
struct ArrowMetadataReader {
|
256
|
+
const char *metadata;
|
257
|
+
int64_t offset;
|
258
|
+
int32_t remaining_keys;
|
259
|
+
};
|
260
|
+
|
261
|
+
/// \brief Initialize an ArrowMetadataReader
|
262
|
+
ArrowErrorCode ArrowMetadataReaderInit(struct ArrowMetadataReader *reader, const char *metadata);
|
263
|
+
|
264
|
+
/// \brief Read the next key/value pair from an ArrowMetadataReader
|
265
|
+
ArrowErrorCode ArrowMetadataReaderRead(struct ArrowMetadataReader *reader, struct ArrowStringView *key_out,
|
266
|
+
struct ArrowStringView *value_out);
|
267
|
+
|
268
|
+
/// \brief The number of bytes in in a key/value metadata string
|
269
|
+
int64_t ArrowMetadataSizeOf(const char *metadata);
|
270
|
+
|
271
|
+
/// \brief Check for a key in schema metadata
|
272
|
+
char ArrowMetadataHasKey(const char *metadata, const char *key);
|
273
|
+
|
274
|
+
/// \brief Extract a value from schema metadata
|
275
|
+
ArrowErrorCode ArrowMetadataGetValue(const char *metadata, const char *key, const char *default_value,
|
276
|
+
struct ArrowStringView *value_out);
|
277
|
+
|
278
|
+
/// }@
|
279
|
+
|
280
|
+
/// \defgroup nanoarrow-schema-view Schema consumer helpers
|
281
|
+
|
282
|
+
/// \brief A non-owning view of a parsed ArrowSchema
|
283
|
+
///
|
284
|
+
/// Contains more readily extractable values than a raw ArrowSchema.
|
285
|
+
/// Clients can stack or statically allocate this structure but are
|
286
|
+
/// encouraged to use the provided getters to ensure forward
|
287
|
+
/// compatiblity.
|
288
|
+
struct ArrowSchemaView {
|
289
|
+
/// \brief A pointer to the schema represented by this view
|
290
|
+
struct ArrowSchema *schema;
|
291
|
+
|
292
|
+
/// \brief The data type represented by the schema
|
293
|
+
///
|
294
|
+
/// This value may be NANOARROW_TYPE_DICTIONARY if the schema has a
|
295
|
+
/// non-null dictionary member; datetime types are valid values.
|
296
|
+
/// This value will never be NANOARROW_TYPE_EXTENSION (see
|
297
|
+
/// extension_name and/or extension_metadata to check for
|
298
|
+
/// an extension type).
|
299
|
+
enum ArrowType data_type;
|
300
|
+
|
301
|
+
/// \brief The storage data type represented by the schema
|
302
|
+
///
|
303
|
+
/// This value will never be NANOARROW_TYPE_DICTIONARY, NANOARROW_TYPE_EXTENSION
|
304
|
+
/// or any datetime type. This value represents only the type required to
|
305
|
+
/// interpret the buffers in the array.
|
306
|
+
enum ArrowType storage_data_type;
|
307
|
+
|
308
|
+
/// \brief The extension type name if it exists
|
309
|
+
///
|
310
|
+
/// If the ARROW:extension:name key is present in schema.metadata,
|
311
|
+
/// extension_name.data will be non-NULL.
|
312
|
+
struct ArrowStringView extension_name;
|
313
|
+
|
314
|
+
/// \brief The extension type metadata if it exists
|
315
|
+
///
|
316
|
+
/// If the ARROW:extension:metadata key is present in schema.metadata,
|
317
|
+
/// extension_metadata.data will be non-NULL.
|
318
|
+
struct ArrowStringView extension_metadata;
|
319
|
+
|
320
|
+
/// \brief The expected number of buffers in a paired ArrowArray
|
321
|
+
int32_t n_buffers;
|
322
|
+
|
323
|
+
/// \brief The index of the validity buffer or -1 if one does not exist
|
324
|
+
int32_t validity_buffer_id;
|
325
|
+
|
326
|
+
/// \brief The index of the offset buffer or -1 if one does not exist
|
327
|
+
int32_t offset_buffer_id;
|
328
|
+
|
329
|
+
/// \brief The index of the data buffer or -1 if one does not exist
|
330
|
+
int32_t data_buffer_id;
|
331
|
+
|
332
|
+
/// \brief The index of the type_ids buffer or -1 if one does not exist
|
333
|
+
int32_t type_id_buffer_id;
|
334
|
+
|
335
|
+
/// \brief Format fixed size parameter
|
336
|
+
///
|
337
|
+
/// This value is set when parsing a fixed-size binary or fixed-size
|
338
|
+
/// list schema; this value is undefined for other types. For a
|
339
|
+
/// fixed-size binary schema this value is in bytes; for a fixed-size
|
340
|
+
/// list schema this value refers to the number of child elements for
|
341
|
+
/// each element of the parent.
|
342
|
+
int32_t fixed_size;
|
343
|
+
|
344
|
+
/// \brief Decimal bitwidth
|
345
|
+
///
|
346
|
+
/// This value is set when parsing a decimal type schema;
|
347
|
+
/// this value is undefined for other types.
|
348
|
+
int32_t decimal_bitwidth;
|
349
|
+
|
350
|
+
/// \brief Decimal precision
|
351
|
+
///
|
352
|
+
/// This value is set when parsing a decimal type schema;
|
353
|
+
/// this value is undefined for other types.
|
354
|
+
int32_t decimal_precision;
|
355
|
+
|
356
|
+
/// \brief Decimal scale
|
357
|
+
///
|
358
|
+
/// This value is set when parsing a decimal type schema;
|
359
|
+
/// this value is undefined for other types.
|
360
|
+
int32_t decimal_scale;
|
361
|
+
|
362
|
+
/// \brief Format time unit parameter
|
363
|
+
///
|
364
|
+
/// This value is set when parsing a date/time type. The value is
|
365
|
+
/// undefined for other types.
|
366
|
+
enum ArrowTimeUnit time_unit;
|
367
|
+
|
368
|
+
/// \brief Format timezone parameter
|
369
|
+
///
|
370
|
+
/// This value is set when parsing a timestamp type and represents
|
371
|
+
/// the timezone format parameter. The ArrowStrintgView points to
|
372
|
+
/// data within the schema and the value is undefined for other types.
|
373
|
+
struct ArrowStringView timezone;
|
374
|
+
|
375
|
+
/// \brief Union type ids parameter
|
376
|
+
///
|
377
|
+
/// This value is set when parsing a union type and represents
|
378
|
+
/// type ids parameter. The ArrowStringView points to
|
379
|
+
/// data within the schema and the value is undefined for other types.
|
380
|
+
struct ArrowStringView union_type_ids;
|
381
|
+
};
|
382
|
+
|
383
|
+
/// \brief Initialize an ArrowSchemaView
|
384
|
+
ArrowErrorCode ArrowSchemaViewInit(struct ArrowSchemaView *schema_view, struct ArrowSchema *schema,
|
385
|
+
struct ArrowError *error);
|
386
|
+
|
387
|
+
/// }@
|
388
|
+
|
389
|
+
/// \defgroup nanoarrow-buffer-builder Growable buffer builders
|
390
|
+
|
391
|
+
/// \brief An owning mutable view of a buffer
|
392
|
+
struct ArrowBuffer {
|
393
|
+
/// \brief A pointer to the start of the buffer
|
394
|
+
///
|
395
|
+
/// If capacity_bytes is 0, this value may be NULL.
|
396
|
+
uint8_t *data;
|
397
|
+
|
398
|
+
/// \brief The size of the buffer in bytes
|
399
|
+
int64_t size_bytes;
|
400
|
+
|
401
|
+
/// \brief The capacity of the buffer in bytes
|
402
|
+
int64_t capacity_bytes;
|
403
|
+
|
404
|
+
/// \brief The allocator that will be used to reallocate and/or free the buffer
|
405
|
+
struct ArrowBufferAllocator *allocator;
|
406
|
+
};
|
407
|
+
|
408
|
+
/// \brief Initialize an ArrowBuffer
|
409
|
+
///
|
410
|
+
/// Initialize a buffer with a NULL, zero-size buffer using the default
|
411
|
+
/// buffer allocator.
|
412
|
+
void ArrowBufferInit(struct ArrowBuffer *buffer);
|
413
|
+
|
414
|
+
/// \brief Set a newly-initialized buffer's allocator
|
415
|
+
///
|
416
|
+
/// Returns EINVAL if the buffer has already been allocated.
|
417
|
+
ArrowErrorCode ArrowBufferSetAllocator(struct ArrowBuffer *buffer, struct ArrowBufferAllocator *allocator);
|
418
|
+
|
419
|
+
/// \brief Reset an ArrowBuffer
|
420
|
+
///
|
421
|
+
/// Releases the buffer using the allocator's free method if
|
422
|
+
/// the buffer's data member is non-null, sets the data member
|
423
|
+
/// to NULL, and sets the buffer's size and capacity to 0.
|
424
|
+
void ArrowBufferReset(struct ArrowBuffer *buffer);
|
425
|
+
|
426
|
+
/// \brief Move an ArrowBuffer
|
427
|
+
///
|
428
|
+
/// Transfers the buffer data and lifecycle management to another
|
429
|
+
/// address and resets buffer.
|
430
|
+
void ArrowBufferMove(struct ArrowBuffer *buffer, struct ArrowBuffer *buffer_out);
|
431
|
+
|
432
|
+
/// \brief Grow or shrink a buffer to a given capacity
|
433
|
+
///
|
434
|
+
/// When shrinking the capacity of the buffer, the buffer is only reallocated
|
435
|
+
/// if shrink_to_fit is non-zero. Calling ArrowBufferResize() does not
|
436
|
+
/// adjust the buffer's size member except to ensure that the invariant
|
437
|
+
/// capacity >= size remains true.
|
438
|
+
ArrowErrorCode ArrowBufferResize(struct ArrowBuffer *buffer, int64_t new_capacity_bytes, char shrink_to_fit);
|
439
|
+
|
440
|
+
/// \brief Ensure a buffer has at least a given additional capacity
|
441
|
+
///
|
442
|
+
/// Ensures that the buffer has space to append at least
|
443
|
+
/// additional_size_bytes, overallocating when required.
|
444
|
+
ArrowErrorCode ArrowBufferReserve(struct ArrowBuffer *buffer, int64_t additional_size_bytes);
|
445
|
+
|
446
|
+
/// \brief Write data to buffer and increment the buffer size
|
447
|
+
///
|
448
|
+
/// This function does not check that buffer has the required capacity
|
449
|
+
void ArrowBufferAppendUnsafe(struct ArrowBuffer *buffer, const void *data, int64_t size_bytes);
|
450
|
+
|
451
|
+
/// \brief Write data to buffer and increment the buffer size
|
452
|
+
///
|
453
|
+
/// This function writes and ensures that the buffer has the required capacity,
|
454
|
+
/// possibly by reallocating the buffer. Like ArrowBufferReserve, this will
|
455
|
+
/// overallocate when reallocation is required.
|
456
|
+
ArrowErrorCode ArrowBufferAppend(struct ArrowBuffer *buffer, const void *data, int64_t size_bytes);
|
457
|
+
|
458
|
+
/// }@
|
459
|
+
|
460
|
+
} // namespace duckdb_nanoarrow
|
461
|
+
|
462
|
+
#endif // NANOARROW_H_INCLUDED
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "duckdb/common/arrow/nanoarrow/nanoarrow.h"
|
4
|
+
|
5
|
+
// Bring in the symbols from duckdb_nanoarrow into duckdb
|
6
|
+
namespace duckdb {
|
7
|
+
|
8
|
+
// using duckdb_nanoarrow::ArrowBuffer; //We have a variant of this that should be renamed
|
9
|
+
using duckdb_nanoarrow::ArrowBufferAllocator;
|
10
|
+
using duckdb_nanoarrow::ArrowError;
|
11
|
+
using duckdb_nanoarrow::ArrowSchemaView;
|
12
|
+
using duckdb_nanoarrow::ArrowStringView;
|
13
|
+
|
14
|
+
} // namespace duckdb
|
@@ -11,10 +11,8 @@ class DataChunk;
|
|
11
11
|
//! Abstract chunk fetcher
|
12
12
|
class ChunkScanState {
|
13
13
|
public:
|
14
|
-
explicit ChunkScanState()
|
15
|
-
|
16
|
-
virtual ~ChunkScanState() {
|
17
|
-
}
|
14
|
+
explicit ChunkScanState();
|
15
|
+
virtual ~ChunkScanState();
|
18
16
|
|
19
17
|
public:
|
20
18
|
ChunkScanState(const ChunkScanState &other) = delete;
|
@@ -971,6 +971,12 @@ Clear the params bind to the prepared statement.
|
|
971
971
|
*/
|
972
972
|
DUCKDB_API duckdb_state duckdb_clear_bindings(duckdb_prepared_statement prepared_statement);
|
973
973
|
|
974
|
+
/*!
|
975
|
+
Binds a value to the prepared statement at the specified index.
|
976
|
+
*/
|
977
|
+
DUCKDB_API duckdb_state duckdb_bind_value(duckdb_prepared_statement prepared_statement, idx_t param_idx,
|
978
|
+
duckdb_value val);
|
979
|
+
|
974
980
|
/*!
|
975
981
|
Retrieve the index of the parameter for the prepared statement, identified by name
|
976
982
|
*/
|
@@ -2324,6 +2330,16 @@ Fetch the internal arrow schema from the arrow result.
|
|
2324
2330
|
*/
|
2325
2331
|
DUCKDB_API duckdb_state duckdb_query_arrow_schema(duckdb_arrow result, duckdb_arrow_schema *out_schema);
|
2326
2332
|
|
2333
|
+
/*!
|
2334
|
+
Fetch the internal arrow schema from the prepared statement.
|
2335
|
+
|
2336
|
+
* result: The prepared statement to fetch the schema from.
|
2337
|
+
* out_schema: The output schema.
|
2338
|
+
* returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
|
2339
|
+
*/
|
2340
|
+
DUCKDB_API duckdb_state duckdb_prepared_arrow_schema(duckdb_prepared_statement prepared,
|
2341
|
+
duckdb_arrow_schema *out_schema);
|
2342
|
+
|
2327
2343
|
/*!
|
2328
2344
|
Fetch an internal arrow array from the arrow result.
|
2329
2345
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
#include "duckdb/common/arrow/arrow_converter.hpp"
|
2
2
|
#include "duckdb/function/table/arrow.hpp"
|
3
3
|
#include "duckdb/main/capi/capi_internal.hpp"
|
4
|
+
#include "duckdb/main/prepared_statement_data.hpp"
|
5
|
+
#include "duckdb/common/arrow/arrow.hpp"
|
4
6
|
|
5
7
|
using duckdb::ArrowConverter;
|
6
8
|
using duckdb::ArrowResultWrapper;
|
@@ -30,6 +32,45 @@ duckdb_state duckdb_query_arrow_schema(duckdb_arrow result, duckdb_arrow_schema
|
|
30
32
|
return DuckDBSuccess;
|
31
33
|
}
|
32
34
|
|
35
|
+
duckdb_state duckdb_prepared_arrow_schema(duckdb_prepared_statement prepared, duckdb_arrow_schema *out_schema) {
|
36
|
+
if (!out_schema) {
|
37
|
+
return DuckDBSuccess;
|
38
|
+
}
|
39
|
+
auto wrapper = reinterpret_cast<PreparedStatementWrapper *>(prepared);
|
40
|
+
if (!wrapper || !wrapper->statement || !wrapper->statement->data) {
|
41
|
+
return DuckDBError;
|
42
|
+
}
|
43
|
+
auto properties = wrapper->statement->context->GetClientProperties();
|
44
|
+
duckdb::vector<duckdb::LogicalType> prepared_types;
|
45
|
+
duckdb::vector<duckdb::string> prepared_names;
|
46
|
+
|
47
|
+
auto count = wrapper->statement->data->properties.parameter_count;
|
48
|
+
for (idx_t i = 0; i < count; i++) {
|
49
|
+
// Every prepared parameter type is UNKNOWN, which we need to map to NULL according to the spec of
|
50
|
+
// 'AdbcStatementGetParameterSchema'
|
51
|
+
auto type = LogicalType::SQLNULL;
|
52
|
+
|
53
|
+
// FIXME: we don't support named parameters yet, but when we do, this needs to be updated
|
54
|
+
auto name = std::to_string(i);
|
55
|
+
prepared_types.push_back(std::move(type));
|
56
|
+
prepared_names.push_back(name);
|
57
|
+
}
|
58
|
+
|
59
|
+
auto result_schema = (ArrowSchema *)*out_schema;
|
60
|
+
if (!result_schema) {
|
61
|
+
return DuckDBError;
|
62
|
+
}
|
63
|
+
|
64
|
+
if (result_schema->release) {
|
65
|
+
// Need to release the existing schema before we overwrite it
|
66
|
+
result_schema->release(result_schema);
|
67
|
+
result_schema->release = nullptr;
|
68
|
+
}
|
69
|
+
|
70
|
+
ArrowConverter::ToArrowSchema(result_schema, prepared_types, prepared_names, properties);
|
71
|
+
return DuckDBSuccess;
|
72
|
+
}
|
73
|
+
|
33
74
|
duckdb_state duckdb_query_arrow_array(duckdb_arrow result, duckdb_arrow_array *out_array) {
|
34
75
|
if (!out_array) {
|
35
76
|
return DuckDBSuccess;
|