From 5e81f12caca98d077c84f148093d9e758ef74f51 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Wed, 2 Oct 2024 13:45:41 -0400 Subject: [PATCH] unit-testing --- apis/r/R/SOMADataFrame.R | 3 -- apis/r/R/utils-arrow.R | 2 - apis/r/src/rutilities.cpp | 24 ++++++++++ apis/r/tests/testthat/test-SOMADataFrame.R | 51 +--------------------- 4 files changed, 26 insertions(+), 54 deletions(-) diff --git a/apis/r/R/SOMADataFrame.R b/apis/r/R/SOMADataFrame.R index b70ed0e9e9..0a8c669c99 100644 --- a/apis/r/R/SOMADataFrame.R +++ b/apis/r/R/SOMADataFrame.R @@ -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) @@ -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] diff --git a/apis/r/R/utils-arrow.R b/apis/r/R/utils-arrow.R index 7dd764f784..a7d3d4df3e 100644 --- a/apis/r/R/utils-arrow.R +++ b/apis/r/R/utils-arrow.R @@ -313,8 +313,6 @@ check_arrow_schema_data_types <- function(from, to) { } } - ### debug 3079:03 - if (length(msgs) > 0L) { stop( "Schemas are incompatible:\n", diff --git a/apis/r/src/rutilities.cpp b/apis/r/src/rutilities.cpp index 913d00b6a7..78b848923b 100644 --- a/apis/r/src/rutilities.cpp +++ b/apis/r/src/rutilities.cpp @@ -501,3 +501,27 @@ SEXP convert_domainish(const tdbs::ArrowTable& arrow_table) { return arrayxp; } + +static std::map _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; + } +} diff --git a/apis/r/tests/testthat/test-SOMADataFrame.R b/apis/r/tests/testthat/test-SOMADataFrame.R index c4b248b4ff..c5974878e9 100644 --- a/apis/r/tests/testthat/test-SOMADataFrame.R +++ b/apis/r/tests/testthat/test-SOMADataFrame.R @@ -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 - # $soma_joinid - # $string_column - # $float_column - # $frobo > - # ^^^^^^ - - ### 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 - # ^^^^^^ + expect_no_condition(sdf <- SOMADataFrameOpen(uri, mode = "WRITE")$update(tbl0)) # Verify enum was added on disk expect_s3_class( @@ -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 - # $soma_joinid - # $string_column - # $float_column - # $frobo > - # ^^^^^^ - - # Browse[2]> SOMADataFrameOpen(uri)$schema() - # Schema - # int_column: int32 not null - # soma_joinid: int64 - # string_column: large_string - # float_column: bool - # frobo: dictionary - # ^^^^^^ - - # 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(