Skip to content

Commit

Permalink
unit-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Oct 2, 2024
1 parent 5bbd2c6 commit 5e81f12
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 54 deletions.
3 changes: 0 additions & 3 deletions apis/r/R/SOMADataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ SOMADataFrame <- R6::R6Class(
write = function(values) {
private$check_open_for_write()

### 3079:04

# Prevent downcasting of int64 to int32 when materializing a column
op <- options(arrow.int64_downcast = FALSE)
on.exit(options(op), add = TRUE, after = FALSE)
Expand Down Expand Up @@ -296,7 +294,6 @@ SOMADataFrame <- R6::R6Class(
tiledb_create_options <- TileDBCreateOptions$new(self$platform_config)

# Check compatibility of new/old data types in common columns
### debug 3079:02
check_arrow_schema_data_types(
old_schema[common_cols],
new_schema[common_cols]
Expand Down
2 changes: 0 additions & 2 deletions apis/r/R/utils-arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ check_arrow_schema_data_types <- function(from, to) {
}
}

### debug 3079:03

if (length(msgs) > 0L) {
stop(
"Schemas are incompatible:\n",
Expand Down
24 changes: 24 additions & 0 deletions apis/r/src/rutilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,27 @@ SEXP convert_domainish(const tdbs::ArrowTable& arrow_table) {

return arrayxp;
}

static std::map<std::string, std::string> _type_name_remap = {
{"int8", "c"},
{"int16", "s"},
{"int32", "i"},
{"int64", "l"},
{"uint8", "C"},
{"uint16", "S"},
{"uint32", "I"},
{"uint64", "L"},
{"utf8", "u"},
{"large_utf8", "U"},
{"bool", "b"},
{"float", "f"},
{"double", "g"}};

std::string remap_arrow_type_code_r_to_c(std::string input) {
auto it = _type_name_remap.find(input);
if (it == _type_name_remap.end()) {
return input;
} else {
return it->second;
}
}
51 changes: 2 additions & 49 deletions apis/r/tests/testthat/test-SOMADataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -639,30 +639,7 @@ test_that("SOMADataFrame can be updated", {

# Add a new enum and update
tbl0$frobo <- factor(sample(letters[1:3], nrow(tbl0), replace = TRUE))

# Browse[2]> tbl0
# Table
# 10 rows x 5 columns
# $int_column <int32 not null>
# $soma_joinid <int64>
# $string_column <large_string>
# $float_column <bool>
# $frobo <dictionary<values=string, indices=int8>>
# ^^^^^^

### debug 3079
### expect_no_condition(sdf <- SOMADataFrameOpen(uri, mode = "WRITE")$update(tbl0))
sdf <- SOMADataFrameOpen(uri, mode = "WRITE")
sdf <- sdf$update(tbl0)

# Browse[2]> SOMADataFrameOpen(uri)$schema()
# Schema
# int_column: int32 not null
# soma_joinid: int64
# string_column: large_string
# float_column: bool
# frobo: dictionary<values=binary, indices=int8>
# ^^^^^^
expect_no_condition(sdf <- SOMADataFrameOpen(uri, mode = "WRITE")$update(tbl0))

# Verify enum was added on disk
expect_s3_class(
Expand All @@ -686,31 +663,7 @@ test_that("SOMADataFrame can be updated", {
levels(tbl0$GetColumnByName("rlvl")$as_vector()),
c("green", "red", "blue")
)
### debug 3079:01
### expect_no_condition(sdf <- SOMADataFrameOpen(uri, mode = "WRITE")$update(tbl0))

# Browse[2]> tbl0
# Table
# 10 rows x 6 columns
# $int_column <int32 not null>
# $soma_joinid <int64>
# $string_column <large_string>
# $float_column <bool>
# $frobo <dictionary<values=string, indices=int8>>
# ^^^^^^

# Browse[2]> SOMADataFrameOpen(uri)$schema()
# Schema
# int_column: int32 not null
# soma_joinid: int64
# string_column: large_string
# float_column: bool
# frobo: dictionary<values=binary, indices=int8>
# ^^^^^^

# The written-to sdf has binary values

sdf <- SOMADataFrameOpen(uri, mode = "WRITE")$update(tbl0)
expect_no_condition(sdf <- SOMADataFrameOpen(uri, mode = "WRITE")$update(tbl0))

# Verify unordered enum was added on disk
expect_s3_class(
Expand Down

0 comments on commit 5e81f12

Please sign in to comment.