Skip to content

Commit d8e3964

Browse files
committed
Move standalone array/groups functions at the top.
1 parent 1f09c94 commit d8e3964

File tree

2 files changed

+66
-66
lines changed

2 files changed

+66
-66
lines changed

array.go

+53-53
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,59 @@ func newArrayFromHandle(tdbCtx *Context, arrayHandle arrayHandle) *Array {
6969
return &Array{context: tdbCtx, tiledbArray: arrayHandle}
7070
}
7171

72+
// ConsolidateArray consolidates the fragments of an array into a single fragment.
73+
// You must first finalize all queries to the array before consolidation can
74+
// begin (as consolidation temporarily acquires an exclusive lock on the array).
75+
func ConsolidateArray(tdbCtx *Context, uri string, config *Config) error {
76+
if config == nil {
77+
return errors.New("Config must not be nil for Consolidate")
78+
}
79+
80+
curi := C.CString(uri)
81+
defer C.free(unsafe.Pointer(curi))
82+
ret := C.tiledb_array_consolidate(tdbCtx.tiledbContext.Get(), curi, config.tiledbConfig.Get())
83+
runtime.KeepAlive(tdbCtx)
84+
runtime.KeepAlive(config)
85+
if ret != C.TILEDB_OK {
86+
return fmt.Errorf("error consolidating tiledb array: %w", tdbCtx.LastError())
87+
}
88+
89+
runtime.KeepAlive(config)
90+
return nil
91+
}
92+
93+
// CreateArray creates a new TileDB array given a context, URI and schema.
94+
func CreateArray(tdbCtx *Context, uri string, arraySchema *ArraySchema) error {
95+
curi := C.CString(uri)
96+
defer C.free(unsafe.Pointer(curi))
97+
ret := C.tiledb_array_create(tdbCtx.tiledbContext.Get(), curi, arraySchema.tiledbArraySchema.Get())
98+
runtime.KeepAlive(tdbCtx)
99+
runtime.KeepAlive(arraySchema)
100+
if ret != C.TILEDB_OK {
101+
return fmt.Errorf("error creating tiledb array: %w", tdbCtx.LastError())
102+
}
103+
return nil
104+
}
105+
106+
// VacuumArray cleans up an array, such as consolidated fragments and array metadata.
107+
func VacuumArray(tdbCtx *Context, uri string, config *Config) error {
108+
if config == nil {
109+
return errors.New("Config must not be nil for Vacuum")
110+
}
111+
112+
curi := C.CString(uri)
113+
defer C.free(unsafe.Pointer(curi))
114+
ret := C.tiledb_array_vacuum(tdbCtx.tiledbContext.Get(), curi, config.tiledbConfig.Get())
115+
runtime.KeepAlive(tdbCtx)
116+
runtime.KeepAlive(config)
117+
if ret != C.TILEDB_OK {
118+
return fmt.Errorf("error vacuuming tiledb array: %w", tdbCtx.LastError())
119+
}
120+
121+
runtime.KeepAlive(config)
122+
return nil
123+
}
124+
72125
// NewArray allocates a new array.
73126
// If the provided Context is nil, a default context is allocated and used.
74127
func NewArray(tdbCtx *Context, uri string) (*Array, error) {
@@ -221,46 +274,12 @@ func (a *Array) Close() error {
221274
return nil
222275
}
223276

224-
// CreateArray creates a new TileDB array given a context, URI and schema.
225-
func CreateArray(tdbCtx *Context, uri string, arraySchema *ArraySchema) error {
226-
curi := C.CString(uri)
227-
defer C.free(unsafe.Pointer(curi))
228-
ret := C.tiledb_array_create(tdbCtx.tiledbContext.Get(), curi, arraySchema.tiledbArraySchema.Get())
229-
runtime.KeepAlive(tdbCtx)
230-
runtime.KeepAlive(arraySchema)
231-
if ret != C.TILEDB_OK {
232-
return fmt.Errorf("error creating tiledb array: %w", tdbCtx.LastError())
233-
}
234-
return nil
235-
}
236-
237277
// Create creates a new TileDB array given an input schema.
238278
// Deprecated: Use CreateArray instead.
239279
func (a *Array) Create(arraySchema *ArraySchema) error {
240280
return CreateArray(a.context, a.uri, arraySchema)
241281
}
242282

243-
// ConsolidateArray consolidates the fragments of an array into a single fragment.
244-
// You must first finalize all queries to the array before consolidation can
245-
// begin (as consolidation temporarily acquires an exclusive lock on the array).
246-
func ConsolidateArray(tdbCtx *Context, uri string, config *Config) error {
247-
if config == nil {
248-
return errors.New("Config must not be nil for Consolidate")
249-
}
250-
251-
curi := C.CString(uri)
252-
defer C.free(unsafe.Pointer(curi))
253-
ret := C.tiledb_array_consolidate(tdbCtx.tiledbContext.Get(), curi, config.tiledbConfig.Get())
254-
runtime.KeepAlive(tdbCtx)
255-
runtime.KeepAlive(config)
256-
if ret != C.TILEDB_OK {
257-
return fmt.Errorf("error consolidating tiledb array: %w", tdbCtx.LastError())
258-
}
259-
260-
runtime.KeepAlive(config)
261-
return nil
262-
}
263-
264283
// Consolidate consolidates the fragments of the array into a single fragment.
265284
// You must first finalize all queries to the array before consolidation can
266285
// begin (as consolidation temporarily acquires an exclusive lock on the array).
@@ -269,25 +288,6 @@ func (a *Array) Consolidate(config *Config) error {
269288
return ConsolidateArray(a.context, a.uri, config)
270289
}
271290

272-
// VacuumArray cleans up an array, such as consolidated fragments and array metadata.
273-
func VacuumArray(tdbCtx *Context, uri string, config *Config) error {
274-
if config == nil {
275-
return errors.New("Config must not be nil for Vacuum")
276-
}
277-
278-
curi := C.CString(uri)
279-
defer C.free(unsafe.Pointer(curi))
280-
ret := C.tiledb_array_vacuum(tdbCtx.tiledbContext.Get(), curi, config.tiledbConfig.Get())
281-
runtime.KeepAlive(tdbCtx)
282-
runtime.KeepAlive(config)
283-
if ret != C.TILEDB_OK {
284-
return fmt.Errorf("error vacuuming tiledb array: %w", tdbCtx.LastError())
285-
}
286-
287-
runtime.KeepAlive(config)
288-
return nil
289-
}
290-
291291
// Vacuum cleans up the array, such as consolidated fragments and array metadata.
292292
// Deprecated: Use VacuumArray instead.
293293
func (a *Array) Vacuum(config *Config) error {

group.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,31 @@ func newGroupFromHandle(context *Context, uri string, group groupHandle) *Group
3939
return &Group{group: group, uri: uri, context: context}
4040
}
4141

42-
// NewGroup allocates an embedded group.
43-
func NewGroup(tdbCtx *Context, uri string) (*Group, error) {
42+
// CreateGroup creates a new TileDB group given a context and URI.
43+
func CreateGroup(tdbCtx *Context, uri string) error {
4444
curi := C.CString(uri)
4545
defer C.free(unsafe.Pointer(curi))
46-
var groupPtr *C.tiledb_group_t
47-
ret := C.tiledb_group_alloc(tdbCtx.tiledbContext.Get(), curi, &groupPtr)
46+
47+
ret := C.tiledb_group_create(tdbCtx.tiledbContext.Get(), curi)
4848
runtime.KeepAlive(tdbCtx)
4949
if ret != C.TILEDB_OK {
50-
return nil, fmt.Errorf("error creating tiledb group: %w", tdbCtx.LastError())
50+
return fmt.Errorf("error in creating group: %w", tdbCtx.LastError())
5151
}
52-
53-
return newGroupFromHandle(tdbCtx, uri, newGroupHandle(groupPtr)), nil
52+
return nil
5453
}
5554

56-
// CreateGroup creates a new TileDB group given a context and URI.
57-
func CreateGroup(tdbCtx *Context, uri string) error {
55+
// NewGroup allocates an embedded group.
56+
func NewGroup(tdbCtx *Context, uri string) (*Group, error) {
5857
curi := C.CString(uri)
5958
defer C.free(unsafe.Pointer(curi))
60-
61-
ret := C.tiledb_group_create(tdbCtx.tiledbContext.Get(), curi)
59+
var groupPtr *C.tiledb_group_t
60+
ret := C.tiledb_group_alloc(tdbCtx.tiledbContext.Get(), curi, &groupPtr)
6261
runtime.KeepAlive(tdbCtx)
6362
if ret != C.TILEDB_OK {
64-
return fmt.Errorf("error in creating group: %w", tdbCtx.LastError())
63+
return nil, fmt.Errorf("error creating tiledb group: %w", tdbCtx.LastError())
6564
}
66-
return nil
65+
66+
return newGroupFromHandle(tdbCtx, uri, newGroupHandle(groupPtr)), nil
6767
}
6868

6969
// Create creates a new TileDB group.

0 commit comments

Comments
 (0)