Skip to content

schema() 's show (print) method raises error #873

Description

@cgiachalis

The print method of tiledb_array_schema object raises an error when passing a tiledb_array object on write mode.

reprex:

library(tiledb)

uri <- tempfile()
df <- data.frame(id = 1:2, val= c(10, 20))
fromDataFrame(df, uri, col_index  = 1)

arr <- tiledb_array(uri, query_type = "WRITE", keep_open = TRUE)

# verify is opened in write mode
tiledb_array_is_open_for_writing(arr)
#> [1] TRUE

# so far OK
sch <- schema(arr)
attr <- attrs(sch) # just a check


# but printing...
schema(arr)
#> Error:
#> ! [TileDB::Array] Error: Cannot open array; Array already open.


# Now reopen to READ mode
arr <- tiledb_array_close(arr)

arr <- tiledb_array_open(arr, type = "READ")

# Good
schema(arr)
#> tiledb_array_schema(
#>     domain=tiledb_domain(c(
#>         tiledb_dim(name="id", domain=c(1L,2L), tile=2L, type="INT32", filter_list=tiledb_filter_list(c(tiledb_filter_set_option(tiledb_filter("ZSTD"),"COMPRESSION_LEVEL",-1))))
#>     )),
#>     attrs=c(
#>         tiledb_attr(name="val", type="FLOAT64", ncells=1, nullable=FALSE, filter_list=tiledb_filter_list(c(tiledb_filter_set_option(tiledb_filter("ZSTD"),"COMPRESSION_LEVEL",-1))))
#>     ),
#>     cell_order="COL_MAJOR", tile_order="COL_MAJOR", capacity=10000, sparse=TRUE, allows_dups=TRUE,
#>     coords_filter_list=tiledb_filter_list(c(tiledb_filter_set_option(tiledb_filter("ZSTD"),"COMPRESSION_LEVEL",-1))),
#>     offsets_filter_list=tiledb_filter_list(c(tiledb_filter_set_option(tiledb_filter("ZSTD"),"COMPRESSION_LEVEL",-1))),
#>     validity_filter_list=tiledb_filter_list(c(tiledb_filter_set_option(tiledb_filter("RLE"),"COMPRESSION_LEVEL",-1)))
#> )

Root cause

The issue is in the internal text helper .as_text_attribute that checks if the array pointer is open in READ mode and not just opened:

if (!libtiledb_array_is_open_for_reading(arrptr)) arrptr <- libtiledb_array_open_with_ptr(arrptr, "READ")

A bit of background on schema show method: if you pass a tiledb_array object, it uses the array pointer to query about enums and construct the schema for printing. In case you pass a uri, the print function will not show any enums (incomplete schema).

Also, .as_text_attribute will print "dictionary"/"ordered_dictionary" which is not the case as the correct argument in tiledb_attr is enumerations. Run the example in #854 and print the schema using the array..

dictionary_txt <- if (ord) "ordered_dictionary" else "dictionary"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions