/
dimension.go
567 lines (524 loc) · 18.7 KB
/
dimension.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
package tiledb
/*
#cgo LDFLAGS: -ltiledb
#cgo linux LDFLAGS: -ldl
#include <tiledb/tiledb.h>
#include <stdlib.h>
*/
import "C"
import (
"fmt"
"os"
"reflect"
"strconv"
"unsafe"
)
// Dimension Describes one dimension of an Array.
// The dimension consists of a type, lower and upper bound, and tile-extent
// describing the memory ordering. Dimensions are added to a Domain.
type Dimension struct {
tiledbDimension *C.tiledb_dimension_t
context *Context
}
// NewDimension alloc a new dimension
func NewDimension(context *Context, name string, datatype Datatype, domain interface{}, extent interface{}) (*Dimension, error) {
dimension := Dimension{context: context}
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
if reflect.TypeOf(domain).Kind() != reflect.Slice {
return nil, fmt.Errorf("Domain passed must be a slice of two integers or two floats, type passed was: %s", reflect.TypeOf(domain).Kind().String())
}
domainInterfaceVal := reflect.ValueOf(domain)
if domainInterfaceVal.Len() != 2 {
return nil, fmt.Errorf("Domain passed must be a slice of two integers or two floats, size of slice is: %d", domainInterfaceVal.Len())
}
domainType := reflect.TypeOf(domain).Elem().Kind()
extentType := reflect.TypeOf(extent).Kind()
if extentType != domainType {
return nil, fmt.Errorf("domain and extent do not have the same data types. Domain: %s, Extent: %s", domainType, extentType)
}
// Domain data type need to match datatype passed
domainTypeMatchDatatype := true
var ret C.int32_t
// Convert domain to type then to void*
var cdomain unsafe.Pointer
// Convert extent to type then to void*
var cextent unsafe.Pointer
// Switch on datatype type to create void* for domain and extent.
// Extent has already checked to be same type as domain so this is safe
switch datatype {
case TILEDB_INT8:
if domainType != reflect.Int8 {
domainTypeMatchDatatype = false
break
}
// Create domain void*
tmpDomain := domain.([]int8)
cdomain = unsafe.Pointer(&tmpDomain[0])
// Create extent void*
tmpExtent := (extent.(int8))
cextent = unsafe.Pointer(&tmpExtent)
case TILEDB_INT16:
if domainType != reflect.Int16 {
domainTypeMatchDatatype = false
break
}
// Create domain void*
tmpDomain := domain.([]int16)
cdomain = unsafe.Pointer(&tmpDomain[0])
// Create extent void*
tmpExtent := (extent.(int16))
cextent = unsafe.Pointer(&tmpExtent)
case TILEDB_INT32:
if domainType != reflect.Int32 && domainType != reflect.Int {
domainTypeMatchDatatype = false
break
}
if domainType == reflect.Int && strconv.IntSize == 64 {
// User asked for Int64 if size of int on platform is 64 bit
domainTypeMatchDatatype = false
break
}
// Create domain void*
tmpDomain := domain.([]int32)
cdomain = unsafe.Pointer(&tmpDomain[0])
// Create extent void*
tmpExtent := (extent.(int32))
cextent = unsafe.Pointer(&tmpExtent)
case TILEDB_INT64, TILEDB_DATETIME_YEAR, TILEDB_DATETIME_MONTH, TILEDB_DATETIME_WEEK, TILEDB_DATETIME_DAY, TILEDB_DATETIME_HR, TILEDB_DATETIME_MIN, TILEDB_DATETIME_SEC, TILEDB_DATETIME_MS, TILEDB_DATETIME_US, TILEDB_DATETIME_NS, TILEDB_DATETIME_PS, TILEDB_DATETIME_FS, TILEDB_DATETIME_AS, TILEDB_TIME_HR, TILEDB_TIME_MIN, TILEDB_TIME_SEC, TILEDB_TIME_MS, TILEDB_TIME_US, TILEDB_TIME_NS, TILEDB_TIME_PS, TILEDB_TIME_FS, TILEDB_TIME_AS:
if domainType != reflect.Int64 && domainType != reflect.Int {
domainTypeMatchDatatype = false
break
}
if domainType == reflect.Int && strconv.IntSize == 32 {
// User asked for Int32 if size of int on platform is 32 bit
domainTypeMatchDatatype = false
break
}
// Create domain void*
tmpDomain := domain.([]int64)
cdomain = unsafe.Pointer(&tmpDomain[0])
// Create extent void*
tmpExtent := (extent.(int64))
cextent = unsafe.Pointer(&tmpExtent)
case TILEDB_UINT8:
if domainType != reflect.Uint8 {
domainTypeMatchDatatype = false
break
}
// Create domain void*
tmpDomain := domain.([]uint8)
cdomain = unsafe.Pointer(&tmpDomain[0])
// Create extent void*
tmpExtent := (extent.(uint8))
cextent = unsafe.Pointer(&tmpExtent)
case TILEDB_UINT16:
if domainType != reflect.Uint16 {
domainTypeMatchDatatype = false
break
}
// Create domain void*
tmpDomain := domain.([]uint16)
cdomain = unsafe.Pointer(&tmpDomain[0])
// Create extent void*
tmpExtent := (extent.(uint16))
cextent = unsafe.Pointer(&tmpExtent)
case TILEDB_UINT32:
if domainType != reflect.Uint32 && domainType != reflect.Uint {
domainTypeMatchDatatype = false
break
}
if domainType == reflect.Uint && strconv.IntSize == 64 {
// User asked for Uint64 if size of int on platform is 64 bit
domainTypeMatchDatatype = false
break
}
// Create domain void*
tmpDomain := domain.([]uint32)
cdomain = unsafe.Pointer(&tmpDomain[0])
// Create extent void*
tmpExtent := (extent.(uint32))
cextent = unsafe.Pointer(&tmpExtent)
case TILEDB_UINT64:
if domainType != reflect.Uint64 && domainType != reflect.Uint {
domainTypeMatchDatatype = false
break
}
if domainType == reflect.Uint && strconv.IntSize == 32 {
// User asked for Uint32 if size of int on platform is 32 bit
domainTypeMatchDatatype = false
break
}
// Create domain void*
tmpDomain := domain.([]uint64)
cdomain = unsafe.Pointer(&tmpDomain[0])
// Create extent void*
tmpExtent := (extent.(uint64))
cextent = unsafe.Pointer(&tmpExtent)
case TILEDB_FLOAT32:
if domainType != reflect.Float32 {
domainTypeMatchDatatype = false
break
}
// Create domain void*
tmpDomain := domain.([]float32)
cdomain = unsafe.Pointer(&tmpDomain[0])
// Create extent void*
tmpExtent := (extent.(float32))
cextent = unsafe.Pointer(&tmpExtent)
case TILEDB_FLOAT64:
if domainType != reflect.Float64 {
domainTypeMatchDatatype = false
break
}
// Create domain void*
tmpDomain := domain.([]float64)
cdomain = unsafe.Pointer(&tmpDomain[0])
// Create extent void*
tmpExtent := (extent.(float64))
cextent = unsafe.Pointer(&tmpExtent)
case TILEDB_BOOL:
if domainType != reflect.Bool {
domainTypeMatchDatatype = false
break
}
// Create domain void*
tmpDomain := domain.([]bool)
cdomain = unsafe.Pointer(&tmpDomain[0])
// Create extent void*
tmpExtent := (extent.(bool))
cextent = unsafe.Pointer(&tmpExtent)
default:
return nil, fmt.Errorf("Unrecognized datatype passed: %s", datatype.String())
}
if !domainTypeMatchDatatype {
return nil, fmt.Errorf("domain and datatype do not have the same data types. Domain: %s, Datatype: %s", domainType.String(), datatype.String())
}
ret = C.tiledb_dimension_alloc(context.tiledbContext, cname, C.tiledb_datatype_t(datatype), cdomain, cextent, &dimension.tiledbDimension)
if ret != C.TILEDB_OK {
return nil, fmt.Errorf("error creating tiledb dimension: %s", context.LastError())
}
freeOnGC(&dimension)
return &dimension, nil
}
// NewStringDimension alloc a new string dimension
func NewStringDimension(context *Context, name string) (*Dimension, error) {
dimension := Dimension{context: context}
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
var datatype Datatype
var ret C.int32_t
datatype = TILEDB_STRING_ASCII
ret = C.tiledb_dimension_alloc(context.tiledbContext, cname, C.tiledb_datatype_t(datatype), nil, nil, &dimension.tiledbDimension)
if ret != C.TILEDB_OK {
return nil, fmt.Errorf("Error creating tiledb dimension: %s", context.LastError())
}
freeOnGC(&dimension)
return &dimension, nil
}
// Free releases the internal TileDB core data that was allocated on the C heap.
// It is automatically called when this object is garbage collected, but can be
// called earlier to manually release memory if needed. Free is idempotent and
// can safely be called many times on the same object; if it has already
// been freed, it will not be freed again.
func (d *Dimension) Free() {
if d.tiledbDimension != nil {
C.tiledb_dimension_free(&d.tiledbDimension)
}
}
// Context exposes the internal TileDB context used to initialize the dimension
func (d *Dimension) Context() *Context {
return d.context
}
// SetFilterList sets the dimension filterList
func (d *Dimension) SetFilterList(filterlist *FilterList) error {
ret := C.tiledb_dimension_set_filter_list(d.context.tiledbContext, d.tiledbDimension, filterlist.tiledbFilterList)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error setting tiledb dimension filter list: %s", d.context.LastError())
}
return nil
}
// FilterList returns a copy of the filter list for attribute
func (d *Dimension) FilterList() (*FilterList, error) {
filterList := FilterList{context: d.context}
ret := C.tiledb_dimension_get_filter_list(d.context.tiledbContext, d.tiledbDimension, &filterList.tiledbFilterList)
if ret != C.TILEDB_OK {
return nil, fmt.Errorf("Error getting tiledb dimension filter list: %s", d.context.LastError())
}
freeOnGC(&filterList)
return &filterList, nil
}
// SetCellValNum Sets the number of values per cell for a dimension.
// If this is not used, the default is `1`.
// This is inferred from the type parameter of the NewDimension
// function, but can also be set manually.
func (d *Dimension) SetCellValNum(val uint32) error {
ret := C.tiledb_dimension_set_cell_val_num(d.context.tiledbContext,
d.tiledbDimension, C.uint32_t(val))
if ret != C.TILEDB_OK {
return fmt.Errorf("Error setting tiledb dimension cell val num: %s", d.context.LastError())
}
return nil
}
// CellValNum returns number of values of one cell on this attribute.
// For variable-sized attributes returns TILEDB_VAR_NUM.
func (d *Dimension) CellValNum() (uint32, error) {
var cellValNum C.uint32_t
ret := C.tiledb_dimension_get_cell_val_num(d.context.tiledbContext, d.tiledbDimension, &cellValNum)
if ret != C.TILEDB_OK {
return 0, fmt.Errorf("Error getting tiledb dimension cell val num: %s", d.context.LastError())
}
return uint32(cellValNum), nil
}
// Name returns the name of the dimension
func (d *Dimension) Name() (string, error) {
var cName *C.char
ret := C.tiledb_dimension_get_name(d.context.tiledbContext, d.tiledbDimension, &cName)
if ret != C.TILEDB_OK {
return "", fmt.Errorf("Error getting tiledb dimension name: %s", d.context.LastError())
}
return C.GoString(cName), nil
}
// Type returns the type of the dimension
func (d *Dimension) Type() (Datatype, error) {
var cType C.tiledb_datatype_t
ret := C.tiledb_dimension_get_type(d.context.tiledbContext, d.tiledbDimension, &cType)
if ret != C.TILEDB_OK {
return 0, fmt.Errorf("Error getting tiledb dimension type: %s", d.context.LastError())
}
return Datatype(cType), nil
}
// Domain returns the dimension's domain
func (d *Dimension) Domain() (interface{}, error) {
datatype, err := d.Type()
if err != nil {
return nil, err
}
var ret C.int32_t
var domain interface{}
switch datatype {
case TILEDB_INT8:
cdomain := C.malloc(2 * C.sizeof_int8_t)
defer C.free(cdomain)
tmpDomain := make([]int8, 2)
ret = C.tiledb_dimension_get_domain(d.context.tiledbContext, d.tiledbDimension, &cdomain)
tmpslice := (*[1 << 46]C.int8_t)(unsafe.Pointer(cdomain))[:2:2]
for i, s := range tmpslice {
tmpDomain[i] = int8(s)
}
domain = tmpDomain
case TILEDB_INT16:
cdomain := C.malloc(2 * C.sizeof_int16_t)
defer C.free(cdomain)
tmpDomain := make([]int16, 2)
ret = C.tiledb_dimension_get_domain(d.context.tiledbContext, d.tiledbDimension, &cdomain)
tmpslice := (*[1 << 46]C.int16_t)(unsafe.Pointer(cdomain))[:2:2]
for i, s := range tmpslice {
tmpDomain[i] = int16(s)
}
domain = tmpDomain
case TILEDB_INT32:
cdomain := C.malloc(2 * C.sizeof_int32_t)
defer C.free(cdomain)
tmpDomain := make([]int32, 2)
ret = C.tiledb_dimension_get_domain(d.context.tiledbContext, d.tiledbDimension, &cdomain)
tmpslice := (*[1 << 46]C.int32_t)(unsafe.Pointer(cdomain))[:2:2]
for i, s := range tmpslice {
tmpDomain[i] = int32(s)
}
domain = tmpDomain
case TILEDB_INT64:
cdomain := C.malloc(2 * C.sizeof_int64_t)
defer C.free(cdomain)
tmpDomain := make([]int64, 2)
ret = C.tiledb_dimension_get_domain(d.context.tiledbContext, d.tiledbDimension, &cdomain)
tmpslice := (*[1 << 46]C.int64_t)(unsafe.Pointer(cdomain))[:2:2]
for i, s := range tmpslice {
tmpDomain[i] = int64(s)
}
domain = tmpDomain
case TILEDB_UINT8:
cdomain := C.malloc(2 * C.sizeof_uint8_t)
defer C.free(cdomain)
tmpDomain := make([]uint8, 2)
ret = C.tiledb_dimension_get_domain(d.context.tiledbContext, d.tiledbDimension, &cdomain)
tmpslice := (*[1 << 46]C.uint8_t)(unsafe.Pointer(cdomain))[:2:2]
for i, s := range tmpslice {
tmpDomain[i] = uint8(s)
}
domain = tmpDomain
case TILEDB_UINT16:
cdomain := C.malloc(2 * C.sizeof_uint16_t)
defer C.free(cdomain)
tmpDomain := make([]uint16, 2)
ret = C.tiledb_dimension_get_domain(d.context.tiledbContext, d.tiledbDimension, &cdomain)
tmpslice := (*[1 << 46]C.uint16_t)(unsafe.Pointer(cdomain))[:2:2]
for i, s := range tmpslice {
tmpDomain[i] = uint16(s)
}
domain = tmpDomain
case TILEDB_UINT32:
cdomain := C.malloc(2 * C.sizeof_uint32_t)
defer C.free(cdomain)
tmpDomain := make([]uint32, 2)
ret = C.tiledb_dimension_get_domain(d.context.tiledbContext, d.tiledbDimension, &cdomain)
tmpslice := (*[1 << 46]C.uint32_t)(unsafe.Pointer(cdomain))[:2:2]
for i, s := range tmpslice {
tmpDomain[i] = uint32(s)
}
domain = tmpDomain
case TILEDB_UINT64:
cdomain := C.malloc(2 * C.sizeof_uint64_t)
defer C.free(cdomain)
tmpDomain := make([]uint64, 2)
ret = C.tiledb_dimension_get_domain(d.context.tiledbContext, d.tiledbDimension, &cdomain)
tmpslice := (*[1 << 46]C.uint64_t)(unsafe.Pointer(cdomain))[:2:2]
for i, s := range tmpslice {
tmpDomain[i] = uint64(s)
}
domain = tmpDomain
case TILEDB_FLOAT32:
cdomain := C.malloc(2 * C.sizeof_float)
defer C.free(cdomain)
tmpDomain := make([]float32, 2)
ret = C.tiledb_dimension_get_domain(d.context.tiledbContext, d.tiledbDimension, &cdomain)
tmpslice := (*[1 << 46]C.float)(unsafe.Pointer(cdomain))[:2:2]
for i, s := range tmpslice {
tmpDomain[i] = float32(s)
}
domain = tmpDomain
case TILEDB_FLOAT64:
cdomain := C.malloc(2 * C.sizeof_double)
defer C.free(cdomain)
tmpDomain := make([]float64, 2)
ret = C.tiledb_dimension_get_domain(d.context.tiledbContext, d.tiledbDimension, &cdomain)
tmpslice := (*[1 << 46]C.double)(unsafe.Pointer(cdomain))[:2:2]
for i, s := range tmpslice {
tmpDomain[i] = float64(s)
}
domain = tmpDomain
case TILEDB_BOOL:
cdomain := C.malloc(2 * C.sizeof_double)
defer C.free(cdomain)
tmpDomain := make([]bool, 2)
ret = C.tiledb_dimension_get_domain(d.context.tiledbContext, d.tiledbDimension, &cdomain)
tmpslice := (*[1 << 46]C.uint8_t)(unsafe.Pointer(cdomain))[:2:2]
for i, s := range tmpslice {
if s != 0 {
tmpDomain[i] = true
}
}
domain = tmpDomain
case TILEDB_STRING_ASCII:
domain = nil
default:
return nil, fmt.Errorf("Unrecognized domain type: %d", datatype)
}
if ret != C.TILEDB_OK {
return nil, fmt.Errorf("Error getting tiledb dimension's domain: %s", d.context.LastError())
}
return domain, nil
}
// Extent returns the dimension's extent
func (d *Dimension) Extent() (interface{}, error) {
datatype, err := d.Type()
if err != nil {
return nil, err
}
var ret C.int32_t
var extent interface{}
switch datatype {
case TILEDB_INT8:
cextent := C.malloc(C.sizeof_int8_t)
defer C.free(cextent)
ret = C.tiledb_dimension_get_tile_extent(d.context.tiledbContext, d.tiledbDimension, &cextent)
extent = *(*int8)(unsafe.Pointer(cextent))
case TILEDB_INT16:
cextent := C.malloc(C.sizeof_int16_t)
defer C.free(cextent)
ret = C.tiledb_dimension_get_tile_extent(d.context.tiledbContext, d.tiledbDimension, &cextent)
extent = *(*int16)(unsafe.Pointer(cextent))
case TILEDB_INT32:
cextent := C.malloc(C.sizeof_int32_t)
defer C.free(cextent)
ret = C.tiledb_dimension_get_tile_extent(d.context.tiledbContext, d.tiledbDimension, &cextent)
extent = *(*int32)(unsafe.Pointer(cextent))
case TILEDB_INT64:
cextent := C.malloc(C.sizeof_int64_t)
defer C.free(cextent)
ret = C.tiledb_dimension_get_tile_extent(d.context.tiledbContext, d.tiledbDimension, &cextent)
extent = *(*int64)(unsafe.Pointer(cextent))
case TILEDB_UINT8:
cextent := C.malloc(C.sizeof_uint8_t)
defer C.free(cextent)
ret = C.tiledb_dimension_get_tile_extent(d.context.tiledbContext, d.tiledbDimension, &cextent)
extent = *(*uint8)(unsafe.Pointer(cextent))
case TILEDB_UINT16:
cextent := C.malloc(C.sizeof_uint16_t)
defer C.free(cextent)
ret = C.tiledb_dimension_get_tile_extent(d.context.tiledbContext, d.tiledbDimension, &cextent)
extent = *(*uint16)(unsafe.Pointer(cextent))
case TILEDB_UINT32:
cextent := C.malloc(C.sizeof_uint32_t)
defer C.free(cextent)
ret = C.tiledb_dimension_get_tile_extent(d.context.tiledbContext, d.tiledbDimension, &cextent)
extent = *(*uint32)(unsafe.Pointer(cextent))
case TILEDB_UINT64:
cextent := C.malloc(C.sizeof_uint64_t)
defer C.free(cextent)
ret = C.tiledb_dimension_get_tile_extent(d.context.tiledbContext, d.tiledbDimension, &cextent)
extent = *(*uint64)(unsafe.Pointer(cextent))
case TILEDB_FLOAT32:
cextent := C.malloc(C.sizeof_float)
defer C.free(cextent)
ret = C.tiledb_dimension_get_tile_extent(d.context.tiledbContext, d.tiledbDimension, &cextent)
extent = *(*float32)(unsafe.Pointer(cextent))
case TILEDB_FLOAT64:
cextent := C.malloc(C.sizeof_double)
defer C.free(cextent)
ret = C.tiledb_dimension_get_tile_extent(d.context.tiledbContext, d.tiledbDimension, &cextent)
extent = *(*float64)(unsafe.Pointer(cextent))
case TILEDB_BOOL:
cextent := C.malloc(C.sizeof_uint8_t)
defer C.free(cextent)
ret = C.tiledb_dimension_get_tile_extent(d.context.tiledbContext, d.tiledbDimension, &cextent)
extent = *(*bool)(unsafe.Pointer(cextent))
case TILEDB_STRING_ASCII:
extent = nil
default:
return nil, fmt.Errorf("Unrecognized extent type: %d", datatype)
}
if ret != C.TILEDB_OK {
return nil, fmt.Errorf("Error getting tiledb dimension's extent: %s", d.context.LastError())
}
return extent, nil
}
// DumpSTDOUT Dumps the dimension in ASCII format to stdout
func (d *Dimension) DumpSTDOUT() error {
ret := C.tiledb_dimension_dump(d.context.tiledbContext, d.tiledbDimension, C.stdout)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error dumping dimension to stdout: %s", d.context.LastError())
}
return nil
}
// Dump Dumps the dimension in ASCII format in the selected output.
func (d *Dimension) Dump(path string) error {
if _, err := os.Stat(path); err == nil {
return fmt.Errorf("Error path already %s exists", path)
}
// Convert to char *
cPath := C.CString(path)
defer C.free(unsafe.Pointer(cPath))
// Set mode as char*
cMode := C.CString("w")
defer C.free(unsafe.Pointer(cMode))
// Open file to get FILE*
cFile := C.fopen(cPath, cMode)
defer C.fclose(cFile)
// Dump dimension to file
ret := C.tiledb_dimension_dump(d.context.tiledbContext, d.tiledbDimension, cFile)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error dumping dimension to file %s: %s", path, d.context.LastError())
}
return nil
}