-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.go
1146 lines (888 loc) · 39.5 KB
/
functions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package duckdb
/*
#include <duckdb.h>
#include <duckdb_go_extension.h>
*/
import "C"
import "unsafe"
// TODO: should I always pass the custom types as pointers?
//func Open(path string, db *Database) State {
// cPath := C.CString(path)
// defer C.duckdb_free(unsafe.Pointer(cPath))
//
// state := State(C.duckdb_open(cPath, db.data))
// db.Ptr = unsafe.Pointer(db.data)
// return state
//}
//
//func OpenExt(path string, db *Database, config Config, errMsg *string) State {
// cPath := C.CString(path)
// defer C.duckdb_free(unsafe.Pointer(cPath))
//
// var err *C.char
// defer C.duckdb_free(unsafe.Pointer(err))
//
// state := State(C.duckdb_open_ext(cPath, db.data, *config.data, &err))
// db.Ptr = unsafe.Pointer(db.data)
// *errMsg = C.GoString(err)
// return state
//}
//
//func Close(db *Database) {
// C.duckdb_close(db.data)
// db.Ptr = nil
//}
func Connect(db Database, conn *Connection) State {
var c C.duckdb_connection
state := State(C.duckdb_connect(db.data(), &c))
conn.Ptr = unsafe.Pointer(c)
return state
}
//func Interrupt(conn Connection) {
// C.duckdb_interrupt(*conn.data)
//}
//
//func QueryProgress(conn Connection) QueryProgressType {
// p := C.duckdb_query_progress(*conn.data)
//
// return QueryProgressType{
// Percentage: float64(p.percentage),
// RowsProcessed: uint64(p.rows_processed),
// TotalRowsToProcess: uint64(p.total_rows_to_process),
// }
//}
func Disconnect(c *Connection) {
data := c.data()
C.duckdb_disconnect(&data)
c.Ptr = nil
}
//func LibraryVersion() string {
// cStr := C.duckdb_library_version()
// defer C.duckdb_free(unsafe.Pointer(cStr))
// return C.GoString(cStr)
//}
// Config
/*
static duckdb_state duckdb_create_config(duckdb_config *out_config) {
return duckdb_ext_api->duckdb_create_config(out_config);
}
static size_t duckdb_config_count() {
return duckdb_ext_api->duckdb_config_count();
}
static duckdb_state duckdb_get_config_flag(size_t index, const char **out_name, const char **out_description) {
return duckdb_ext_api->duckdb_get_config_flag(index, out_name, out_description);
}
static duckdb_state duckdb_set_config(duckdb_config config, const char *name, const char *option) {
return duckdb_ext_api->duckdb_set_config(config, name, option);
}
static void duckdb_destroy_config(duckdb_config *config) {
return duckdb_ext_api->duckdb_destroy_config(config);
}
*/
// Result
/*
static duckdb_state duckdb_query(duckdb_connection connection, const char *query, duckdb_result *out_result) {
return duckdb_ext_api->duckdb_query(connection, query, out_result);
}
static void duckdb_destroy_result(duckdb_result *result) {
return duckdb_ext_api->duckdb_destroy_result(result);
}
static const char *duckdb_column_name(duckdb_result *result, idx_t col) {
return duckdb_ext_api->duckdb_column_name(result, col);
}
static duckdb_type duckdb_column_type(duckdb_result *result, idx_t col) {
return duckdb_ext_api->duckdb_column_type(result, col);
}
static duckdb_statement_type duckdb_result_statement_type(duckdb_result result) {
return duckdb_ext_api->duckdb_result_statement_type(result);
}
static duckdb_logical_type duckdb_column_logical_type(duckdb_result *result, idx_t col) {
return duckdb_ext_api->duckdb_column_logical_type(result, col);
}
static idx_t duckdb_column_count(duckdb_result *result) {
return duckdb_ext_api->duckdb_column_count(result);
}
static idx_t duckdb_rows_changed(duckdb_result *result) {
return duckdb_ext_api->duckdb_rows_changed(result);
}
static const char *duckdb_result_error(duckdb_result *result) {
return duckdb_ext_api->duckdb_result_error(result);
}
*/
// Utility
/*
static void *duckdb_malloc(size_t size) {
return duckdb_ext_api->duckdb_malloc(size);
}
static void duckdb_free(void *ptr) {
return duckdb_ext_api->duckdb_free(ptr);
}
static idx_t duckdb_vector_size() {
return duckdb_ext_api->duckdb_vector_size();
}
*/
// Type utility
/*
static bool duckdb_string_is_inlined(duckdb_string_t string) {
return duckdb_ext_api->duckdb_string_is_inlined(string);
}
static duckdb_date_struct duckdb_from_date(duckdb_date date) {
return duckdb_ext_api->duckdb_from_date(date);
}
static duckdb_date duckdb_to_date(duckdb_date_struct date) {
return duckdb_ext_api->duckdb_to_date(date);
}
static bool duckdb_is_finite_date(duckdb_date date) {
return duckdb_ext_api->duckdb_is_finite_date(date);
}
static duckdb_time_struct duckdb_from_time(duckdb_time time) {
return duckdb_ext_api->duckdb_from_time(time);
}
static duckdb_time_tz duckdb_create_time_tz(int64_t micros, int32_t offset) {
return duckdb_ext_api->duckdb_create_time_tz(micros, offset);
}
static duckdb_time_tz_struct duckdb_from_time_tz(duckdb_time_tz micros) {
return duckdb_ext_api->duckdb_from_time_tz(micros);
}
static duckdb_time duckdb_to_time(duckdb_time_struct time) {
return duckdb_ext_api->duckdb_to_time(time);
}
static duckdb_timestamp_struct duckdb_from_timestamp(duckdb_timestamp ts) {
return duckdb_ext_api->duckdb_from_timestamp(ts);
}
static duckdb_timestamp duckdb_to_timestamp(duckdb_timestamp_struct ts) {
return duckdb_ext_api->duckdb_to_timestamp(ts);
}
static bool duckdb_is_finite_timestamp(duckdb_timestamp ts) {
return duckdb_ext_api->duckdb_is_finite_timestamp(ts);
}
static double duckdb_hugeint_to_double(duckdb_hugeint val) {
return duckdb_ext_api->duckdb_hugeint_to_double(val);
}
static duckdb_hugeint duckdb_double_to_hugeint(double val) {
return duckdb_ext_api->duckdb_double_to_hugeint(val);
}
static double duckdb_uhugeint_to_double(duckdb_uhugeint val) {
return duckdb_ext_api->duckdb_uhugeint_to_double(val);
}
static duckdb_uhugeint duckdb_double_to_uhugeint(double val) {
return duckdb_ext_api->duckdb_double_to_uhugeint(val);
}
static duckdb_decimal duckdb_double_to_decimal(double val, uint8_t width, uint8_t scale) {
return duckdb_ext_api->duckdb_double_to_decimal(val, width, scale);
}
static double duckdb_decimal_to_double(duckdb_decimal val) {
return duckdb_ext_api->duckdb_decimal_to_double(val);
}
*/
// Prepared and extracted statements
/*
static duckdb_state duckdb_prepare(duckdb_connection connection, const char *query,
duckdb_prepared_statement *out_prepared_statement) {
return duckdb_ext_api->duckdb_prepare(connection, query, out_prepared_statement);
}
static void duckdb_destroy_prepare(duckdb_prepared_statement *prepared_statement) {
return duckdb_ext_api->duckdb_destroy_prepare(prepared_statement);
}
static const char *duckdb_prepare_error(duckdb_prepared_statement prepared_statement) {
return duckdb_ext_api->duckdb_prepare_error(prepared_statement);
}
static idx_t duckdb_nparams(duckdb_prepared_statement prepared_statement) {
return duckdb_ext_api->duckdb_nparams(prepared_statement);
}
static const char *duckdb_parameter_name(duckdb_prepared_statement prepared_statement, idx_t index) {
return duckdb_ext_api->duckdb_parameter_name(prepared_statement, index);
}
static duckdb_type duckdb_param_type(duckdb_prepared_statement prepared_statement, idx_t param_idx) {
return duckdb_ext_api->duckdb_param_type(prepared_statement, param_idx);
}
static duckdb_state duckdb_clear_bindings(duckdb_prepared_statement prepared_statement) {
return duckdb_ext_api->duckdb_clear_bindings(prepared_statement);
}
static duckdb_statement_type duckdb_prepared_statement_type(duckdb_prepared_statement statement) {
return duckdb_ext_api->duckdb_prepared_statement_type(statement);
}
static duckdb_state duckdb_bind_value(duckdb_prepared_statement prepared_statement, idx_t param_idx, duckdb_value val) {
return duckdb_ext_api->duckdb_bind_value(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_parameter_index(duckdb_prepared_statement prepared_statement, idx_t *param_idx_out,
const char *name) {
return duckdb_ext_api->duckdb_bind_parameter_index(prepared_statement, param_idx_out, name);
}
static duckdb_state duckdb_bind_boolean(duckdb_prepared_statement prepared_statement, idx_t param_idx, bool val) {
return duckdb_ext_api->duckdb_bind_boolean(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_int8(duckdb_prepared_statement prepared_statement, idx_t param_idx, int8_t val) {
return duckdb_ext_api->duckdb_bind_int8(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_int16(duckdb_prepared_statement prepared_statement, idx_t param_idx, int16_t val) {
return duckdb_ext_api->duckdb_bind_int16(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_int32(duckdb_prepared_statement prepared_statement, idx_t param_idx, int32_t val) {
return duckdb_ext_api->duckdb_bind_int32(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_int64(duckdb_prepared_statement prepared_statement, idx_t param_idx, int64_t val) {
return duckdb_ext_api->duckdb_bind_int64(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_hugeint(duckdb_prepared_statement prepared_statement, idx_t param_idx,
duckdb_hugeint val) {
return duckdb_ext_api->duckdb_bind_hugeint(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_uhugeint(duckdb_prepared_statement prepared_statement, idx_t param_idx,
duckdb_uhugeint val) {
return duckdb_ext_api->duckdb_bind_uhugeint(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_decimal(duckdb_prepared_statement prepared_statement, idx_t param_idx,
duckdb_decimal val) {
return duckdb_ext_api->duckdb_bind_decimal(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_uint8(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint8_t val) {
return duckdb_ext_api->duckdb_bind_uint8(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_uint16(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint16_t val) {
return duckdb_ext_api->duckdb_bind_uint16(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_uint32(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint32_t val) {
return duckdb_ext_api->duckdb_bind_uint32(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_uint64(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint64_t val) {
return duckdb_ext_api->duckdb_bind_uint64(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_float(duckdb_prepared_statement prepared_statement, idx_t param_idx, float val) {
return duckdb_ext_api->duckdb_bind_float(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_double(duckdb_prepared_statement prepared_statement, idx_t param_idx, double val) {
return duckdb_ext_api->duckdb_bind_double(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_date(duckdb_prepared_statement prepared_statement, idx_t param_idx, duckdb_date val) {
return duckdb_ext_api->duckdb_bind_date(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_time(duckdb_prepared_statement prepared_statement, idx_t param_idx, duckdb_time val) {
return duckdb_ext_api->duckdb_bind_time(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_timestamp(duckdb_prepared_statement prepared_statement, idx_t param_idx,
duckdb_timestamp val) {
return duckdb_ext_api->duckdb_bind_timestamp(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_timestamp_tz(duckdb_prepared_statement prepared_statement, idx_t param_idx,
duckdb_timestamp val) {
return duckdb_ext_api->duckdb_bind_timestamp_tz(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_interval(duckdb_prepared_statement prepared_statement, idx_t param_idx,
duckdb_interval val) {
return duckdb_ext_api->duckdb_bind_interval(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_varchar(duckdb_prepared_statement prepared_statement, idx_t param_idx,
const char *val) {
return duckdb_ext_api->duckdb_bind_varchar(prepared_statement, param_idx, val);
}
static duckdb_state duckdb_bind_varchar_length(duckdb_prepared_statement prepared_statement, idx_t param_idx,
const char *val, idx_t length) {
return duckdb_ext_api->duckdb_bind_varchar_length(prepared_statement, param_idx, val, length);
}
static duckdb_state duckdb_bind_blob(duckdb_prepared_statement prepared_statement, idx_t param_idx, const void *data,
idx_t length) {
return duckdb_ext_api->duckdb_bind_blob(prepared_statement, param_idx, data, length);
}
static duckdb_state duckdb_bind_null(duckdb_prepared_statement prepared_statement, idx_t param_idx) {
return duckdb_ext_api->duckdb_bind_null(prepared_statement, param_idx);
}
static duckdb_state duckdb_execute_prepared(duckdb_prepared_statement prepared_statement, duckdb_result *out_result) {
return duckdb_ext_api->duckdb_execute_prepared(prepared_statement, out_result);
}
static idx_t duckdb_extract_statements(duckdb_connection connection, const char *query,
duckdb_extracted_statements *out_extracted_statements) {
return duckdb_ext_api->duckdb_extract_statements(connection, query, out_extracted_statements);
}
static duckdb_state duckdb_prepare_extracted_statement(duckdb_connection connection,
duckdb_extracted_statements extracted_statements, idx_t index,
duckdb_prepared_statement *out_prepared_statement) {
return duckdb_ext_api->duckdb_prepare_extracted_statement(connection, extracted_statements, index,
out_prepared_statement);
}
static const char *duckdb_extract_statements_error(duckdb_extracted_statements extracted_statements) {
return duckdb_ext_api->duckdb_extract_statements_error(extracted_statements);
}
static void duckdb_destroy_extracted(duckdb_extracted_statements *extracted_statements) {
return duckdb_ext_api->duckdb_destroy_extracted(extracted_statements);
}
static duckdb_state duckdb_pending_prepared(duckdb_prepared_statement prepared_statement,
duckdb_pending_result *out_result) {
return duckdb_ext_api->duckdb_pending_prepared(prepared_statement, out_result);
}
*/
// Pending result
/*
static void duckdb_destroy_pending(duckdb_pending_result *pending_result) {
return duckdb_ext_api->duckdb_destroy_pending(pending_result);
}
static const char *duckdb_pending_error(duckdb_pending_result pending_result) {
return duckdb_ext_api->duckdb_pending_error(pending_result);
}
static duckdb_pending_state duckdb_pending_execute_task(duckdb_pending_result pending_result) {
return duckdb_ext_api->duckdb_pending_execute_task(pending_result);
}
static duckdb_pending_state duckdb_pending_execute_check_state(duckdb_pending_result pending_result) {
return duckdb_ext_api->duckdb_pending_execute_check_state(pending_result);
}
static duckdb_state duckdb_execute_pending(duckdb_pending_result pending_result, duckdb_result *out_result) {
return duckdb_ext_api->duckdb_execute_pending(pending_result, out_result);
}
static bool duckdb_pending_execution_is_finished(duckdb_pending_state pending_state) {
return duckdb_ext_api->duckdb_pending_execution_is_finished(pending_state);
}
*/
// Types
/*
static void duckdb_destroy_value(duckdb_value *value) {
return duckdb_ext_api->duckdb_destroy_value(value);
}
static duckdb_value duckdb_create_varchar(const char *text) {
return duckdb_ext_api->duckdb_create_varchar(text);
}
static duckdb_value duckdb_create_varchar_length(const char *text, idx_t length) {
return duckdb_ext_api->duckdb_create_varchar_length(text, length);
}
static duckdb_value duckdb_create_int64(int64_t val) {
return duckdb_ext_api->duckdb_create_int64(val);
}
static duckdb_value duckdb_create_struct_value(duckdb_logical_type type, duckdb_value *values) {
return duckdb_ext_api->duckdb_create_struct_value(type, values);
}
static duckdb_value duckdb_create_list_value(duckdb_logical_type type, duckdb_value *values, idx_t value_count) {
return duckdb_ext_api->duckdb_create_list_value(type, values, value_count);
}
static duckdb_value duckdb_create_array_value(duckdb_logical_type type, duckdb_value *values, idx_t value_count) {
return duckdb_ext_api->duckdb_create_array_value(type, values, value_count);
}
static char *duckdb_get_varchar(duckdb_value value) {
return duckdb_ext_api->duckdb_get_varchar(value);
}
static int64_t duckdb_get_int64(duckdb_value val) {
return duckdb_ext_api->duckdb_get_int64(val);
}
*/
func CreateLogicalType(t Type) LogicalType {
internalType := C.duckdb_type(t)
logicalType := C.duckdb_create_logical_type(internalType)
return LogicalType{unsafe.Pointer(logicalType)}
}
/*
static char *duckdb_logical_type_get_alias(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_logical_type_get_alias(type);
}
static duckdb_logical_type duckdb_create_list_type(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_create_list_type(type);
}
static duckdb_logical_type duckdb_create_array_type(duckdb_logical_type type, idx_t array_size) {
return duckdb_ext_api->duckdb_create_array_type(type, array_size);
}
static duckdb_logical_type duckdb_create_map_type(duckdb_logical_type key_type, duckdb_logical_type value_type) {
return duckdb_ext_api->duckdb_create_map_type(key_type, value_type);
}
static duckdb_logical_type duckdb_create_union_type(duckdb_logical_type *member_types, const char **member_names,
idx_t member_count) {
return duckdb_ext_api->duckdb_create_union_type(member_types, member_names, member_count);
}
static duckdb_logical_type duckdb_create_struct_type(duckdb_logical_type *member_types, const char **member_names,
idx_t member_count) {
return duckdb_ext_api->duckdb_create_struct_type(member_types, member_names, member_count);
}
static duckdb_logical_type duckdb_create_enum_type(const char **member_names, idx_t member_count) {
return duckdb_ext_api->duckdb_create_enum_type(member_names, member_count);
}
static duckdb_logical_type duckdb_create_decimal_type(uint8_t width, uint8_t scale) {
return duckdb_ext_api->duckdb_create_decimal_type(width, scale);
}
static duckdb_type duckdb_get_type_id(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_get_type_id(type);
}
static uint8_t duckdb_decimal_width(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_decimal_width(type);
}
static uint8_t duckdb_decimal_scale(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_decimal_scale(type);
}
static duckdb_type duckdb_decimal_internal_type(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_decimal_internal_type(type);
}
static duckdb_type duckdb_enum_internal_type(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_enum_internal_type(type);
}
static uint32_t duckdb_enum_dictionary_size(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_enum_dictionary_size(type);
}
static char *duckdb_enum_dictionary_value(duckdb_logical_type type, idx_t index) {
return duckdb_ext_api->duckdb_enum_dictionary_value(type, index);
}
static duckdb_logical_type duckdb_list_type_child_type(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_list_type_child_type(type);
}
static duckdb_logical_type duckdb_array_type_child_type(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_array_type_child_type(type);
}
static idx_t duckdb_array_type_array_size(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_array_type_array_size(type);
}
static duckdb_logical_type duckdb_map_type_key_type(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_map_type_key_type(type);
}
static duckdb_logical_type duckdb_map_type_value_type(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_map_type_value_type(type);
}
static idx_t duckdb_struct_type_child_count(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_struct_type_child_count(type);
}
static char *duckdb_struct_type_child_name(duckdb_logical_type type, idx_t index) {
return duckdb_ext_api->duckdb_struct_type_child_name(type, index);
}
static duckdb_logical_type duckdb_struct_type_child_type(duckdb_logical_type type, idx_t index) {
return duckdb_ext_api->duckdb_struct_type_child_type(type, index);
}
static idx_t duckdb_union_type_member_count(duckdb_logical_type type) {
return duckdb_ext_api->duckdb_union_type_member_count(type);
}
static char *duckdb_union_type_member_name(duckdb_logical_type type, idx_t index) {
return duckdb_ext_api->duckdb_union_type_member_name(type, index);
}
static duckdb_logical_type duckdb_union_type_member_type(duckdb_logical_type type, idx_t index) {
return duckdb_ext_api->duckdb_union_type_member_type(type, index);
}
*/
func DestroyLogicalType(t *LogicalType) {
data := t.data()
C.duckdb_destroy_logical_type(&data)
t.Ptr = nil
}
// Data chunk
//func FetchChunk(result Result) DataChunk {
// chunk := C.duckdb_fetch_chunk(result.data)
// return DataChunk{}
//}
//
//func CreateDataChunk(types []LogicalType, count uint64) DataChunk {
// var dummy C.duckdb_logical_type
// size := C.size_t(unsafe.Sizeof(dummy))
//
// ptr := unsafe.Pointer(C.malloc(C.size_t(count) * size))
// slice := (*[1 << 30]C.duckdb_logical_type)(ptr)[:count:count]
//
// for k, t := range types {
// slice[k] = t.c
// }
//
// typesPtr := (*C.duckdb_logical_type)(ptr)
// return DataChunk{C.duckdb_create_data_chunk(typesPtr, C.idx_t(count))}
//}
//
//func DestroyDataChunk(chunk *DataChunk) {
// C.duckdb_destroy_data_chunk(&chunk.c)
//}
//
//func DataChunkReset(chunk DataChunk) {
// C.duckdb_data_chunk_reset(chunk.c)
//}
//
//func DataChunkGetColumnCount(chunk DataChunk) uint64 {
// return uint64(C.duckdb_data_chunk_get_column_count(chunk.c))
//}
func DataChunkGetVector(chunk DataChunk, colIdx uint64) Vector {
v := C.duckdb_data_chunk_get_vector(chunk.data(), C.idx_t(colIdx))
return Vector{unsafe.Pointer(v)}
}
func DataChunkGetSize(chunk DataChunk) uint64 {
size := C.duckdb_data_chunk_get_size(chunk.data())
return uint64(size)
}
//func DataChunkSetSize(chunk DataChunk, size uint64) {
// C.duckdb_data_chunk_set_size(chunk.c, C.idx_t(size))
//}
// Vector
//func VectorGetColumnType(v Vector) LogicalType {
// ptr := C.duckdb_vector(v)
// return LogicalType{C.duckdb_vector_get_column_type(ptr)}
//}
func VectorGetData(v Vector) unsafe.Pointer {
data := C.duckdb_vector_get_data(v.data())
return unsafe.Pointer(data)
}
func VectorGetValidity(v Vector) unsafe.Pointer {
mask := C.duckdb_vector_get_validity(v.data())
return unsafe.Pointer(mask)
}
func VectorEnsureValidityWritable(v Vector) {
C.duckdb_vector_ensure_validity_writable(v.data())
}
// String vector
/*
static void duckdb_vector_assign_string_element(duckdb_vector vector, idx_t index, const char *str) {
return duckdb_ext_api->duckdb_vector_assign_string_element(vector, index, str);
}
static void duckdb_vector_assign_string_element_len(duckdb_vector vector, idx_t index, const char *str, idx_t str_len) {
return duckdb_ext_api->duckdb_vector_assign_string_element_len(vector, index, str, str_len);
}
*/
// List vector
/*
static duckdb_vector duckdb_list_vector_get_child(duckdb_vector vector) {
return duckdb_ext_api->duckdb_list_vector_get_child(vector);
}
static idx_t duckdb_list_vector_get_size(duckdb_vector vector) {
return duckdb_ext_api->duckdb_list_vector_get_size(vector);
}
static duckdb_state duckdb_list_vector_set_size(duckdb_vector vector, idx_t size) {
return duckdb_ext_api->duckdb_list_vector_set_size(vector, size);
}
static duckdb_state duckdb_list_vector_reserve(duckdb_vector vector, idx_t required_capacity) {
return duckdb_ext_api->duckdb_list_vector_reserve(vector, required_capacity);
}
*/
// Struct vector
/*
static duckdb_vector duckdb_struct_vector_get_child(duckdb_vector vector, idx_t index) {
return duckdb_ext_api->duckdb_struct_vector_get_child(vector, index);
}
*/
// Array vector
/*
static duckdb_vector duckdb_array_vector_get_child(duckdb_vector vector) {
return duckdb_ext_api->duckdb_array_vector_get_child(vector);
}
*/
// Validity
func ValidityRowIsValid(mask unsafe.Pointer, rowIdx uint64) bool {
return bool(C.duckdb_validity_row_is_valid((*C.uint64_t)(mask), C.idx_t(rowIdx)))
}
//func ValiditySetRowValidity(mask unsafe.Pointer, rowIdx uint64, valid bool) {
// C.duckdb_validity_set_row_validity((*C.uint64_t)(mask), C.idx_t(rowIdx), C.bool(valid))
//}
func ValiditySetRowInvalid(mask unsafe.Pointer, rowIdx uint64) {
C.duckdb_validity_set_row_invalid((*C.uint64_t)(mask), C.idx_t(rowIdx))
}
//func ValiditySetRowValid(mask unsafe.Pointer, rowIdx uint64) {
// C.duckdb_validity_set_row_valid((*C.uint64_t)(mask), C.idx_t(rowIdx))
//}
// Scalar function
func CreateScalarFunction() ScalarFunction {
data := C.duckdb_create_scalar_function()
return ScalarFunction{unsafe.Pointer(data)}
}
func DestroyScalarFunction(f *ScalarFunction) {
data := f.data()
C.duckdb_destroy_scalar_function(&data)
f.Ptr = nil
}
func ScalarFunctionSetName(f ScalarFunction, name string) {
cName := C.CString(name)
defer C.duckdb_free(unsafe.Pointer(cName))
C.duckdb_scalar_function_set_name(f.data(), cName)
}
func ScalarFunctionAddParameter(f ScalarFunction, t LogicalType) {
C.duckdb_scalar_function_add_parameter(f.data(), t.data())
}
func ScalarFunctionSetReturnType(f ScalarFunction, t LogicalType) {
C.duckdb_scalar_function_set_return_type(f.data(), t.data())
}
//func ScalarFunctionSetExtraInfo(f ScalarFunction, info unsafe.Pointer, deleteFun unsafe.Pointer) {
// df := C.duckdb_delete_callback_t(deleteFun)
// C.duckdb_scalar_function_set_extra_info(f.c, info, df)
//}
func ScalarFunctionSetFunction(f ScalarFunction, scalarFun unsafe.Pointer) {
sf := C.duckdb_scalar_function_t(scalarFun)
C.duckdb_scalar_function_set_function(f.data(), sf)
}
func RegisterScalarFunction(c Connection, f ScalarFunction) State {
return State(C.duckdb_register_scalar_function(c.data(), f.data()))
}
// Table function
/*
static duckdb_table_function duckdb_create_table_function() {
return duckdb_ext_api->duckdb_create_table_function();
}
static void duckdb_destroy_table_function(duckdb_table_function *table_function) {
return duckdb_ext_api->duckdb_destroy_table_function(table_function);
}
static void duckdb_table_function_set_name(duckdb_table_function table_function, const char *name) {
return duckdb_ext_api->duckdb_table_function_set_name(table_function, name);
}
static void duckdb_table_function_add_parameter(duckdb_table_function table_function, duckdb_logical_type type) {
return duckdb_ext_api->duckdb_table_function_add_parameter(table_function, type);
}
static void duckdb_table_function_add_named_parameter(duckdb_table_function table_function, const char *name,
duckdb_logical_type type) {
return duckdb_ext_api->duckdb_table_function_add_named_parameter(table_function, name, type);
}
static void duckdb_table_function_set_extra_info(duckdb_table_function table_function, void *extra_info,
duckdb_delete_callback_t destroy) {
return duckdb_ext_api->duckdb_table_function_set_extra_info(table_function, extra_info, destroy);
}
static void duckdb_table_function_set_bind(duckdb_table_function table_function, duckdb_table_function_bind_t bind) {
return duckdb_ext_api->duckdb_table_function_set_bind(table_function, bind);
}
static void duckdb_table_function_set_init(duckdb_table_function table_function, duckdb_table_function_init_t init) {
return duckdb_ext_api->duckdb_table_function_set_init(table_function, init);
}
static void duckdb_table_function_set_local_init(duckdb_table_function table_function,
duckdb_table_function_init_t init) {
return duckdb_ext_api->duckdb_table_function_set_local_init(table_function, init);
}
static void duckdb_table_function_set_function(duckdb_table_function table_function, duckdb_table_function_t function) {
return duckdb_ext_api->duckdb_table_function_set_function(table_function, function);
}
static void duckdb_table_function_supports_projection_pushdown(duckdb_table_function table_function, bool pushdown) {
return duckdb_ext_api->duckdb_table_function_supports_projection_pushdown(table_function, pushdown);
}
static duckdb_state duckdb_register_table_function(duckdb_connection con, duckdb_table_function function) {
return duckdb_ext_api->duckdb_register_table_function(con, function);
}
*/
// Bind
/*
static void *duckdb_bind_get_extra_info(duckdb_bind_info info) {
return duckdb_ext_api->duckdb_bind_get_extra_info(info);
}
static void duckdb_bind_add_result_column(duckdb_bind_info info, const char *name, duckdb_logical_type type) {
return duckdb_ext_api->duckdb_bind_add_result_column(info, name, type);
}
static idx_t duckdb_bind_get_parameter_count(duckdb_bind_info info) {
return duckdb_ext_api->duckdb_bind_get_parameter_count(info);
}
static duckdb_value duckdb_bind_get_parameter(duckdb_bind_info info, idx_t index) {
return duckdb_ext_api->duckdb_bind_get_parameter(info, index);
}
static duckdb_value duckdb_bind_get_named_parameter(duckdb_bind_info info, const char *name) {
return duckdb_ext_api->duckdb_bind_get_named_parameter(info, name);
}
static void duckdb_bind_set_bind_data(duckdb_bind_info info, void *bind_data, duckdb_delete_callback_t destroy) {
return duckdb_ext_api->duckdb_bind_set_bind_data(info, bind_data, destroy);
}
static void duckdb_bind_set_cardinality(duckdb_bind_info info, idx_t cardinality, bool is_exact) {
return duckdb_ext_api->duckdb_bind_set_cardinality(info, cardinality, is_exact);
}
static void duckdb_bind_set_error(duckdb_bind_info info, const char *error) {
return duckdb_ext_api->duckdb_bind_set_error(info, error);
}
*/
// Init
/*
static void *duckdb_init_get_extra_info(duckdb_init_info info) {
return duckdb_ext_api->duckdb_init_get_extra_info(info);
}
static void *duckdb_init_get_bind_data(duckdb_init_info info) {
return duckdb_ext_api->duckdb_init_get_bind_data(info);
}
static void duckdb_init_set_init_data(duckdb_init_info info, void *init_data, duckdb_delete_callback_t destroy) {
return duckdb_ext_api->duckdb_init_set_init_data(info, init_data, destroy);
}
static idx_t duckdb_init_get_column_count(duckdb_init_info info) {
return duckdb_ext_api->duckdb_init_get_column_count(info);
}
static idx_t duckdb_init_get_column_index(duckdb_init_info info, idx_t column_index) {
return duckdb_ext_api->duckdb_init_get_column_index(info, column_index);
}
static void duckdb_init_set_max_threads(duckdb_init_info info, idx_t max_threads) {
return duckdb_ext_api->duckdb_init_set_max_threads(info, max_threads);
}
static void duckdb_init_set_error(duckdb_init_info info, const char *error) {
return duckdb_ext_api->duckdb_init_set_error(info, error);
}
*/
// Function
/*
static void *duckdb_function_get_extra_info(duckdb_function_info info) {
return duckdb_ext_api->duckdb_function_get_extra_info(info);
}
static void *duckdb_function_get_bind_data(duckdb_function_info info) {
return duckdb_ext_api->duckdb_function_get_bind_data(info);
}
static void *duckdb_function_get_init_data(duckdb_function_info info) {
return duckdb_ext_api->duckdb_function_get_init_data(info);
}
static void *duckdb_function_get_local_init_data(duckdb_function_info info) {
return duckdb_ext_api->duckdb_function_get_local_init_data(info);
}
static void duckdb_function_set_error(duckdb_function_info info, const char *error) {
return duckdb_ext_api->duckdb_function_set_error(info, error);
}
*/
// Replacement scan
/*
static void duckdb_add_replacement_scan(duckdb_database db, duckdb_replacement_callback_t replacement, void *extra_data,
duckdb_delete_callback_t delete_callback) {
return duckdb_ext_api->duckdb_add_replacement_scan(db, replacement, extra_data, delete_callback);
}
static void duckdb_replacement_scan_set_function_name(duckdb_replacement_scan_info info, const char *function_name) {
return duckdb_ext_api->duckdb_replacement_scan_set_function_name(info, function_name);
}
static void duckdb_replacement_scan_add_parameter(duckdb_replacement_scan_info info, duckdb_value parameter) {
return duckdb_ext_api->duckdb_replacement_scan_add_parameter(info, parameter);
}
static void duckdb_replacement_scan_set_error(duckdb_replacement_scan_info info, const char *error) {
return duckdb_ext_api->duckdb_replacement_scan_set_error(info, error);
}
*/
// Appender
/*
static duckdb_state duckdb_appender_create(duckdb_connection connection, const char *schema, const char *table,
duckdb_appender *out_appender) {
return duckdb_ext_api->duckdb_appender_create(connection, schema, table, out_appender);
}
static idx_t duckdb_appender_column_count(duckdb_appender appender) {
return duckdb_ext_api->duckdb_appender_column_count(appender);
}
static duckdb_logical_type duckdb_appender_column_type(duckdb_appender appender, idx_t col_idx) {
return duckdb_ext_api->duckdb_appender_column_type(appender, col_idx);
}
static const char *duckdb_appender_error(duckdb_appender appender) {
return duckdb_ext_api->duckdb_appender_error(appender);
}
static duckdb_state duckdb_appender_flush(duckdb_appender appender) {
return duckdb_ext_api->duckdb_appender_flush(appender);
}
static duckdb_state duckdb_appender_close(duckdb_appender appender) {
return duckdb_ext_api->duckdb_appender_close(appender);
}
static duckdb_state duckdb_appender_destroy(duckdb_appender *appender) {
return duckdb_ext_api->duckdb_appender_destroy(appender);
}
static duckdb_state duckdb_appender_begin_row(duckdb_appender appender) {
return duckdb_ext_api->duckdb_appender_begin_row(appender);
}
static duckdb_state duckdb_appender_end_row(duckdb_appender appender) {
return duckdb_ext_api->duckdb_appender_end_row(appender);
}
static duckdb_state duckdb_append_default(duckdb_appender appender) {
return duckdb_ext_api->duckdb_append_default(appender);
}
static duckdb_state duckdb_append_bool(duckdb_appender appender, bool value) {
return duckdb_ext_api->duckdb_append_bool(appender, value);
}
static duckdb_state duckdb_append_int8(duckdb_appender appender, int8_t value) {
return duckdb_ext_api->duckdb_append_int8(appender, value);
}
static duckdb_state duckdb_append_int16(duckdb_appender appender, int16_t value) {
return duckdb_ext_api->duckdb_append_int16(appender, value);
}
static duckdb_state duckdb_append_int32(duckdb_appender appender, int32_t value) {
return duckdb_ext_api->duckdb_append_int32(appender, value);
}
static duckdb_state duckdb_append_int64(duckdb_appender appender, int64_t value) {
return duckdb_ext_api->duckdb_append_int64(appender, value);
}
static duckdb_state duckdb_append_hugeint(duckdb_appender appender, duckdb_hugeint value) {
return duckdb_ext_api->duckdb_append_hugeint(appender, value);
}
static duckdb_state duckdb_append_uint8(duckdb_appender appender, uint8_t value) {