TileDB-R icon indicating copy to clipboard operation
TileDB-R copied to clipboard

Reading an array with evolved nullable attribute with dupes `segfaults`

Open cgiachalis opened this issue 6 months ago • 1 comments

While reading an array that has been evolved with a new nullable (NAs) attribute, it will segfault when duplicate values are allowed.

library(tiledb) # 0.32.0.5

# helper
evolved_df <- function(allows_dups = TRUE, nullable = FALSE, write_data = TRUE) {

  # create a sample array and populate
  uri <- tempfile()
  df <- data.frame(key = letters[1:3], val = 1:3)
  arr <- fromDataFrame(df, uri, col_index = 1, sparse = TRUE, allows_dups = allows_dups)

  # evolve schema 
  ase <- tiledb_array_schema_evolution()
  attr <- tiledb_attr("foo", "INT32", nullable = nullable)
  ase <- tiledb_array_schema_evolution_add_attribute(ase, attr)
  ase <- tiledb_array_schema_evolution_array_evolve(ase, uri)

  arr <- tiledb_array(uri, return_as = "data.frame")

  # write data on the new attribute
  if (write_data) {
    arr[] <- cbind(df, foo = sample.int(3))
  }

  arr
}

# case 1: No nullables, allow dupes, populate evolved attribute 
arr1 <- evolved_df()
arr1[] # OK
#>   key val foo
#> 1   a   1  NA
#> 2   b   2  NA
#> 3   c   3  NA
#> 4   a   1   1
#> 5   b   2   3
#> 6   c   3   2

# case 2: No nullables, no dupes, populate evolved attribute 
arr2 <- evolved_df(allows_dups = FALSE, write_data = TRUE) 
arr2[] # OK 
#>   key val foo
#> 1   a   1   2
#> 2   b   2   3
#> 3   c   3   1

# case 3: No nullables, without populating evolved attribute 
arr3 <- evolved_df(allows_dups = FALSE, write_data = FALSE) 
arr3[] # OK 
#>   key val foo
#> 1   a   1  NA
#> 2   b   2  NA
#> 3   c   3  NA

# case 4: Nullables, without populating evolved attribute 
arr4 <- evolved_df(nullable = TRUE, allows_dups = FALSE, write_data = FALSE) 
arr4[] # OK 
#>   key val foo
#> 1   a   1  NA
#> 2   b   2  NA
#> 3   c   3  NA

# case 5: Nullables, no dupes, populate evolved attribute 
arr5 <- evolved_df(nullable = TRUE, allows_dups = FALSE, write_data = TRUE)
arr5[] # OK 
#>   key val foo
#> 1   a   1   2
#> 2   b   2   1
#> 3   c   3   3

# case 6: Nullables, allow dupes, populate evolved attribute 
arr6 <- evolved_df(nullable = TRUE, allows_dups = TRUE, write_data = TRUE)
arr6[] # segfaults

cgiachalis avatar Jun 13 '25 09:06 cgiachalis