-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy patharray.go
More file actions
570 lines (513 loc) · 21.6 KB
/
array.go
File metadata and controls
570 lines (513 loc) · 21.6 KB
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
package tiledb
/*
#cgo LDFLAGS: -ltiledb
#cgo linux LDFLAGS: -ldl
#include <tiledb/tiledb.h>
#include <stdlib.h>
*/
import "C"
import (
"fmt"
"runtime"
"unsafe"
)
/*
Array struct representing a TileDB array object.
An Array object represents array data in TileDB at some persisted location,
e.g. on disk, in an S3 bucket, etc. Once an array has been opened for reading
or writing, interact with the data through Query objects.
*/
type Array struct {
tiledbArray *C.tiledb_array_t
context *Context
uri string
}
// NonEmptyDomain contains the non empty dimension bounds and dimension name
type NonEmptyDomain struct {
DimensionName string
Bounds interface{}
}
// NewArray alloc a new array
func NewArray(ctx *Context, uri string) (*Array, error) {
curi := C.CString(uri)
defer C.free(unsafe.Pointer(curi))
array := Array{context: ctx, uri: uri}
ret := C.tiledb_array_alloc(array.context.tiledbContext, curi, &array.tiledbArray)
if ret != C.TILEDB_OK {
return nil, fmt.Errorf("Error creating tiledb array: %s", array.context.LastError())
}
// Set finalizer for free C pointer on gc
runtime.SetFinalizer(&array, func(array *Array) {
array.Free()
})
return &array, nil
}
// Free tiledb_array_t that was allocated on heap in c
func (a *Array) Free() {
if a.tiledbArray != nil {
a.Close()
C.tiledb_array_free(&a.tiledbArray)
}
}
/*
Open the array. The array is opened using a query type as input.
This is to indicate that queries created for this Array object will inherit
the query type. In other words, Array objects are opened to receive only one
type of queries. They can always be closed and be re-opened with another query
type. Also there may be many different Array objects created and opened with
different query types. For instance, one may create and open an array object
array_read for reads and another one array_write for writes, and interleave
creation and submission of queries for both these array objects.
*/
func (a *Array) Open(queryType QueryType) error {
ret := C.tiledb_array_open(a.context.tiledbContext, a.tiledbArray, C.tiledb_query_type_t(queryType))
if ret != C.TILEDB_OK {
return fmt.Errorf("Error opening tiledb array for querying: %s", a.context.LastError())
}
return nil
}
/*
OpenWithKey Opens an encrypted array using the given encryption key.
This function has the same semantics as tiledb_array_open() but is used
for encrypted arrays.
An encrypted array must be opened with this function before queries can
be issued to it.
*/
func (a *Array) OpenWithKey(queryType QueryType, encryptionType EncryptionType, key string) error {
ckey := unsafe.Pointer(C.CString(key))
defer C.free(ckey)
ret := C.tiledb_array_open_with_key(a.context.tiledbContext, a.tiledbArray, C.tiledb_query_type_t(queryType), C.tiledb_encryption_type_t(encryptionType), ckey, C.uint32_t(len(key)))
if ret != C.TILEDB_OK {
return fmt.Errorf("Error opening tiledb array with key for querying: %s", a.context.LastError())
}
return nil
}
/*
OpenAt Similar to tiledb_array_open, but this function takes as input
a timestamp, representing time in milliseconds ellapsed since
1970-01-01 00:00:00 +0000 (UTC). Opening the array at a timestamp provides
a view of the array with all writes/updates that happened at or before
timestamp (i.e., excluding those that occurred after timestamp). This
function is useful to ensure consistency at a potential distributed
setting, where machines need to operate on the same view of the array.
*/
func (a *Array) OpenAt(queryType QueryType, timestamp uint64) error {
ret := C.tiledb_array_open_at(a.context.tiledbContext, a.tiledbArray, C.tiledb_query_type_t(queryType), C.uint64_t(timestamp))
if ret != C.TILEDB_OK {
return fmt.Errorf("Error opening tiledb array at %d for querying: %s", timestamp, a.context.LastError())
}
return nil
}
/*
OpenAtWithKey Similar to tiledb_array_open_with_key, but this function
takes as input a timestamp, representing time in milliseconds ellapsed
since 1970-01-01 00:00:00 +0000 (UTC). Opening the array at a timestamp
provides a view of the array with all writes/updates that happened at or
before timestamp (i.e., excluding those that occurred after timestamp).
This function is useful to ensure consistency at a potential distributed
setting, where machines need to operate on the same view of the array.
*/
func (a *Array) OpenAtWithKey(queryType QueryType, encryptionType EncryptionType, key string, timestamp uint64) error {
ckey := unsafe.Pointer(C.CString(key))
defer C.free(ckey)
ret := C.tiledb_array_open_at_with_key(a.context.tiledbContext, a.tiledbArray, C.tiledb_query_type_t(queryType), C.tiledb_encryption_type_t(encryptionType), ckey, C.uint32_t(len(key)), C.uint64_t(timestamp))
if ret != C.TILEDB_OK {
return fmt.Errorf("Error opening tiledb array with key at %d for querying: %s", timestamp, a.context.LastError())
}
return nil
}
/*
Reopen the array (the array must be already open). This is useful when the
array got updated after it got opened and the Array object got created.
To sync-up with the updates, the user must either close the array and open
with open(), or just use reopen() without closing. This function will be
generally faster than the former alternative.
*/
func (a *Array) Reopen() error {
ret := C.tiledb_array_reopen(a.context.tiledbContext, a.tiledbArray)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error reopening tiledb array for querying: %s", a.context.LastError())
}
return nil
}
// Close a tiledb array, this is called on garbage collection automatically
func (a *Array) Close() error {
ret := C.tiledb_array_close(a.context.tiledbContext, a.tiledbArray)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error closing tiledb array for querying: %s", a.context.LastError())
}
return nil
}
// Create a new TileDB array given an input schema.
func (a *Array) Create(arraySchema *ArraySchema) error {
curi := C.CString(a.uri)
defer C.free(unsafe.Pointer(curi))
ret := C.tiledb_array_create(a.context.tiledbContext, curi, arraySchema.tiledbArraySchema)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error creating tiledb array: %s", a.context.LastError())
}
return nil
}
// CreateWithKey a new TileDB array given an input schema.
func (a *Array) CreateWithKey(arraySchema *ArraySchema, encryptionType EncryptionType, key string) error {
ckey := unsafe.Pointer(C.CString(key))
defer C.free(ckey)
curi := C.CString(a.uri)
defer C.free(unsafe.Pointer(curi))
ret := C.tiledb_array_create_with_key(a.context.tiledbContext, curi, arraySchema.tiledbArraySchema, C.tiledb_encryption_type_t(encryptionType), ckey, C.uint32_t(len(key)))
if ret != C.TILEDB_OK {
return fmt.Errorf("Error creating tiledb array with key: %s", a.context.LastError())
}
return nil
}
// Consolidate Consolidates the fragments of an array into a single fragment.
// You must first finalize all queries to the array before consolidation can
// begin (as consolidation temporarily acquires an exclusive lock on the array).
func (a *Array) Consolidate(config *Config) error {
if config == nil {
return fmt.Errorf("Config must not be nil for Consolidate")
}
curi := C.CString(a.uri)
defer C.free(unsafe.Pointer(curi))
ret := C.tiledb_array_consolidate(a.context.tiledbContext, curi, config.tiledbConfig)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error consolidating tiledb array: %s", a.context.LastError())
}
return nil
}
// ConsolidateWithKey Consolidates the fragments of an encrypted array
// into a single fragment.
// You must first finalize all queries to the array before consolidation can
// begin (as consolidation temporarily acquires an exclusive lock on the array).
func (a *Array) ConsolidateWithKey(encryptionType EncryptionType, key string, config *Config) error {
if config == nil {
return fmt.Errorf("Config must not be nil for ConsolidateWithKey")
}
ckey := unsafe.Pointer(C.CString(key))
defer C.free(ckey)
curi := C.CString(a.uri)
defer C.free(unsafe.Pointer(curi))
ret := C.tiledb_array_consolidate_with_key(a.context.tiledbContext, curi, C.tiledb_encryption_type_t(encryptionType), ckey, C.uint32_t(len(key)), config.tiledbConfig)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error consolidating tiledb with key array: %s", a.context.LastError())
}
return nil
}
// Schema returns the ArraySchema for the array
func (a *Array) Schema() (*ArraySchema, error) {
arraySchema := ArraySchema{context: a.context}
ret := C.tiledb_array_get_schema(a.context.tiledbContext, a.tiledbArray, &arraySchema.tiledbArraySchema)
if ret != C.TILEDB_OK {
return nil, fmt.Errorf("Error getting schema for tiledb array: %s", a.context.LastError())
}
return &arraySchema, nil
}
// QueryType return the current query type of an open array
func (a *Array) QueryType() (QueryType, error) {
var queryType C.tiledb_query_type_t
ret := C.tiledb_array_get_query_type(a.context.tiledbContext, a.tiledbArray, &queryType)
if ret != C.TILEDB_OK {
return -1, fmt.Errorf("Error getting QueryType for tiledb array: %s", a.context.LastError())
}
return QueryType(queryType), nil
}
// makeNonEmptyDomain creates a []NonEmptyDomain from a generic domain-typed slice
func makeNonEmptyDomain(domain *Domain, domainSlice interface{}) ([]NonEmptyDomain, error) {
domainType, err := domain.Type()
if err != nil {
return nil, err
}
ndims, err := domain.NDim()
if err != nil {
return nil, err
}
nonEmptyDomains := make([]NonEmptyDomain, 0)
for i := uint(0); i < ndims; i++ {
dimension, err := domain.DimensionFromIndex(i)
if err != nil {
return nil, err
}
name, err := dimension.Name()
if err != nil {
return nil, err
}
switch domainType {
case TILEDB_INT8:
tmpDomain := domainSlice.([]int8)
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []int8{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
case TILEDB_INT16:
tmpDomain := domainSlice.([]int16)
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []int16{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
case TILEDB_INT32:
tmpDomain := domainSlice.([]int32)
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []int32{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
case TILEDB_INT64:
tmpDomain := domainSlice.([]int64)
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []int64{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
case TILEDB_UINT8:
tmpDomain := domainSlice.([]uint8)
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []uint8{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
case TILEDB_UINT16:
tmpDomain := domainSlice.([]uint16)
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []uint16{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
case TILEDB_UINT32:
tmpDomain := domainSlice.([]uint32)
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []uint32{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
case TILEDB_UINT64:
tmpDomain := domainSlice.([]uint64)
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []uint64{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
case TILEDB_FLOAT32:
tmpDomain := domainSlice.([]float32)
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []float32{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
case TILEDB_FLOAT64:
tmpDomain := domainSlice.([]float64)
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []float64{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
default:
return nil, fmt.Errorf("error creating non empty domain: unknown domain type")
}
}
return nonEmptyDomains, nil
}
// NonEmptyDomain retrieves the non-empty domain from an array
// This returns the bounding coordinates for each dimension
func (a *Array) NonEmptyDomain() ([]NonEmptyDomain, bool, error) {
schema, err := a.Schema()
if err != nil {
return nil, false, err
}
domain, err := schema.Domain()
if err != nil {
return nil, false, err
}
domainType, err := domain.Type()
if err != nil {
return nil, false, err
}
ndims, err := domain.NDim()
if err != nil {
return nil, false, err
}
tmpDomain, tmpDomainPtr, err := domainType.MakeSlice(uint64(2 * ndims))
if err != nil {
return nil, false, err
}
var isEmpty C.int32_t
ret := C.tiledb_array_get_non_empty_domain(a.context.tiledbContext, a.tiledbArray, tmpDomainPtr, &isEmpty)
if ret != C.TILEDB_OK {
return nil, false, fmt.Errorf("Error in getting non empty domain for array: %s", a.context.LastError())
}
if isEmpty == 1 {
return nil, true, nil
} else {
nonEmptyDomains, err := makeNonEmptyDomain(domain, tmpDomain)
if err != nil {
return nil, false, err
}
return nonEmptyDomains, false, nil
}
}
// MaxBufferSize computes the upper bound on the buffer size (in bytes)
// required for a read query for a given fixed attribute and subarray
func (a *Array) MaxBufferSize(attributeName string, subarray interface{}) (uint64, error) {
// Get Schema
schema, err := a.Schema()
if err != nil {
return 0, err
}
// Get domain from schema
domain, err := schema.Domain()
if err != nil {
return 0, err
}
// Get domain type to switch on
domainType, err := domain.Type()
if err != nil {
return 0, err
}
cAttributeName := C.CString(attributeName)
defer C.free(unsafe.Pointer(cAttributeName))
var bufferSize C.uint64_t
var ret C.int32_t
// Switch on domain type to cast subarray to proper type
switch domainType {
case TILEDB_INT8:
tmpSubArray := subarray.([]int8)
ret = C.tiledb_array_max_buffer_size(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferSize)
case TILEDB_INT16:
tmpSubArray := subarray.([]int16)
ret = C.tiledb_array_max_buffer_size(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferSize)
case TILEDB_INT32:
tmpSubArray := subarray.([]int32)
ret = C.tiledb_array_max_buffer_size(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferSize)
case TILEDB_INT64:
tmpSubArray := subarray.([]int64)
ret = C.tiledb_array_max_buffer_size(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferSize)
case TILEDB_UINT8:
tmpSubArray := subarray.([]uint8)
ret = C.tiledb_array_max_buffer_size(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferSize)
case TILEDB_UINT16:
tmpSubArray := subarray.([]uint16)
ret = C.tiledb_array_max_buffer_size(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferSize)
case TILEDB_UINT32:
tmpSubArray := subarray.([]uint32)
ret = C.tiledb_array_max_buffer_size(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferSize)
case TILEDB_UINT64:
tmpSubArray := subarray.([]uint64)
ret = C.tiledb_array_max_buffer_size(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferSize)
case TILEDB_FLOAT32:
tmpSubArray := subarray.([]float32)
ret = C.tiledb_array_max_buffer_size(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferSize)
case TILEDB_FLOAT64:
tmpSubArray := subarray.([]float64)
ret = C.tiledb_array_max_buffer_size(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferSize)
}
if ret != C.TILEDB_OK {
return 0, fmt.Errorf("Error in getting max buffer size for array: %s", a.context.LastError())
}
return uint64(bufferSize), nil
}
// MaxBufferSizeVar computes the upper bound on the buffer size (in bytes)
// required for a read query for a given variable sized attribute and subarray
func (a *Array) MaxBufferSizeVar(attributeName string, subarray interface{}) (uint64, uint64, error) {
// Get Schema
schema, err := a.Schema()
if err != nil {
return 0, 0, err
}
// Get domain from schema
domain, err := schema.Domain()
if err != nil {
return 0, 0, err
}
// Get domain type to switch on
domainType, err := domain.Type()
if err != nil {
return 0, 0, err
}
cAttributeName := C.CString(attributeName)
defer C.free(unsafe.Pointer(cAttributeName))
var bufferValSize C.uint64_t
var bufferOffSize C.uint64_t
var ret C.int32_t
// Switch on domain type to cast subarray to proper type
switch domainType {
case TILEDB_INT8:
tmpSubArray := subarray.([]int8)
ret = C.tiledb_array_max_buffer_size_var(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferOffSize, &bufferValSize)
case TILEDB_INT16:
tmpSubArray := subarray.([]int16)
ret = C.tiledb_array_max_buffer_size_var(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferOffSize, &bufferValSize)
case TILEDB_INT32:
tmpSubArray := subarray.([]int32)
ret = C.tiledb_array_max_buffer_size_var(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferOffSize, &bufferValSize)
case TILEDB_INT64:
tmpSubArray := subarray.([]int64)
ret = C.tiledb_array_max_buffer_size_var(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferOffSize, &bufferValSize)
case TILEDB_UINT8:
tmpSubArray := subarray.([]uint8)
ret = C.tiledb_array_max_buffer_size_var(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferOffSize, &bufferValSize)
case TILEDB_UINT16:
tmpSubArray := subarray.([]uint16)
ret = C.tiledb_array_max_buffer_size_var(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferOffSize, &bufferValSize)
case TILEDB_UINT32:
tmpSubArray := subarray.([]uint32)
ret = C.tiledb_array_max_buffer_size_var(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferOffSize, &bufferValSize)
case TILEDB_UINT64:
tmpSubArray := subarray.([]uint64)
ret = C.tiledb_array_max_buffer_size_var(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferOffSize, &bufferValSize)
case TILEDB_FLOAT32:
tmpSubArray := subarray.([]float32)
ret = C.tiledb_array_max_buffer_size_var(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferOffSize, &bufferValSize)
case TILEDB_FLOAT64:
tmpSubArray := subarray.([]float64)
ret = C.tiledb_array_max_buffer_size_var(a.context.tiledbContext, a.tiledbArray, cAttributeName, unsafe.Pointer(&tmpSubArray[0]), &bufferOffSize, &bufferValSize)
}
if ret != C.TILEDB_OK {
return 0, 0, fmt.Errorf("Error in getting max buffer size variable for array: %s", a.context.LastError())
}
return uint64(bufferOffSize), uint64(bufferValSize), nil
}
/*
MaxBufferElements compute an upper bound on the buffer elements needed to
read a subarray.
Returns A map of attribute name (including TILEDB_COORDS) to the maximum
number of elements that can be read in the given subarray. For each attribute,
a pair of numbers are returned. The first, for variable-length attributes, is
the maximum number of offsets for that attribute in the given subarray. For
fixed-length attributes and coordinates, the first is always 0. The second
is the maximum number of elements for that attribute in the given subarray.
*/
func (a *Array) MaxBufferElements(subarray interface{}) (map[string][2]uint64, error) {
// Build map
ret := make(map[string][2]uint64, 0)
// Get schema
schema, err := a.Schema()
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
}
attributes, err := schema.Attributes()
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
}
// Loop through each attribute
for _, attribute := range attributes {
// Check if attribute is variable attribute or not
cellValNum, err := attribute.CellValNum()
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
}
// Get datatype size to convert byte lengths to needed buffer sizes
dataType, err := attribute.Type()
dataTypeSize := dataType.Size()
// Get attribute name
name, err := attribute.Name()
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
}
if cellValNum == TILEDB_VAR_NUM {
bufferOffsetSize, bufferValSize, err := a.MaxBufferSizeVar(name, subarray)
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
}
// Set sizes for attribute in return map
ret[name] = [2]uint64{
bufferOffsetSize / uint64(C.TILEDB_OFFSET_SIZE),
bufferValSize / dataTypeSize}
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
}
} else {
bufferValSize, err := a.MaxBufferSize(name, subarray)
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
}
ret[name] = [2]uint64{0, bufferValSize / dataTypeSize}
}
}
// Handle coordinates
domain, err := schema.Domain()
if err != nil {
return nil, fmt.Errorf("Could not get domain for MaxBufferElements: %s", err)
}
domainType, err := domain.Type()
if err != nil {
return nil, fmt.Errorf("Could not get domainType for MaxBufferElements: %s", err)
}
bufferValSize, err := a.MaxBufferSize(TILEDB_COORDS, subarray)
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
}
ret[TILEDB_COORDS] = [2]uint64{0, bufferValSize / domainType.Size()}
return ret, nil
}
// URI returns the array's uri
func (a *Array) URI() (string, error) {
var curi *C.char
defer C.free(unsafe.Pointer(curi))
C.tiledb_array_get_uri(a.context.tiledbContext, a.tiledbArray, &curi)
uri := C.GoString(curi)
if uri == "" {
return uri, fmt.Errorf("Error getting URI for array: uri is empty")
}
return uri, nil
}