-
Notifications
You must be signed in to change notification settings - Fork 1
/
tiledb.h
1442 lines (1328 loc) · 55.3 KB
/
tiledb.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
/**
* @file tiledb.h
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2016 MIT and Intel Corporation
* @copyright Copyright (c) 2018-2021 Omics Data Automation, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
* This file declares the C API for TileDB.
*/
#ifndef __TILEDB_H__
#define __TILEDB_H__
#include "tiledb_constants.h"
#ifdef HAVE_MPI
#include <mpi.h>
#endif
#include <stdint.h>
#include <stddef.h>
#include <string>
#include <string.h>
#include <unistd.h>
/* ********************************* */
/* CONSTANTS */
/* ********************************* */
/** Default error message. */
#define TILEDB_ERRMSG std::string("[TileDB] Error: ")
/** Maximum error message length. */
#define TILEDB_ERRMSG_MAX_LEN 2000
/* ********************************* */
/* MACROS */
/* ********************************* */
#ifdef __cplusplus
extern "C" {
#endif
/**@{*/
/** C Library export. */
#if (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER
# define TILEDB_EXPORT __attribute__((visibility("default")))
#else
# define TILEDB_EXPORT
#endif
/**@}*/
/* ********************************* */
/* GLOBAL VARIABLES */
/* ********************************* */
/** Stores potential error messages. */
extern char tiledb_errmsg[TILEDB_ERRMSG_MAX_LEN];
/* ********************************* */
/* CONFIG */
/* ********************************* */
/** Used to pass congiguration parameters to TileDB. */
typedef struct TileDB_Config {
/**
* The TileDB home directory. If it is set to "" (empty string) or NULL, the
* default home directory will be used, which is ~/.tiledb/.
*/
const char* home_;
#ifdef HAVE_MPI
/** The MPI communicator. Use NULL if no MPI is used. */
MPI_Comm* mpi_comm_;
#endif
/**
* The method for reading data from a file.
* It can be one of the following:
* - TILEDB_IO_MMAP (default)
* TileDB will use mmap.
* - TILEDB_IO_READ
* TileDB will use standard OS read.
* - TILEDB_IO_MPI
* TileDB will use MPI-IO read.
*/
int read_method_;
/**
* The method for writing data to a file.
* It can be one of the following:
* - TILEDB_IO_WRITE (default)
* TileDB will use standard OS write.
* - TILEDB_IO_MPI
* TileDB will use MPI-IO write.
*/
int write_method_;
/**
* Allows some optimizations like disable file locking and keeping file handles open until explicitly closed
* to help minimize excessive writes and other unpredictable behavior on shared posix systems like NFS and Lustre.
* These can be overridden with env TILEDB_DISABLE_FILE_LOCKING and TILEDB_KEEP_FILE_HANDLES_OPEN.
*/
bool enable_shared_posixfs_optimizations_;
/**
* gs://<bucket>/<path> Cloud URIs are serviced through the GCS SDK Client, but if necessary
* can be overridden to use the HDFS Google Cloud Connector.
*/
bool use_gcs_hdfs_connector_;
TileDB_Config() {
memset(this, 0, sizeof(struct TileDB_Config));
}
} TileDB_Config;
/* ********************************* */
/* CONTEXT */
/* ********************************* */
/** The TileDB context, which maintains state for the TileDB modules. */
typedef struct TileDB_CTX TileDB_CTX;
/**
* Initializes the TileDB context.
*
* @param tiledb_ctx The TileDB context to be initialized.
* @param tiledb_config TileDB configuration parameters. If it is NULL,
* TileDB will use its default configuration parameters.
* @return TILEDB_OK for success and TILEDB_ERR for error.
*/
TILEDB_EXPORT int tiledb_ctx_init(
TileDB_CTX** tiledb_ctx,
const TileDB_Config* tiledb_config);
/**
* Finalizes the TileDB context, properly freeing-up memory.
*
* @param tiledb_ctx The TileDB context to be finalized.
* @return TILEDB_OK for success and TILEDB_ERR for error.
*/
TILEDB_EXPORT int tiledb_ctx_finalize(TileDB_CTX* tiledb_ctx);
/* ********************************* */
/* WORKSPACE */
/* ********************************* */
/**
* Creates a new TileDB workspace.
*
* @param tiledb_ctx The TileDB context.
* @param workspace The directory of the workspace to be created in the file
* system. This directory should not be inside another TileDB workspace,
* group, array or metadata directory.
* @return TILEDB_OK for success and TILEDB_ERR for error.
*/
TILEDB_EXPORT int tiledb_workspace_create(
const TileDB_CTX* tiledb_ctx,
const char* workspace);
/* ********************************* */
/* GROUP */
/* ********************************* */
/**
* Creates a new TileDB group.
*
* @param tiledb_ctx The TileDB context.
* @param group The directory of the group to be created in the file system.
* This should be a directory whose parent is a TileDB workspace or another
* TileDB group.
* @return TILEDB_OK for success and TILEDB_ERR for error.
*/
TILEDB_EXPORT int tiledb_group_create(
const TileDB_CTX* tiledb_ctx,
const char* group);
/* ********************************* */
/* ARRAY */
/* ********************************* */
/** A TileDB array object. */
typedef struct TileDB_Array TileDB_Array;
/** The array schema. */
typedef struct TileDB_ArraySchema {
/**
* The TileDB workspace. It is a directory.
*/
char* array_workspace_;
/**
* The array name. It is a directory, whose parent must be a TileDB workspace,
* or group.
*/
char* array_name_;
/** The attribute names. */
char** attributes_;
/** The number of attributes. */
int attribute_num_;
/**
* The tile capacity for the case of sparse fragments. If it is <=0,
* TileDB will use its default.
*/
int64_t capacity_;
/**
* The cell order. It can be one of the following:
* - TILEDB_ROW_MAJOR
* - TILEDB_COL_MAJOR
* - TILEDB_HILBERT.
*/
int cell_order_;
/**
* Specifies the number of values per attribute for a cell. If it is NULL,
* then each attribute has a single value per cell. If for some attribute
* the number of values is variable (e.g., in the case off strings), then
* TILEDB_VAR_NUM must be used.
*/
int* cell_val_num_;
/**
* The compression type for each attribute (plus one extra at the end for the
* coordinates). It can be one of the following:
* - TILEDB_NO_COMPRESSION
* - TILEDB_GZIP
* - TILEDB_ZSTD
* - TILEDB_LZ4
* - TILEDB_BLOSC
* - TILEDB_BLOSC_LZ4
* - TILEDB_BLOSC_LZ4HC
* - TILEDB_BLOSC_SNAPPY
* - TILEDB_BLOSC_ZLIB
* - TILEDB_BLOSC_ZSTD
* - TILEDB_RLE
*
* If it is *NULL*, then the default TILEDB_NO_COMPRESSION is used for all
* attributes.
*/
int* compression_;
/** Specifies the compression level */
int* compression_level_;
/** Compression type for the offsets for variable number of cells TILEDB_VAR_NUM for attribute */
int* offsets_compression_;
/** Compression level for the offsets for variable number of cells TILEDB_VAR_NUM for attribute */
int* offsets_compression_level_;
/**
* Specifies if the array is dense (1) or sparse (0). If the array is dense,
* then the user must specify tile extents (see below).
*/
int dense_;
/** The dimension names. */
char** dimensions_;
/** The number of dimensions. */
int dim_num_;
/**
* The array domain. It should contain one [low, high] pair per dimension.
* The type of the values stored in this buffer should match the coordinates
* type.
*/
void* domain_;
/**
* The tile extents. There should be one value for each dimension. The type of
* the values stored in this buffer should match the coordinates type. It
* can be NULL only for sparse arrays.
*/
void* tile_extents_;
/**
* The tile order. It can be one of the following:
* - TILEDB_ROW_MAJOR
* - TILEDB_COL_MAJOR.
*/
int tile_order_;
/**
* The attribute types, plus an extra one in the end for the coordinates.
* The attribute type can be one of the following:
* - TILEDB_INT32, TILEDB_UINT32
* - TILEDB_INT64, TILEDB_UINT64
* - TILEDB_FLOAT32
* - TILEDB_FLOAT64
* - TILEDB_CHAR, TILEDB_INT8, TILEDB_UINT8
* - TILEDB_INT16, TILEDB_UINT16
*
* The coordinate type can be one of the following:
* - TILEDB_INT32
* - TILEDB_INT64
* - TILEDB_FLOAT32
* - TILEDB_FLOAT64
*/
int* types_;
} TileDB_ArraySchema;
/**
* Populates a TileDB array schema object.
*
* @param tiledb_array_schema The array schema to be populated.
* @param array_name The array name.
* @param attributes The attribute names.
* @param attribute_num The number of attributes.
* @param capacity The tile capacity.
* @param cell_order The cell order.
* @param cell_val_num The number of values per attribute per cell.
* @param compression The compression type for each attribute (plus an extra one
* in the end for the coordinates).
* @param compression_level The compression level associated with the compression type per attribute
* @param dense Specifies if the array is dense (1) or sparse (0).
* @param dimensions The dimension names.
* @param dim_num The number of dimensions.
* @param domain The array domain.
* @param domain_len The length of *domain* in bytes.
* @param tile_extents The tile extents.
* @param tile_extents_len The length of *tile_extents* in bytes.
* @param tile_order The tile order.
* @param types The attribute types (plus one in the end for the coordinates).
* @return TILEDB_OK for success and TILEDB_ERR for error.
* @see TileDB_ArraySchema
*/
TILEDB_EXPORT int tiledb_array_set_schema(
TileDB_ArraySchema* tiledb_array_schema,
const char* array_name,
const char** attributes,
int attribute_num,
int64_t capacity,
int cell_order,
const int* cell_val_num,
const int* compression,
const int* compression_level,
const int* offsets_compression,
const int* offsets_compression_level,
int dense,
const char** dimensions,
int dim_num,
const void* domain,
size_t domain_len,
const void* tile_extents,
size_t tile_extents_len,
int tile_order,
const int* types);
/**
* Creates a new TileDB array.
*
* @param tiledb_ctx The TileDB context.
* @param tiledb_array_schema The array schema.
* @return TILEDB_OK for success and TILEDB_ERR for error.
*/
TILEDB_EXPORT int tiledb_array_create(
const TileDB_CTX* tiledb_ctx,
const TileDB_ArraySchema* tiledb_array_schema);
/**
* Initializes a TileDB array.
*
* @param tiledb_ctx The TileDB context.
* @param tiledb_array The array object to be initialized. The function
* will allocate memory space for it.
* @param array The directory of the array to be initialized.
* @param mode The mode of the array. It must be one of the following:
* - TILEDB_ARRAY_WRITE
* - TILEDB_ARRAY_WRITE_SORTED_COL
* - TILEDB_ARRAY_WRITE_SORTED_ROW
* - TILEDB_ARRAY_WRITE_UNSORTED
* - TILEDB_ARRAY_READ
* - TILEDB_ARRAY_READ_SORTED_COL
* - TILEDB_ARRAY_READ_SORTED_ROW
* @param subarray The subarray in which the array read/write will be
* constrained on. It should be a sequence of [low, high] pairs (one
* pair per dimension), whose type should be the same as that of the
* coordinates. If it is NULL, then the subarray is set to the entire
* array domain. For the case of writes, this is meaningful only for
* dense arrays, and specifically dense writes.
* @param attributes A subset of the array attributes the read/write will be
* constrained on. Note that the coordinates have special attribute name
* TILEDB_COORDS. A NULL value indicates **all** attributes (including
* the coordinates as the last attribute in the case of sparse arrays).
* @param attribute_num The number of the input attributes. If *attributes* is
* NULL, then this should be set to 0.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_init(
const TileDB_CTX* tiledb_ctx,
TileDB_Array** tiledb_array,
const char* array,
int mode,
const void* subarray,
const char** attributes,
int attribute_num);
/**
* Apply filter to the initialized array. This is useful
* when the array is used for reading, and the user wishes to constrain the
* read results with an expression.
*
* @param tiledb_array The TileDB array.
* @param filter_expression An expression string that evaluates to a boolean
* to allow for cells to be filtered out from the buffers while reading.
* If NULL or empty, no filter is applied.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_apply_filter(
const TileDB_Array* tiledb_array,
const char *filter_expression);
/**
* Resets the subarray used upon initialization of the array. This is useful
* when the array is used for reading, and the user wishes to change the
* query subarray without having to finalize and re-initialize the array.
*
* @param tiledb_array The TileDB array.
* @param subarray The new subarray. It should be a sequence of [low, high]
* pairs (one pair per dimension), whose type should be the same as that of
* the coordinates. If it is NULL, then the subarray is set to the entire
* array domain. For the case of writes, this is meaningful only for
* dense arrays, and specifically dense writes.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_reset_subarray(
const TileDB_Array* tiledb_array,
const void* subarray);
/**
* Resets the attributes used upon initialization of the array.
*
* @param tiledb_array The TileDB array.
* @param attributes The new attributes to focus on. If it is NULL, then
* all the attributes are used (including the coordinates in the case of
* sparse arrays, or sparse writes to dense arrays).
* @param attribute_num The number of the attributes. If *attributes* is NULL,
* then this should be 0.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_reset_attributes(
const TileDB_Array* tiledb_array,
const char** attributes,
int attribute_num);
/**
* Retrieves the schema of an already initialized array.
*
* @param tiledb_array The TileDB array object (must already be initialized).
* @param tiledb_array_schema The array schema to be retrieved.
* @return TILEDB_OK for success and TILEDB_ERR for error.
*/
TILEDB_EXPORT int tiledb_array_get_schema(
const TileDB_Array* tiledb_array,
TileDB_ArraySchema* tiledb_array_schema);
/**
* Retrieves the schema of an array from disk.
*
* @param tiledb_ctx The TileDB context.
* @param array The directory of the array whose schema will be retrieved.
* @param tiledb_array_schema The array schema to be retrieved.
* @return TILEDB_OK for success and TILEDB_ERR for error.
*/
TILEDB_EXPORT int tiledb_array_load_schema(
const TileDB_CTX* tiledb_ctx,
const char* array,
TileDB_ArraySchema* tiledb_array_schema);
/**
* Frees the input array schema struct, properly deallocating memory space.
*
* @param tiledb_array_schema The array schema to be freed.
* @return TILEDB_OK for success and TILEDB_ERR for error.
*/
TILEDB_EXPORT int tiledb_array_free_schema(
TileDB_ArraySchema* tiledb_array_schema);
/**
* Performs a write operation to an array.
* The array must be initialized in one of the following write modes,
* each of which has a different behaviour:
* - TILEDB_ARRAY_WRITE: \n
* In this mode, the cell values are provided in the buffers respecting
* the cell order on the disk (specified in the array schema). It is
* practically an **append** operation,
* where the provided cell values are simply written at the end of
* their corresponding attribute files. This mode leads to the best
* performance. The user may invoke this function an arbitrary number
* of times, and all the writes will occur in the same fragment.
* Moreover, the buffers need not be synchronized, i.e., some buffers
* may have more cells than others when the function is invoked.
* - TILEDB_ARRAY_WRITE_SORTED_COL: \n
* In this mode, the cell values are provided in the buffer in column-major
* order with respect to the subarray used upon array initialization.
* TileDB will properly re-organize the cells so that they follow the
* array cell order for storage on the disk.
* - TILEDB_ARRAY_WRITE_SORTED_ROW: \n
* In this mode, the cell values are provided in the buffer in row-major
* order with respect to the subarray used upon array initialization.
* TileDB will properly re-organize the cells so that they follow the
* array cell order for storage on the disk.
* - TILEDB_ARRAY_WRITE_UNSORTED: \n
* This mode is applicable to sparse arrays, or when writing sparse updates
* to a dense array. One of the buffers holds the coordinates. The cells
* in this mode are given in an arbitrary, unsorted order (i.e., without
* respecting how the cells must be stored on the disk according to the
* array schema definition). Each invocation of this function internally
* sorts the cells and writes them to the disk in the proper order. In
* addition, each invocation creates a **new** fragment. Finally, the
* buffers in each invocation must be synchronized, i.e., they must have
* the same number of cell values across all attributes.
*
* @param tiledb_array The TileDB array object (must be already initialized).
* @param buffers An array of buffers, one for each attribute. These must be
* provided in the same order as the attribute order specified in
* tiledb_array_init() or tiledb_array_reset_attributes(). The case of
* variable-sized attributes is special. Instead of providing a single
* buffer for such an attribute, **two** must be provided: the second
* holds the variable-sized cell values, whereas the first holds the
* start offsets of each cell in the second buffer.
* @param buffer_sizes The sizes (in bytes) of the input buffers (there should
* be a one-to-one correspondence).
* @return TILEDB_OK for success and TILEDB_ERR for error.
*/
TILEDB_EXPORT int tiledb_array_write(
const TileDB_Array* tiledb_array,
const void** buffers,
const size_t* buffer_sizes);
/**
* Performs a read operation on an array.
* The array must be initialized in one of the following read modes,
* each of which has a different behaviour:
* - TILEDB_ARRAY_READ: \n
* In this mode, the cell values are stored in the buffers respecting
* the cell order on the disk (specified in the array schema). This mode
* leads to the best performance.
* - TILEDB_ARRAY_READ_SORTED_COL: \n
* In this mode, the cell values are stored in the buffers in column-major
* order with respect to the subarray used upon array initialization.
* - TILEDB_ARRAY_READ_SORTED_ROW: \n
* In this mode, the cell values are stored in the buffer in row-major
* order with respect to the subarray used upon array initialization.
*
* @param tiledb_array The TileDB array.
* @param buffers An array of buffers, one for each attribute. These must be
* provided in the same order as the attributes specified in
* tiledb_array_init() or tiledb_array_reset_attributes(). The case of
* variable-sized attributes is special. Instead of providing a single
* buffer for such an attribute, **two** must be provided: the second
* will hold the variable-sized cell values, whereas the first holds the
* start offsets of each cell in the second buffer.
* @param buffer_sizes The sizes (in bytes) allocated by the user for the input
* buffers (there is a one-to-one correspondence). The function will attempt
* to write as many results as can fit in the buffers, and potentially
* alter the buffer size to indicate the size of the *useful* data written
* in the buffer. If a buffer cannot hold all results, the function will
* still succeed, writing as much data as it can and turning on an overflow
* flag which can be checked with function tiledb_array_overflow(). The
* next invocation will resume from the point the previous one stopped,
* without inflicting a considerable performance penalty due to overflow.
* @return TILEDB_OK for success and TILEDB_ERR for error.
*/
TILEDB_EXPORT int tiledb_array_read(
const TileDB_Array* tiledb_array,
void** buffers,
size_t* buffer_sizes);
/**
* Identical to tiledb_array_read, but skips N cells for each attribute
* before reading data into the buffer. An example where this is useful is
* as follows - user queries fields/attributes [ F0, F1, F2 ], but is only
* interested in cells where F0 > C. So, a good query would read blocks of F0
* data, determine which cells are needed and would only fetch data from F1
* and F2 for the required cells. This can be achieved by skipping over the
* discarded cells
* @params - identical to tiledb_array_read()
* @param skip_counts The number of cells to skip over for each buffer/attribute.
* @return TILEDB_OK for success and TILEDB_ERR for error.
*/
TILEDB_EXPORT int tiledb_array_skip_and_read(
const TileDB_Array* tiledb_array,
void** buffers,
size_t* buffer_sizes,
size_t* skip_counts);
/**
* Checks if a read operation for a particular attribute resulted in a
* buffer overflow.
*
* @param tiledb_array The TileDB array.
* @param attribute_id The id of the attribute for which the overflow is
* checked. This id corresponds to the position of the attribute name
* placed in the *attributes* input of tiledb_array_init(), or
* tiledb_array_reset_attributes() (the positions start from 0).
* If *attributes* was NULL in the
* above functions, then the attribute id corresponds to the order
* in which the attributes were defined in the array schema upon the
* array creation. Note that, in that case, the extra coordinates
* attribute corresponds to the last extra attribute, i.e., its id
* is *attribute_num*.
* @return TILEDB_ERR for error, 1 for overflow, and 0 otherwise.
*/
TILEDB_EXPORT int tiledb_array_overflow(
const TileDB_Array* tiledb_array,
int attribute_id);
/**
* Consolidates the fragments of an array into a single fragment.
*
* @param tiledb_ctx The TileDB context.
* @param array The name of the TileDB array to be consolidated.
* @param buffer_size (Optional) The size of buffers for reading/writing attributes during consolidation. Default is 10M.
* @param batch size (Optional) When specified, consolidation will occur batch-wise with a smaller batch_size set of
* fragments getting consolidating together. Default is all fragments.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_consolidate(
const TileDB_CTX* tiledb_ctx,
const char* array,
size_t buffer_size = TILEDB_CONSOLIDATION_BUFFER_SIZE,
int batch_size = -1);
/**
* Finalizes a TileDB array, properly freeing its memory space.
*
* @param tiledb_array The array to be finalized.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_finalize(
TileDB_Array* tiledb_array);
/**
* Syncs all currently written files in the input array.
*
* @param tiledb_array The array to be synced.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_sync(
TileDB_Array* tiledb_array);
/**
* Syncs the currently written files associated with the input attribute
* in the input array.
*
* @param tiledb_array The array to be synced.
* @param attribute The name of the attribute to be synced.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_sync_attribute(
TileDB_Array* tiledb_array,
const char* attribute);
/** A TileDB array iterator. */
typedef struct TileDB_ArrayIterator TileDB_ArrayIterator;
/**
* Initializes an array iterator for reading cells, potentially constraining it
* on a subset of attributes, as well as a subarray. The cells will be read
* in the order they are stored on the disk, maximizing performance.
*
* @param tiledb_ctx The TileDB context.
* @param tiledb_array_it The TileDB array iterator to be created. The function
* will allocate the appropriate memory space for the iterator.
* @param array The directory of the array the iterator is initialized for.
* @param mode The read mode, which can be one of the following:
* - TILEDB_ARRAY_READ\n
* Reads the cells in the native order they are stored on the disk.
* - TILEDB_ARRAY_READ_SORTED_COL\n
* Reads the cells in column-major order within the specified subarray.
* - TILEDB_ARRAY_READ_SORTED_ROW\n
* Reads the cells in column-major order within the specified subarray.
* @param subarray The subarray in which the array iterator will be
* constrained on. It should be a sequence of [low, high] pairs (one
* pair per dimension), whose type should be the same as that of the
* coordinates. If it is NULL, then the subarray is set to the entire
* array domain.
* @param attributes A subset of the array attributes the iterator will be
* constrained on. Note that the coordinates have special attribute name
* TILEDB_COORDS. A NULL value indicates **all** attributes (including
* the coordinates as the last attribute in the case of sparse arrays).
* @param attribute_num The number of the input attributes. If *attributes* is
* NULL, then this should be set to 0.
* @param buffers This is an array of buffers similar to tiledb_array_read().
* It is the user that allocates and provides buffers that the iterator
* will use for internal buffering of the read cells. The iterator will
* read from the disk the relevant cells in batches, by fitting as many
* cell values as possible in the user buffers. This gives the user the
* flexibility to control the prefetching for optimizing performance
* depending on the application.
* @param buffer_sizes The corresponding size (in bytes) of the allocated
* memory space for *buffers*. The function will prefetch from the
* disk as many cells as can fit in the buffers, whenever it finishes
* iterating over the previously prefetched data.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_iterator_init(
const TileDB_CTX* tiledb_ctx,
TileDB_ArrayIterator** tiledb_array_it,
const char* array,
int mode,
const void* subarray,
const char** attributes,
int attribute_num,
void** buffers,
size_t* buffer_sizes);
/**
* Initializes an array iterator for reading cells, potentially constraining it
* on a subset of attributes, as well as a subarray. The cells will be read
* in the order they are stored on the disk, maximizing performance.
*
* @param tiledb_ctx The TileDB context.
* @param tiledb_array_it The TileDB array iterator to be created. The function
* will allocate the appropriate memory space for the iterator.
* @param array The directory of the array the iterator is initialized for.
* @param mode The read mode, which can be one of the following:
* - TILEDB_ARRAY_READ\n
* Reads the cells in the native order they are stored on the disk.
* - TILEDB_ARRAY_READ_SORTED_COL\n
* Reads the cells in column-major order within the specified subarray.
* - TILEDB_ARRAY_READ_SORTED_ROW\n
* Reads the cells in column-major order within the specified subarray.
* @param subarray The subarray in which the array iterator will be
* constrained on. It should be a sequence of [low, high] pairs (one
* pair per dimension), whose type should be the same as that of the
* coordinates. If it is NULL, then the subarray is set to the entire
* array domain.
* @param attributes A subset of the array attributes the iterator will be
* constrained on. Note that the coordinates have special attribute name
* TILEDB_COORDS. A NULL value indicates **all** attributes (including
* the coordinates as the last attribute in the case of sparse arrays).
* @param attribute_num The number of the input attributes. If *attributes* is
* NULL, then this should be set to 0.
* @param buffers This is an array of buffers similar to tiledb_array_read().
* It is the user that allocates and provides buffers that the iterator
* will use for internal buffering of the read cells. The iterator will
* read from the disk the relevant cells in batches, by fitting as many
* cell values as possible in the user buffers. This gives the user the
* flexibility to control the prefetching for optimizing performance
* depending on the application.
* @param buffer_sizes The corresponding size (in bytes) of the allocated
* memory space for *buffers*. The function will prefetch from the
* disk as many cells as can fit in the buffers, whenever it finishes
* iterating over the previously prefetched data.
* @param filter_expression An expression string that evaluates to a boolean
* to allow for cells to be filtered out from the buffers while reading.
* If NULL or empty, no filter is applied.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_iterator_init_with_filter(
const TileDB_CTX* tiledb_ctx,
TileDB_ArrayIterator** tiledb_array_it,
const char* array,
int mode,
const void* subarray,
const char** attributes,
int attribute_num,
void** buffers,
size_t* buffer_sizes,
const char* filter_expression);
/**
* Resets the subarray used upon initialization of the iterator. This is useful
* when the array is used for reading, and the user wishes to change the
* query subarray without having to finalize and re-initialize the array.
*
* @param tiledb_array_it The TileDB iterator.
* @param subarray The new subarray. It should be a sequence of [low, high]
* pairs (one pair per dimension), whose type should be the same as that of
* the coordinates. If it is NULL, then the subarray is set to the entire
* array domain. For the case of writes, this is meaningful only for
* dense arrays, and specifically dense writes.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_iterator_reset_subarray(
TileDB_ArrayIterator* tiledb_array_it,
const void* subarray);
/**
* Retrieves the current cell value for a particular attribute.
*
* @param tiledb_array_it The TileDB array iterator.
* @param attribute_id The id of the attribute for which the cell value
* is retrieved. This id corresponds to the position of the attribute name
* placed in the *attributes* input of tiledb_array_iterator_init()
* (the positions start from 0).
* If *attributes* was NULL in the above function, then the attribute id
* corresponds to the order in which the attributes were defined in the
* array schema upon the array creation. Note that, in that case, the extra
* coordinates attribute corresponds to the last extra attribute, i.e.,
* its id is *attribute_num*.
* @param value The cell value to be retrieved. Note that its type is the
* same as that defined in the array schema for the corresponding attribute.
* Note also that the function essentially returns a pointer to this value
* in the internal buffers of the iterator.
* @param value_size The size (in bytes) of the retrieved value. Useful mainly
* for the case of variable-sized cells.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_iterator_get_value(
TileDB_ArrayIterator* tiledb_array_it,
int attribute_id,
const void** value,
size_t* value_size);
/**
* Advances the iterator by one cell.
*
* @param tiledb_array_it The TileDB array iterator.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_iterator_next(
TileDB_ArrayIterator* tiledb_array_it);
/**
* Checks if the the iterator has reached its end.
*
* @param tiledb_array_it The TileDB array iterator.
* @return TILEDB_ERR for error, 1 for having reached the end, and 0 otherwise.
*/
TILEDB_EXPORT int tiledb_array_iterator_end(
TileDB_ArrayIterator* tiledb_array_it);
/**
* Finalizes an array iterator, properly freeing the allocating memory space.
*
* @param tiledb_array_it The TileDB array iterator to be finalized.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_array_iterator_finalize(
TileDB_ArrayIterator* tiledb_array_it);
/* ********************************* */
/* METADATA */
/* ********************************* */
/** Specifies the metadata schema. */
typedef struct TileDB_MetadataSchema {
/**
* The metadata name. It is a directory, whose parent must be a TileDB
* workspace, group, or array.
*/
char* metadata_name_;
/** The attribute names. */
char** attributes_;
/** The number of attributes. */
int attribute_num_;
/**
* The tile capacity. If it is <=0, TileDB will use its default.
*/
int64_t capacity_;
/**
* Specifies the number of values per attribute for a cell. If it is NULL,
* then each attribute has a single value per cell. If for some attribute
* the number of values is variable (e.g., in the case off strings), then
* TILEDB_VAR_NUM must be used.
*/
int* cell_val_num_;
/**
* The compression type for each attribute (plus one extra at the end for the
* key). It can be one of the following:
* - TILEDB_NO_COMPRESSION
* - TILEDB_GZIP
* - TILEDB_ZSTD
* - TILEDB_LZ4
* - TILEDB_BLOSC
* - TILEDB_BLOSC_LZ4
* - TILEDB_BLOSC_LZ4HC
* - TILEDB_BLOSC_SNAPPY
* - TILEDB_BLOSC_ZLIB
* - TILEDB_BLOSC_ZSTD
* - TILEDB_RLE
*
* If it is *NULL*, then the default TILEDB_NO_COMPRESSION is used for all
* attributes.
*/
int* compression_;
int* compression_level_;
/**
* The attribute types.
* The attribute type can be one of the following:
* - TILEDB_INT32
* - TILEDB_INT64
* - TILEDB_FLOAT32
* - TILEDB_FLOAT64
* - TILEDB_CHAR.
*/
int* types_;
} TileDB_MetadataSchema;
/** A TileDB metadata object. */
typedef struct TileDB_Metadata TileDB_Metadata;
/**
* Populates a TileDB metadata schema object.
*
* @param tiledb_metadata_schema The metadata schema C API struct.
* @param metadata_name The metadata name.
* @param attributes The attribute names.
* @param attribute_num The number of attributes.
* @param capacity The tile capacity.
* @param cell_val_num The number of values per attribute per cell.
* @param compression The compression type for each attribute (plus an extra one
* in the end for the key).
* @param types The attribute types.
* @return TILEDB_OK for success and TILEDB_ERR for error.
* @see TileDB_MetadataSchema
*/
TILEDB_EXPORT int tiledb_metadata_set_schema(
TileDB_MetadataSchema* tiledb_metadata_schema,
const char* metadata_name,
const char** attributes,
int attribute_num,
int64_t capacity,
const int* cell_val_num,
const int* compression,
const int* compression_level,
const int* types);
/**
* Creates a new TileDB metadata object.
*
* @param tiledb_ctx The TileDB context.
* @param metadata_schema The metadata schema.
* @return TILEDB_OK for success and TILEDB_ERR for error.
*/
TILEDB_EXPORT int tiledb_metadata_create(
const TileDB_CTX* tiledb_ctx,
const TileDB_MetadataSchema* metadata_schema);
/**
* Initializes a TileDB metadata object.
*
* @param tiledb_ctx The TileDB context.
* @param tiledb_metadata The metadata object to be initialized. The function
* will allocate memory space for it.
* @param metadata The directory of the metadata to be initialized.
* @param mode The mode of the metadata. It must be one of the following:
* - TILEDB_METADATA_WRITE
* - TILEDB_METADATA_READ
* @param attributes A subset of the metadata attributes the read/write will be
* constrained on. Note that the keys have a special attribute name
* called TILEDB_KEYS. A NULL value indicates **all** attributes (including
* the keys as an extra attribute in the end).
* @param attribute_num The number of the input attributes. If *attributes* is
* NULL, then this should be set to 0.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_metadata_init(
const TileDB_CTX* tiledb_ctx,
TileDB_Metadata** tiledb_metadata,
const char* metadata,
int mode,
const char** attributes,
int attribute_num);
/**
* Resets the attributes used upon initialization of the metadata.
*
* @param tiledb_metadata The TileDB metadata.
* @param attributes The new attributes to focus on. If it is NULL, then
* all the attributes are used.
* @param attribute_num The number of the attributes. If *attributes* is NULL,
* then this should be 0.
* @return TILEDB_OK on success, and TILEDB_ERR on error.
*/
TILEDB_EXPORT int tiledb_metadata_reset_attributes(
const TileDB_Metadata* tiledb_metadata,
const char** attributes,
int attribute_num);