@@ -153,3 +153,116 @@ if (tiledb_version(TRUE) < "2.27.0") {
153153} else {
154154 expect_silent(tiledb_array_schema_set_current_domain(dsch , cd ))
155155}
156+
157+ # # enumerations
158+ if (tiledb_version(TRUE ) > = " 2.17.0" ) {
159+
160+ dom <- tiledb_domain(c(tiledb_dim(
161+ name = " id" ,
162+ domain = c(NULL , NULL ),
163+ tile = NULL ,
164+ type = " ASCII" )))
165+
166+ attrs <- c(
167+
168+ tiledb_attr(
169+ name = " col1" ,
170+ type = " INT32" ,
171+ ncells = 1 ,
172+ nullable = FALSE ),
173+ tiledb_attr(
174+ name = " enum1" ,
175+ type = " INT32" ,
176+ ncells = 1 ,
177+ nullable = FALSE ,
178+ enumeration = TRUE
179+ ),
180+ tiledb_attr(
181+ name = " col2" ,
182+ type = " INT32" ,
183+ ncells = 1 ,
184+ nullable = FALSE
185+ ),
186+ tiledb_attr(
187+ name = " enum2" ,
188+ type = " INT32" ,
189+ ncells = 1 ,
190+ nullable = FALSE ,
191+ enumeration = TRUE
192+ ),
193+ tiledb_attr(
194+ name = " enum3" ,
195+ type = " INT32" ,
196+ ncells = 1 ,
197+ nullable = FALSE ,
198+ enumeration = TRUE
199+ )
200+ )
201+
202+ # case 1 (ordered enums)
203+ uri <- tempfile()
204+
205+ enums <- list (
206+ enum1 = c(" A" , " B" ),
207+ enum2 = c(" yes" , " no" ),
208+ enum3 = c(" aa" )
209+ )
210+
211+ sch <- tiledb_array_schema(domain = dom , attrs = attrs , sparse = TRUE , enumerations = enums )
212+ tiledb_array_create(uri , sch )
213+ arr <- tiledb_array(uri )
214+
215+ # columns with enums
216+ trg <- c(col1 = FALSE , enum1 = TRUE , col2 = FALSE , enum2 = TRUE , enum3 = TRUE )
217+
218+ expect_equal(tiledb_array_has_enumeration(arr ), trg )
219+
220+ # case 2 (unordered enums)
221+ uri <- tempfile()
222+
223+ enums <- list (
224+ enum2 = c(" yes" , " no" ),
225+ enum1 = c(" A" , " B" ),
226+ enum3 = c(" aa" )
227+ )
228+
229+ sch <- tiledb_array_schema(domain = dom , attrs = attrs , sparse = TRUE , enumerations = enums )
230+ tiledb_array_create(uri , sch )
231+ arr <- tiledb_array(uri )
232+
233+ expect_equal(tiledb_array_has_enumeration(arr ), trg )
234+
235+ # case 3 (unordered map all attributes)
236+ uri <- tempfile()
237+
238+ enums <- list (
239+ enum1 = c(" A" , " B" ),
240+ col1 = NULL ,
241+ enum2 = c(" yes" , " no" ),
242+ enum3 = c(" aa" ),
243+ col2 = NULL
244+ )
245+
246+
247+ sch <- tiledb_array_schema(domain = dom , attrs = attrs , sparse = TRUE , enumerations = enums )
248+ tiledb_array_create(uri , sch )
249+ arr <- tiledb_array(uri )
250+
251+ expect_equal(tiledb_array_has_enumeration(arr ), trg )
252+
253+ # case 4 (unknown mapping name)
254+ uri <- tempfile()
255+
256+ enums <- list (
257+ name = c(" A" , " B" ),
258+ col1 = NULL ,
259+ enum2 = c(" yes" , " no" ),
260+ enum3 = c(" aa" ),
261+ col2 = NULL
262+ )
263+
264+ # enums contains a named element that is not found in attributes
265+ expect_error(tiledb_array_schema(domain = dom , attrs = attrs , sparse = TRUE , enumerations = enums ))
266+
267+ unlink(uri )
268+ }
0 commit comments