Skip to content

[<- on sparse arrays fails with zero-row data frames #879

Description

@LTLA
library(tiledb)

tmp <- tempfile()
dom <- tiledb_domain(dims = list(
    tiledb_dim("d1", c(1L, 10L), 10L, type = "INT32"),
    tiledb_dim("d2", c(1L, 20L), 20L, type = "INT32")
))
schema <- tiledb_array_schema(
    dom,
    attrs = list(tiledb_attr("x", type = "FLOAT64")),
    sparse = TRUE
)
tiledb_array_create(tmp, schema)

arr <- tiledb_array(tmp, query_type = "WRITE")

arr[] <- data.frame(d1 = 1L, d2 = 2L, x = 3) # OK

arr[] <- data.frame(d1 = integer(0), d2 = integer(0), x = numeric(0)) # FAIL
## Error: [TileDB::Query] Error: Fix-Sized input attribute/dimension 'd2' is not set correctly. 
## Data buffer is not set.

tiledb_array_close(arr)

For more context: we're breaking up an array into blocks that are processed and written to file by [<- (see LTLA/TileDBArray#33). Some of those blocks will be empty (no non-zero elements), resulting in the above error. Currently, we just work around it by checking for at least one non-zero element before attempting to call [<-. However, I think an empty data frame is a perfectly reasonable input; [<- should handle this case more gracefully and just no-op if the supplied value is empty.

Session information
R Under development (unstable) (2026-02-19 r89439)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.5 LTS

Matrix products: default
BLAS:   /home/luna/Software/R/trunk/lib/libRblas.so 
LAPACK: /home/luna/Software/R/trunk/lib/libRlapack.so;  LAPACK version 3.12.1

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Australia/Sydney
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RcppSpdlog_0.0.28 tiledb_0.33.0    

loaded via a namespace (and not attached):
 [1] zoo_1.8-15      bit_4.6.0       compiler_4.6.0  tools_4.6.0    
 [5] RcppCCTZ_0.2.14 spdl_0.0.5      Rcpp_1.1.1      nanoarrow_0.8.0
 [9] bit64_4.6.0-1   nanotime_0.3.13 grid_4.6.0      lattice_0.22-9 

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