Skip to content

Commit 6f2f84a

Browse files
tdennistonShelnutt2
authored andcommitted
Wrap non-empty domain serialization/deserialization APIs.
1 parent 11ebb86 commit 6f2f84a

File tree

3 files changed

+164
-205
lines changed

3 files changed

+164
-205
lines changed

array.go

+77-203
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,70 @@ func (a *Array) QueryType() (QueryType, error) {
237237
return QueryType(queryType), nil
238238
}
239239

240+
// makeNonEmptyDomain creates a []NonEmptyDomain from a generic domain-typed slice
241+
func makeNonEmptyDomain(domain *Domain, domainSlice interface{}) ([]NonEmptyDomain, error) {
242+
domainType, err := domain.Type()
243+
if err != nil {
244+
return nil, err
245+
}
246+
ndims, err := domain.NDim()
247+
if err != nil {
248+
return nil, err
249+
}
250+
251+
nonEmptyDomains := make([]NonEmptyDomain, 0)
252+
for i := uint(0); i < ndims; i++ {
253+
dimension, err := domain.DimensionFromIndex(i)
254+
if err != nil {
255+
return nil, err
256+
}
257+
name, err := dimension.Name()
258+
if err != nil {
259+
return nil, err
260+
}
261+
262+
switch domainType {
263+
case TILEDB_INT8:
264+
tmpDomain := domainSlice.([]int8)
265+
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []int8{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
266+
case TILEDB_INT16:
267+
tmpDomain := domainSlice.([]int16)
268+
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []int16{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
269+
case TILEDB_INT32:
270+
tmpDomain := domainSlice.([]int32)
271+
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []int32{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
272+
case TILEDB_INT64:
273+
tmpDomain := domainSlice.([]int64)
274+
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []int64{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
275+
case TILEDB_UINT8:
276+
tmpDomain := domainSlice.([]uint8)
277+
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []uint8{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
278+
case TILEDB_UINT16:
279+
tmpDomain := domainSlice.([]uint16)
280+
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []uint16{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
281+
case TILEDB_UINT32:
282+
tmpDomain := domainSlice.([]uint32)
283+
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []uint32{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
284+
case TILEDB_UINT64:
285+
tmpDomain := domainSlice.([]uint64)
286+
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []uint64{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
287+
case TILEDB_FLOAT32:
288+
tmpDomain := domainSlice.([]float32)
289+
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []float32{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
290+
case TILEDB_FLOAT64:
291+
tmpDomain := domainSlice.([]float64)
292+
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []float64{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
293+
default:
294+
return nil, fmt.Errorf("error creating non empty domain: unknown domain type")
295+
}
296+
}
297+
298+
return nonEmptyDomains, nil
299+
}
300+
240301
// NonEmptyDomain retrieves the non-empty domain from an array
241302
// This returns the bounding coordinates for each dimension
242303
func (a *Array) NonEmptyDomain() ([]NonEmptyDomain, bool, error) {
243-
nonEmptyDomains := make([]NonEmptyDomain, 0)
244304
schema, err := a.Schema()
245305
if err != nil {
246306
return nil, false, err
@@ -261,212 +321,26 @@ func (a *Array) NonEmptyDomain() ([]NonEmptyDomain, bool, error) {
261321
return nil, false, err
262322
}
263323

264-
var ret C.int32_t
324+
tmpDomain, tmpDomainPtr, err := domainType.MakeSlice(uint64(2 * ndims))
325+
if err != nil {
326+
return nil, false, err
327+
}
328+
265329
var isEmpty C.int32_t
266-
switch domainType {
330+
ret := C.tiledb_array_get_non_empty_domain(a.context.tiledbContext, a.tiledbArray, tmpDomainPtr, &isEmpty)
331+
if ret != C.TILEDB_OK {
332+
return nil, false, fmt.Errorf("Error in getting non empty domain for array: %s", a.context.LastError())
333+
}
267334

268-
case TILEDB_INT8:
269-
tmpDomain := make([]int8, 2*ndims)
270-
ret = C.tiledb_array_get_non_empty_domain(a.context.tiledbContext, a.tiledbArray, unsafe.Pointer(&tmpDomain[0]), &isEmpty)
271-
if ret != C.TILEDB_OK {
272-
return nil, false, fmt.Errorf("Error in getting non empty domain for array: %s", a.context.LastError())
273-
}
274-
if isEmpty == 0 {
275-
for i := uint(0); i < ndims; i++ {
276-
dimension, err := domain.DimensionFromIndex(i)
277-
if err != nil {
278-
return nil, false, err
279-
}
280-
281-
name, err := dimension.Name()
282-
if err != nil {
283-
return nil, false, err
284-
}
285-
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []int8{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
286-
}
287-
}
288-
case TILEDB_INT16:
289-
tmpDomain := make([]int16, 2*ndims)
290-
ret = C.tiledb_array_get_non_empty_domain(a.context.tiledbContext, a.tiledbArray, unsafe.Pointer(&tmpDomain[0]), &isEmpty)
291-
if ret != C.TILEDB_OK {
292-
return nil, false, fmt.Errorf("Error in getting non empty domain for array: %s", a.context.LastError())
293-
}
294-
if isEmpty == 0 {
295-
for i := uint(0); i < ndims; i++ {
296-
dimension, err := domain.DimensionFromIndex(i)
297-
if err != nil {
298-
return nil, false, err
299-
}
300-
301-
name, err := dimension.Name()
302-
if err != nil {
303-
return nil, false, err
304-
}
305-
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []int16{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
306-
}
307-
}
308-
case TILEDB_INT32:
309-
tmpDomain := make([]int32, 2*ndims)
310-
ret = C.tiledb_array_get_non_empty_domain(a.context.tiledbContext, a.tiledbArray, unsafe.Pointer(&tmpDomain[0]), &isEmpty)
311-
if ret != C.TILEDB_OK {
312-
return nil, false, fmt.Errorf("Error in getting non empty domain for array: %s", a.context.LastError())
313-
}
314-
if isEmpty == 0 {
315-
for i := uint(0); i < ndims; i++ {
316-
dimension, err := domain.DimensionFromIndex(i)
317-
if err != nil {
318-
return nil, false, err
319-
}
320-
321-
name, err := dimension.Name()
322-
if err != nil {
323-
return nil, false, err
324-
}
325-
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []int32{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
326-
}
327-
}
328-
case TILEDB_INT64:
329-
tmpDomain := make([]int64, 2*ndims)
330-
ret = C.tiledb_array_get_non_empty_domain(a.context.tiledbContext, a.tiledbArray, unsafe.Pointer(&tmpDomain[0]), &isEmpty)
331-
if ret != C.TILEDB_OK {
332-
return nil, false, fmt.Errorf("Error in getting non empty domain for array: %s", a.context.LastError())
333-
}
334-
if isEmpty == 0 {
335-
for i := uint(0); i < ndims; i++ {
336-
dimension, err := domain.DimensionFromIndex(i)
337-
if err != nil {
338-
return nil, false, err
339-
}
340-
341-
name, err := dimension.Name()
342-
if err != nil {
343-
return nil, false, err
344-
}
345-
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []int64{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
346-
}
347-
}
348-
case TILEDB_UINT8:
349-
tmpDomain := make([]uint8, 2*ndims)
350-
ret = C.tiledb_array_get_non_empty_domain(a.context.tiledbContext, a.tiledbArray, unsafe.Pointer(&tmpDomain[0]), &isEmpty)
351-
if ret != C.TILEDB_OK {
352-
return nil, false, fmt.Errorf("Error in getting non empty domain for array: %s", a.context.LastError())
353-
}
354-
if isEmpty == 0 {
355-
for i := uint(0); i < ndims; i++ {
356-
dimension, err := domain.DimensionFromIndex(i)
357-
if err != nil {
358-
return nil, false, err
359-
}
360-
361-
name, err := dimension.Name()
362-
if err != nil {
363-
return nil, false, err
364-
}
365-
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []uint8{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
366-
}
367-
}
368-
case TILEDB_UINT16:
369-
tmpDomain := make([]uint16, 2*ndims)
370-
ret = C.tiledb_array_get_non_empty_domain(a.context.tiledbContext, a.tiledbArray, unsafe.Pointer(&tmpDomain[0]), &isEmpty)
371-
if ret != C.TILEDB_OK {
372-
return nil, false, fmt.Errorf("Error in getting non empty domain for array: %s", a.context.LastError())
373-
}
374-
if isEmpty == 0 {
375-
for i := uint(0); i < ndims; i++ {
376-
dimension, err := domain.DimensionFromIndex(i)
377-
if err != nil {
378-
return nil, false, err
379-
}
380-
381-
name, err := dimension.Name()
382-
if err != nil {
383-
return nil, false, err
384-
}
385-
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []uint16{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
386-
}
387-
}
388-
case TILEDB_UINT32:
389-
tmpDomain := make([]uint32, 2*ndims)
390-
ret = C.tiledb_array_get_non_empty_domain(a.context.tiledbContext, a.tiledbArray, unsafe.Pointer(&tmpDomain[0]), &isEmpty)
391-
if ret != C.TILEDB_OK {
392-
return nil, false, fmt.Errorf("Error in getting non empty domain for array: %s", a.context.LastError())
393-
}
394-
if isEmpty == 0 {
395-
for i := uint(0); i < ndims; i++ {
396-
dimension, err := domain.DimensionFromIndex(i)
397-
if err != nil {
398-
return nil, false, err
399-
}
400-
401-
name, err := dimension.Name()
402-
if err != nil {
403-
return nil, false, err
404-
}
405-
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []uint32{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
406-
}
407-
}
408-
case TILEDB_UINT64:
409-
tmpDomain := make([]uint64, 2*ndims)
410-
ret = C.tiledb_array_get_non_empty_domain(a.context.tiledbContext, a.tiledbArray, unsafe.Pointer(&tmpDomain[0]), &isEmpty)
411-
if ret != C.TILEDB_OK {
412-
return nil, false, fmt.Errorf("Error in getting non empty domain for array: %s", a.context.LastError())
413-
}
414-
if isEmpty == 0 {
415-
for i := uint(0); i < ndims; i++ {
416-
dimension, err := domain.DimensionFromIndex(i)
417-
if err != nil {
418-
return nil, false, err
419-
}
420-
421-
name, err := dimension.Name()
422-
if err != nil {
423-
return nil, false, err
424-
}
425-
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []uint64{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
426-
}
427-
}
428-
case TILEDB_FLOAT32:
429-
tmpDomain := make([]float32, 2*ndims)
430-
ret = C.tiledb_array_get_non_empty_domain(a.context.tiledbContext, a.tiledbArray, unsafe.Pointer(&tmpDomain[0]), &isEmpty)
431-
if ret != C.TILEDB_OK {
432-
return nil, false, fmt.Errorf("Error in getting non empty domain for array: %s", a.context.LastError())
433-
}
434-
if isEmpty == 0 {
435-
for i := uint(0); i < ndims; i++ {
436-
dimension, err := domain.DimensionFromIndex(i)
437-
if err != nil {
438-
return nil, false, err
439-
}
440-
441-
name, err := dimension.Name()
442-
if err != nil {
443-
return nil, false, err
444-
}
445-
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []float32{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
446-
}
447-
}
448-
case TILEDB_FLOAT64:
449-
tmpDomain := make([]float64, 2*ndims)
450-
ret = C.tiledb_array_get_non_empty_domain(a.context.tiledbContext, a.tiledbArray, unsafe.Pointer(&tmpDomain[0]), &isEmpty)
451-
if ret != C.TILEDB_OK {
452-
return nil, false, fmt.Errorf("Error in getting non empty domain for array: %s", a.context.LastError())
453-
}
454-
if isEmpty == 0 {
455-
for i := uint(0); i < ndims; i++ {
456-
dimension, err := domain.DimensionFromIndex(i)
457-
if err != nil {
458-
return nil, false, err
459-
}
460-
461-
name, err := dimension.Name()
462-
if err != nil {
463-
return nil, false, err
464-
}
465-
nonEmptyDomains = append(nonEmptyDomains, NonEmptyDomain{DimensionName: name, Bounds: []float64{tmpDomain[i*2], tmpDomain[(i*2)+1]}})
466-
}
335+
if isEmpty == 1 {
336+
return nil, true, nil
337+
} else {
338+
nonEmptyDomains, err := makeNonEmptyDomain(domain, tmpDomain)
339+
if err != nil {
340+
return nil, false, err
467341
}
342+
return nonEmptyDomains, false, nil
468343
}
469-
return nonEmptyDomains, isEmpty == 1, nil
470344
}
471345

472346
// MaxBufferSize computes the upper bound on the buffer size (in bytes)

array_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func TestArray(t *testing.T) {
190190
// Get non empty domain, which is none since no data has been written
191191
nonEmptyDomain, isEmpty, err := array.NonEmptyDomain()
192192
assert.Nil(t, err)
193-
assert.NotNil(t, nonEmptyDomain)
193+
assert.Nil(t, nonEmptyDomain)
194194
assert.True(t, isEmpty)
195195

196196
// Get MaxBufferSize, which is 0 because array is empty
@@ -279,7 +279,7 @@ func TestArrayEncryption(t *testing.T) {
279279
// Get non empty domain, which is none since no data has been written
280280
nonEmptyDomain, isEmpty, err := array.NonEmptyDomain()
281281
assert.Nil(t, err)
282-
assert.NotNil(t, nonEmptyDomain)
282+
assert.Nil(t, nonEmptyDomain)
283283
assert.True(t, isEmpty)
284284

285285
// Get MaxBufferSize, which is 0 because array is empty

0 commit comments

Comments
 (0)