-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkuzu.h
1569 lines (1513 loc) · 68.9 KB
/
kuzu.h
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
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <time.h>
#ifdef _WIN32
#include <windows.h>
#endif
/* Export header from common/api.h */
// Helpers
#if defined _WIN32 || defined __CYGWIN__
#define KUZU_HELPER_DLL_IMPORT __declspec(dllimport)
#define KUZU_HELPER_DLL_EXPORT __declspec(dllexport)
#define KUZU_HELPER_DLL_LOCAL
#define KUZU_HELPER_DEPRECATED __declspec(deprecated)
#else
#define KUZU_HELPER_DLL_IMPORT __attribute__((visibility("default")))
#define KUZU_HELPER_DLL_EXPORT __attribute__((visibility("default")))
#define KUZU_HELPER_DLL_LOCAL __attribute__((visibility("hidden")))
#define KUZU_HELPER_DEPRECATED __attribute__((__deprecated__))
#endif
#ifdef KUZU_STATIC_DEFINE
#define KUZU_API
#define KUZU_NO_EXPORT
#else
#ifndef KUZU_API
#ifdef KUZU_EXPORTS
/* We are building this library */
#define KUZU_API KUZU_HELPER_DLL_EXPORT
#else
/* We are using this library */
#define KUZU_API KUZU_HELPER_DLL_IMPORT
#endif
#endif
#endif
#ifndef KUZU_DEPRECATED
#define KUZU_DEPRECATED KUZU_HELPER_DEPRECATED
#endif
#ifndef KUZU_DEPRECATED_EXPORT
#define KUZU_DEPRECATED_EXPORT KUZU_API KUZU_DEPRECATED
#endif
/* end export header */
// The Arrow C data interface.
// https://arrow.apache.org/docs/format/CDataInterface.html
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef ARROW_C_DATA_INTERFACE
#define ARROW_C_DATA_INTERFACE
#define ARROW_FLAG_DICTIONARY_ORDERED 1
#define ARROW_FLAG_NULLABLE 2
#define ARROW_FLAG_MAP_KEYS_SORTED 4
struct ArrowSchema {
// Array type description
const char* format;
const char* name;
const char* metadata;
int64_t flags;
int64_t n_children;
struct ArrowSchema** children;
struct ArrowSchema* dictionary;
// Release callback
void (*release)(struct ArrowSchema*);
// Opaque producer-specific data
void* private_data;
};
struct ArrowArray {
// Array data description
int64_t length;
int64_t null_count;
int64_t offset;
int64_t n_buffers;
int64_t n_children;
const void** buffers;
struct ArrowArray** children;
struct ArrowArray* dictionary;
// Release callback
void (*release)(struct ArrowArray*);
// Opaque producer-specific data
void* private_data;
};
#endif // ARROW_C_DATA_INTERFACE
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
#define KUZU_C_API extern "C" KUZU_API
#else
#define KUZU_C_API KUZU_API
#endif
/**
* @brief Stores runtime configuration for creating or opening a Database
*/
typedef struct {
// bufferPoolSize Max size of the buffer pool in bytes.
// The larger the buffer pool, the more data from the database files is kept in memory,
// reducing the amount of File I/O
uint64_t buffer_pool_size;
// The maximum number of threads to use during query execution
uint64_t max_num_threads;
// Whether or not to compress data on-disk for supported types
bool enable_compression;
// If true, open the database in read-only mode. No write transaction is allowed on the Database
// object. If false, open the database read-write.
bool read_only;
// The maximum size of the database in bytes. Note that this is introduced temporarily for now
// to get around with the default 8TB mmap address space limit under some environment. This
// will be removed once we implemente a better solution later. The value is default to 1 << 43
// (8TB) under 64-bit environment and 1GB under 32-bit one (see `DEFAULT_VM_REGION_MAX_SIZE`).
uint64_t max_db_size;
// If true, the database will automatically checkpoint when the size of
// the WAL file exceeds the checkpoint threshold.
bool auto_checkpoint;
// The threshold of the WAL file size in bytes. When the size of the
// WAL file exceeds this threshold, the database will checkpoint if auto_checkpoint is true.
uint64_t checkpoint_threshold;
} kuzu_system_config;
/**
* @brief kuzu_database manages all database components.
*/
typedef struct {
void* _database;
} kuzu_database;
/**
* @brief kuzu_connection is used to interact with a Database instance. Each connection is
* thread-safe. Multiple connections can connect to the same Database instance in a multi-threaded
* environment.
*/
typedef struct {
void* _connection;
} kuzu_connection;
/**
* @brief kuzu_prepared_statement is a parameterized query which can avoid planning the same query
* for repeated execution.
*/
typedef struct {
void* _prepared_statement;
void* _bound_values;
} kuzu_prepared_statement;
/**
* @brief kuzu_query_result stores the result of a query.
*/
typedef struct {
void* _query_result;
bool _is_owned_by_cpp;
} kuzu_query_result;
/**
* @brief kuzu_flat_tuple stores a vector of values.
*/
typedef struct {
void* _flat_tuple;
bool _is_owned_by_cpp;
} kuzu_flat_tuple;
/**
* @brief kuzu_logical_type is the kuzu internal representation of data types.
*/
typedef struct {
void* _data_type;
} kuzu_logical_type;
/**
* @brief kuzu_value is used to represent a value with any kuzu internal dataType.
*/
typedef struct {
void* _value;
bool _is_owned_by_cpp;
} kuzu_value;
/**
* @brief kuzu internal internal_id type which stores the table_id and offset of a node/rel.
*/
typedef struct {
uint64_t table_id;
uint64_t offset;
} kuzu_internal_id_t;
/**
* @brief kuzu internal date type which stores the number of days since 1970-01-01 00:00:00 UTC.
*/
typedef struct {
// Days since 1970-01-01 00:00:00 UTC.
int32_t days;
} kuzu_date_t;
/**
* @brief kuzu internal timestamp_ns type which stores the number of nanoseconds since 1970-01-01
* 00:00:00 UTC.
*/
typedef struct {
// Nanoseconds since 1970-01-01 00:00:00 UTC.
int64_t value;
} kuzu_timestamp_ns_t;
/**
* @brief kuzu internal timestamp_ms type which stores the number of milliseconds since 1970-01-01
* 00:00:00 UTC.
*/
typedef struct {
// Milliseconds since 1970-01-01 00:00:00 UTC.
int64_t value;
} kuzu_timestamp_ms_t;
/**
* @brief kuzu internal timestamp_sec_t type which stores the number of seconds since 1970-01-01
* 00:00:00 UTC.
*/
typedef struct {
// Seconds since 1970-01-01 00:00:00 UTC.
int64_t value;
} kuzu_timestamp_sec_t;
/**
* @brief kuzu internal timestamp_tz type which stores the number of microseconds since 1970-01-01
* with timezone 00:00:00 UTC.
*/
typedef struct {
// Microseconds since 1970-01-01 00:00:00 UTC.
int64_t value;
} kuzu_timestamp_tz_t;
/**
* @brief kuzu internal timestamp type which stores the number of microseconds since 1970-01-01
* 00:00:00 UTC.
*/
typedef struct {
// Microseconds since 1970-01-01 00:00:00 UTC.
int64_t value;
} kuzu_timestamp_t;
/**
* @brief kuzu internal interval type which stores the months, days and microseconds.
*/
typedef struct {
int32_t months;
int32_t days;
int64_t micros;
} kuzu_interval_t;
/**
* @brief kuzu_query_summary stores the execution time, plan, compiling time and query options of a
* query.
*/
typedef struct {
void* _query_summary;
} kuzu_query_summary;
typedef struct {
uint64_t low;
int64_t high;
} kuzu_int128_t;
/**
* @brief enum class for kuzu internal dataTypes.
*/
typedef enum {
KUZU_ANY = 0,
KUZU_NODE = 10,
KUZU_REL = 11,
KUZU_RECURSIVE_REL = 12,
// SERIAL is a special data type that is used to represent a sequence of INT64 values that are
// incremented by 1 starting from 0.
KUZU_SERIAL = 13,
// fixed size types
KUZU_BOOL = 22,
KUZU_INT64 = 23,
KUZU_INT32 = 24,
KUZU_INT16 = 25,
KUZU_INT8 = 26,
KUZU_UINT64 = 27,
KUZU_UINT32 = 28,
KUZU_UINT16 = 29,
KUZU_UINT8 = 30,
KUZU_INT128 = 31,
KUZU_DOUBLE = 32,
KUZU_FLOAT = 33,
KUZU_DATE = 34,
KUZU_TIMESTAMP = 35,
KUZU_TIMESTAMP_SEC = 36,
KUZU_TIMESTAMP_MS = 37,
KUZU_TIMESTAMP_NS = 38,
KUZU_TIMESTAMP_TZ = 39,
KUZU_INTERVAL = 40,
KUZU_DECIMAL = 41,
KUZU_INTERNAL_ID = 42,
// variable size types
KUZU_STRING = 50,
KUZU_BLOB = 51,
KUZU_LIST = 52,
KUZU_ARRAY = 53,
KUZU_STRUCT = 54,
KUZU_MAP = 55,
KUZU_UNION = 56,
KUZU_POINTER = 58,
KUZU_UUID = 59
} kuzu_data_type_id;
/**
* @brief enum class for kuzu function return state.
*/
typedef enum { KuzuSuccess = 0, KuzuError = 1 } kuzu_state;
// Database
/**
* @brief Allocates memory and creates a kuzu database instance at database_path with
* bufferPoolSize=buffer_pool_size. Caller is responsible for calling kuzu_database_destroy() to
* release the allocated memory.
* @param database_path The path to the database.
* @param system_config The runtime configuration for creating or opening the database.
* @param[out] out_database The output parameter that will hold the database instance.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_database_init(const char* database_path,
kuzu_system_config system_config, kuzu_database* out_database);
/**
* @brief Destroys the kuzu database instance and frees the allocated memory.
* @param database The database instance to destroy.
*/
KUZU_C_API void kuzu_database_destroy(kuzu_database* database);
KUZU_C_API kuzu_system_config kuzu_default_system_config();
// Connection
/**
* @brief Allocates memory and creates a connection to the database. Caller is responsible for
* calling kuzu_connection_destroy() to release the allocated memory.
* @param database The database instance to connect to.
* @param[out] out_connection The output parameter that will hold the connection instance.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_connection_init(kuzu_database* database,
kuzu_connection* out_connection);
/**
* @brief Destroys the connection instance and frees the allocated memory.
* @param connection The connection instance to destroy.
*/
KUZU_C_API void kuzu_connection_destroy(kuzu_connection* connection);
/**
* @brief Sets the maximum number of threads to use for executing queries.
* @param connection The connection instance to set max number of threads for execution.
* @param num_threads The maximum number of threads to use for executing queries.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_connection_set_max_num_thread_for_exec(kuzu_connection* connection,
uint64_t num_threads);
/**
* @brief Returns the maximum number of threads of the connection to use for executing queries.
* @param connection The connection instance to return max number of threads for execution.
* @param[out] out_result The output parameter that will hold the maximum number of threads to use
* for executing queries.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_connection_get_max_num_thread_for_exec(kuzu_connection* connection,
uint64_t* out_result);
/**
* @brief Executes the given query and returns the result.
* @param connection The connection instance to execute the query.
* @param query The query to execute.
* @param[out] out_query_result The output parameter that will hold the result of the query.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_connection_query(kuzu_connection* connection, const char* query,
kuzu_query_result* out_query_result);
/**
* @brief Prepares the given query and returns the prepared statement.
* @param connection The connection instance to prepare the query.
* @param query The query to prepare.
* @param[out] out_prepared_statement The output parameter that will hold the prepared statement.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_connection_prepare(kuzu_connection* connection, const char* query,
kuzu_prepared_statement* out_prepared_statement);
/**
* @brief Executes the prepared_statement using connection.
* @param connection The connection instance to execute the prepared_statement.
* @param prepared_statement The prepared statement to execute.
* @param[out] out_query_result The output parameter that will hold the result of the query.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_connection_execute(kuzu_connection* connection,
kuzu_prepared_statement* prepared_statement, kuzu_query_result* out_query_result);
/**
* @brief Interrupts the current query execution in the connection.
* @param connection The connection instance to interrupt.
*/
KUZU_C_API void kuzu_connection_interrupt(kuzu_connection* connection);
/**
* @brief Sets query timeout value in milliseconds for the connection.
* @param connection The connection instance to set query timeout value.
* @param timeout_in_ms The timeout value in milliseconds.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_connection_set_query_timeout(kuzu_connection* connection,
uint64_t timeout_in_ms);
// PreparedStatement
/**
* @brief Destroys the prepared statement instance and frees the allocated memory.
* @param prepared_statement The prepared statement instance to destroy.
*/
KUZU_C_API void kuzu_prepared_statement_destroy(kuzu_prepared_statement* prepared_statement);
/**
* @return the query is prepared successfully or not.
*/
KUZU_C_API bool kuzu_prepared_statement_is_success(kuzu_prepared_statement* prepared_statement);
/**
* @param prepared_statement The prepared statement instance.
* @return the error message if the statement is not prepared successfully.
*/
KUZU_C_API char* kuzu_prepared_statement_get_error_message(
kuzu_prepared_statement* prepared_statement);
/**
* @brief Binds the given boolean value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The boolean value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_bool(kuzu_prepared_statement* prepared_statement,
const char* param_name, bool value);
/**
* @brief Binds the given int64_t value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The int64_t value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_int64(
kuzu_prepared_statement* prepared_statement, const char* param_name, int64_t value);
/**
* @brief Binds the given int32_t value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The int32_t value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_int32(
kuzu_prepared_statement* prepared_statement, const char* param_name, int32_t value);
/**
* @brief Binds the given int16_t value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The int16_t value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_int16(
kuzu_prepared_statement* prepared_statement, const char* param_name, int16_t value);
/**
* @brief Binds the given int8_t value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The int8_t value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_int8(kuzu_prepared_statement* prepared_statement,
const char* param_name, int8_t value);
/**
* @brief Binds the given uint64_t value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The uint64_t value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_uint64(
kuzu_prepared_statement* prepared_statement, const char* param_name, uint64_t value);
/**
* @brief Binds the given uint32_t value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The uint32_t value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_uint32(
kuzu_prepared_statement* prepared_statement, const char* param_name, uint32_t value);
/**
* @brief Binds the given uint16_t value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The uint16_t value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_uint16(
kuzu_prepared_statement* prepared_statement, const char* param_name, uint16_t value);
/**
* @brief Binds the given int8_t value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The int8_t value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_uint8(
kuzu_prepared_statement* prepared_statement, const char* param_name, uint8_t value);
/**
* @brief Binds the given double value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The double value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_double(
kuzu_prepared_statement* prepared_statement, const char* param_name, double value);
/**
* @brief Binds the given float value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The float value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_float(
kuzu_prepared_statement* prepared_statement, const char* param_name, float value);
/**
* @brief Binds the given date value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The date value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_date(kuzu_prepared_statement* prepared_statement,
const char* param_name, kuzu_date_t value);
/**
* @brief Binds the given timestamp_ns value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The timestamp_ns value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_timestamp_ns(
kuzu_prepared_statement* prepared_statement, const char* param_name, kuzu_timestamp_ns_t value);
/**
* @brief Binds the given timestamp_sec value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The timestamp_sec value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_timestamp_sec(
kuzu_prepared_statement* prepared_statement, const char* param_name,
kuzu_timestamp_sec_t value);
/**
* @brief Binds the given timestamp_tz value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The timestamp_tz value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_timestamp_tz(
kuzu_prepared_statement* prepared_statement, const char* param_name, kuzu_timestamp_tz_t value);
/**
* @brief Binds the given timestamp_ms value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The timestamp_ms value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_timestamp_ms(
kuzu_prepared_statement* prepared_statement, const char* param_name, kuzu_timestamp_ms_t value);
/**
* @brief Binds the given timestamp value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The timestamp value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_timestamp(
kuzu_prepared_statement* prepared_statement, const char* param_name, kuzu_timestamp_t value);
/**
* @brief Binds the given interval value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The interval value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_interval(
kuzu_prepared_statement* prepared_statement, const char* param_name, kuzu_interval_t value);
/**
* @brief Binds the given string value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The string value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_string(
kuzu_prepared_statement* prepared_statement, const char* param_name, const char* value);
/**
* @brief Binds the given kuzu value to the given parameter name in the prepared statement.
* @param prepared_statement The prepared statement instance to bind the value.
* @param param_name The parameter name to bind the value.
* @param value The kuzu value to bind.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_prepared_statement_bind_value(
kuzu_prepared_statement* prepared_statement, const char* param_name, kuzu_value* value);
// QueryResult
/**
* @brief Destroys the given query result instance.
* @param query_result The query result instance to destroy.
*/
KUZU_C_API void kuzu_query_result_destroy(kuzu_query_result* query_result);
/**
* @brief Returns true if the query is executed successful, false otherwise.
* @param query_result The query result instance to check.
*/
KUZU_C_API bool kuzu_query_result_is_success(kuzu_query_result* query_result);
/**
* @brief Returns the error message if the query is failed.
* @param query_result The query result instance to check and return error message.
* @return The error message if the query has failed.
*/
KUZU_C_API char* kuzu_query_result_get_error_message(kuzu_query_result* query_result);
/**
* @brief Returns the number of columns in the query result.
* @param query_result The query result instance to return.
*/
KUZU_C_API uint64_t kuzu_query_result_get_num_columns(kuzu_query_result* query_result);
/**
* @brief Returns the column name at the given index.
* @param query_result The query result instance to return.
* @param index The index of the column to return name.
* @param[out] out_column_name The output parameter that will hold the column name.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_query_result_get_column_name(kuzu_query_result* query_result,
uint64_t index, char** out_column_name);
/**
* @brief Returns the data type of the column at the given index.
* @param query_result The query result instance to return.
* @param index The index of the column to return data type.
* @param[out] out_column_data_type The output parameter that will hold the column data type.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_query_result_get_column_data_type(kuzu_query_result* query_result,
uint64_t index, kuzu_logical_type* out_column_data_type);
/**
* @brief Returns the number of tuples in the query result.
* @param query_result The query result instance to return.
*/
KUZU_C_API uint64_t kuzu_query_result_get_num_tuples(kuzu_query_result* query_result);
/**
* @brief Returns the query summary of the query result.
* @param query_result The query result instance to return.
* @param[out] out_query_summary The output parameter that will hold the query summary.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_query_result_get_query_summary(kuzu_query_result* query_result,
kuzu_query_summary* out_query_summary);
/**
* @brief Returns true if we have not consumed all tuples in the query result, false otherwise.
* @param query_result The query result instance to check.
*/
KUZU_C_API bool kuzu_query_result_has_next(kuzu_query_result* query_result);
/**
* @brief Returns the next tuple in the query result. Throws an exception if there is no more tuple.
* Note that to reduce resource allocation, all calls to kuzu_query_result_get_next() reuse the same
* FlatTuple object. Since its contents will be overwritten, please complete processing a FlatTuple
* or make a copy of its data before calling kuzu_query_result_get_next() again.
* @param query_result The query result instance to return.
* @param[out] out_flat_tuple The output parameter that will hold the next tuple.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_query_result_get_next(kuzu_query_result* query_result,
kuzu_flat_tuple* out_flat_tuple);
/**
* @brief Returns true if we have not consumed all query results, false otherwise. Use this function
* for loop results of multiple query statements
* @param query_result The query result instance to check.
*/
KUZU_C_API bool kuzu_query_result_has_next_query_result(kuzu_query_result* query_result);
/**
* @brief Returns the next query result. Use this function to loop multiple query statements'
* results.
* @param query_result The query result instance to return.
* @param[out] out_next_query_result The output parameter that will hold the next query result.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_query_result_get_next_query_result(kuzu_query_result* query_result,
kuzu_query_result* out_next_query_result);
/**
* @brief Returns the query result as a string.
* @param query_result The query result instance to return.
* @return The query result as a string.
*/
KUZU_C_API char* kuzu_query_result_to_string(kuzu_query_result* query_result);
/**
* @brief Resets the iterator of the query result to the beginning of the query result.
* @param query_result The query result instance to reset iterator.
*/
KUZU_C_API void kuzu_query_result_reset_iterator(kuzu_query_result* query_result);
/**
* @brief Returns the query result's schema as ArrowSchema.
* @param query_result The query result instance to return.
* @param[out] out_schema The output parameter that will hold the datatypes of the columns as an
* arrow schema.
* @return The state indicating the success or failure of the operation.
*
* It is the caller's responsibility to call the release function to release the underlying data
*/
KUZU_C_API kuzu_state kuzu_query_result_get_arrow_schema(kuzu_query_result* query_result,
struct ArrowSchema* out_schema);
/**
* @brief Returns the next chunk of the query result as ArrowArray.
* @param query_result The query result instance to return.
* @param chunk_size The number of tuples to return in the chunk.
* @param[out] out_arrow_array The output parameter that will hold the arrow array representation of
* the query result. The arrow array internally stores an arrow struct with fields for each of the
* columns.
* @return The state indicating the success or failure of the operation.
*
* It is the caller's responsibility to call the release function to release the underlying data
*/
KUZU_C_API kuzu_state kuzu_query_result_get_next_arrow_chunk(kuzu_query_result* query_result,
int64_t chunk_size, struct ArrowArray* out_arrow_array);
// FlatTuple
/**
* @brief Destroys the given flat tuple instance.
* @param flat_tuple The flat tuple instance to destroy.
*/
KUZU_C_API void kuzu_flat_tuple_destroy(kuzu_flat_tuple* flat_tuple);
/**
* @brief Returns the value at index of the flat tuple.
* @param flat_tuple The flat tuple instance to return.
* @param index The index of the value to return.
* @param[out] out_value The output parameter that will hold the value at index.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_flat_tuple_get_value(kuzu_flat_tuple* flat_tuple, uint64_t index,
kuzu_value* out_value);
/**
* @brief Converts the flat tuple to a string.
* @param flat_tuple The flat tuple instance to convert.
* @return The flat tuple as a string.
*/
KUZU_C_API char* kuzu_flat_tuple_to_string(kuzu_flat_tuple* flat_tuple);
// DataType
// TODO(Chang): Refactor the datatype constructor to follow the cpp way of creating dataTypes.
/**
* @brief Creates a data type instance with the given id, childType and num_elements_in_array.
* Caller is responsible for destroying the returned data type instance.
* @param id The enum type id of the datatype to create.
* @param child_type The child type of the datatype to create(only used for nested dataTypes).
* @param num_elements_in_array The number of elements in the array(only used for ARRAY).
* @param[out] out_type The output parameter that will hold the data type instance.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API void kuzu_data_type_create(kuzu_data_type_id id, kuzu_logical_type* child_type,
uint64_t num_elements_in_array, kuzu_logical_type* out_type);
/**
* @brief Creates a new data type instance by cloning the given data type instance.
* @param data_type The data type instance to clone.
* @param[out] out_type The output parameter that will hold the cloned data type instance.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API void kuzu_data_type_clone(kuzu_logical_type* data_type, kuzu_logical_type* out_type);
/**
* @brief Destroys the given data type instance.
* @param data_type The data type instance to destroy.
*/
KUZU_C_API void kuzu_data_type_destroy(kuzu_logical_type* data_type);
/**
* @brief Returns true if the given data type is equal to the other data type, false otherwise.
* @param data_type1 The first data type instance to compare.
* @param data_type2 The second data type instance to compare.
*/
KUZU_C_API bool kuzu_data_type_equals(kuzu_logical_type* data_type1, kuzu_logical_type* data_type2);
/**
* @brief Returns the enum type id of the given data type.
* @param data_type The data type instance to return.
*/
KUZU_C_API kuzu_data_type_id kuzu_data_type_get_id(kuzu_logical_type* data_type);
/**
* @brief Returns the number of elements for array.
* @param data_type The data type instance to return.
* @param[out] out_result The output parameter that will hold the number of elements in the array.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_data_type_get_num_elements_in_array(kuzu_logical_type* data_type,
uint64_t* out_result);
// Value
/**
* @brief Creates a NULL value of ANY type. Caller is responsible for destroying the returned value.
*/
KUZU_C_API kuzu_value* kuzu_value_create_null();
/**
* @brief Creates a value of the given data type. Caller is responsible for destroying the
* returned value.
* @param data_type The data type of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_null_with_data_type(kuzu_logical_type* data_type);
/**
* @brief Returns true if the given value is NULL, false otherwise.
* @param value The value instance to check.
*/
KUZU_C_API bool kuzu_value_is_null(kuzu_value* value);
/**
* @brief Sets the given value to NULL or not.
* @param value The value instance to set.
* @param is_null True if sets the value to NULL, false otherwise.
*/
KUZU_C_API void kuzu_value_set_null(kuzu_value* value, bool is_null);
/**
* @brief Creates a value of the given data type with default non-NULL value. Caller is responsible
* for destroying the returned value.
* @param data_type The data type of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_default(kuzu_logical_type* data_type);
/**
* @brief Creates a value with boolean type and the given bool value. Caller is responsible for
* destroying the returned value.
* @param val_ The bool value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_bool(bool val_);
/**
* @brief Creates a value with int8 type and the given int8 value. Caller is responsible for
* destroying the returned value.
* @param val_ The int8 value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_int8(int8_t val_);
/**
* @brief Creates a value with int16 type and the given int16 value. Caller is responsible for
* destroying the returned value.
* @param val_ The int16 value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_int16(int16_t val_);
/**
* @brief Creates a value with int32 type and the given int32 value. Caller is responsible for
* destroying the returned value.
* @param val_ The int32 value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_int32(int32_t val_);
/**
* @brief Creates a value with int64 type and the given int64 value. Caller is responsible for
* destroying the returned value.
* @param val_ The int64 value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_int64(int64_t val_);
/**
* @brief Creates a value with uint8 type and the given uint8 value. Caller is responsible for
* destroying the returned value.
* @param val_ The uint8 value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_uint8(uint8_t val_);
/**
* @brief Creates a value with uint16 type and the given uint16 value. Caller is responsible for
* destroying the returned value.
* @param val_ The uint16 value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_uint16(uint16_t val_);
/**
* @brief Creates a value with uint32 type and the given uint32 value. Caller is responsible for
* destroying the returned value.
* @param val_ The uint32 value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_uint32(uint32_t val_);
/**
* @brief Creates a value with uint64 type and the given uint64 value. Caller is responsible for
* destroying the returned value.
* @param val_ The uint64 value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_uint64(uint64_t val_);
/**
* @brief Creates a value with int128 type and the given int128 value. Caller is responsible for
* destroying the returned value.
* @param val_ The int128 value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_int128(kuzu_int128_t val_);
/**
* @brief Creates a value with float type and the given float value. Caller is responsible for
* destroying the returned value.
* @param val_ The float value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_float(float val_);
/**
* @brief Creates a value with double type and the given double value. Caller is responsible for
* destroying the returned value.
* @param val_ The double value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_double(double val_);
/**
* @brief Creates a value with internal_id type and the given internal_id value. Caller is
* responsible for destroying the returned value.
* @param val_ The internal_id value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_internal_id(kuzu_internal_id_t val_);
/**
* @brief Creates a value with date type and the given date value. Caller is responsible for
* destroying the returned value.
* @param val_ The date value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_date(kuzu_date_t val_);
/**
* @brief Creates a value with timestamp_ns type and the given timestamp value. Caller is
* responsible for destroying the returned value.
* @param val_ The timestamp_ns value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_timestamp_ns(kuzu_timestamp_ns_t val_);
/**
* @brief Creates a value with timestamp_ms type and the given timestamp value. Caller is
* responsible for destroying the returned value.
* @param val_ The timestamp_ms value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_timestamp_ms(kuzu_timestamp_ms_t val_);
/**
* @brief Creates a value with timestamp_sec type and the given timestamp value. Caller is
* responsible for destroying the returned value.
* @param val_ The timestamp_sec value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_timestamp_sec(kuzu_timestamp_sec_t val_);
/**
* @brief Creates a value with timestamp_tz type and the given timestamp value. Caller is
* responsible for destroying the returned value.
* @param val_ The timestamp_tz value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_timestamp_tz(kuzu_timestamp_tz_t val_);
/**
* @brief Creates a value with timestamp type and the given timestamp value. Caller is responsible
* for destroying the returned value.
* @param val_ The timestamp value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_timestamp(kuzu_timestamp_t val_);
/**
* @brief Creates a value with interval type and the given interval value. Caller is responsible
* for destroying the returned value.
* @param val_ The interval value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_interval(kuzu_interval_t val_);
/**
* @brief Creates a value with string type and the given string value. Caller is responsible for
* destroying the returned value.
* @param val_ The string value of the value to create.
*/
KUZU_C_API kuzu_value* kuzu_value_create_string(const char* val_);
/**
* @brief Creates a list value with the given number of elements and the given elements.
* The caller needs to make sure that all elements have the same type.
* The elements are copied into the list value, so destroying the elements after creating the list
* value is safe.
* Caller is responsible for destroying the returned value.
* @param num_elements The number of elements in the list.
* @param elements The elements of the list.
* @param[out] out_value The output parameter that will hold a pointer to the created list value.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_value_create_list(uint64_t num_elements, kuzu_value** elements,
kuzu_value** out_value);
/**
* @brief Creates a struct value with the given number of fields and the given field names and
* values. The caller needs to make sure that all field names are unique.
* The field names and values are copied into the struct value, so destroying the field names and
* values after creating the struct value is safe.
* Caller is responsible for destroying the returned value.
* @param num_fields The number of fields in the struct.
* @param field_names The field names of the struct.
* @param field_values The field values of the struct.
* @param[out] out_value The output parameter that will hold a pointer to the created struct value.
* @return The state indicating the success or failure of the operation.
*/
KUZU_C_API kuzu_state kuzu_value_create_struct(uint64_t num_fields, const char** field_names,
kuzu_value** field_values, kuzu_value** out_value);
/**
* @brief Creates a map value with the given number of fields and the given keys and values. The
* caller needs to make sure that all keys are unique, and all keys and values have the same type.
* The keys and values are copied into the map value, so destroying the keys and values after
* creating the map value is safe.
* Caller is responsible for destroying the returned value.
* @param num_fields The number of fields in the map.
* @param keys The keys of the map.
* @param values The values of the map.
* @param[out] out_value The output parameter that will hold a pointer to the created map value.
* @return The state indicating the success or failure of the operation.