diff --git a/ci/scripts/r_test_old_version.sh b/ci/scripts/r_test_old_version.sh new file mode 100755 index 00000000000..712b996c072 --- /dev/null +++ b/ci/scripts/r_test_old_version.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +set -ex + +: ${R_BIN:=R} + +source_dir=${1}/r + +pushd ${source_dir} + +printenv + +export TEST_R_WITH_ARROW=TRUE + +${R_BIN} -e "as_cran <- !identical(tolower(Sys.getenv('NOT_CRAN')), 'true') + remotes::install_version('arrow', '$OLD_ARROW_VERSION', quiet = FALSE, verbose = TRUE) + library(arrow) + testthat::test_file('tests/testthat/test-parquet-compatibility.R')" + +popd diff --git a/dev/tasks/r/azure.linux.yml b/dev/tasks/r/azure.linux.yml index 7ffe8c581cc..e715191fae7 100644 --- a/dev/tasks/r/azure.linux.yml +++ b/dev/tasks/r/azure.linux.yml @@ -37,6 +37,7 @@ jobs: export R_IMAGE={{ r_image }} export R_TAG={{ r_tag }} export DEVTOOLSET_VERSION={{ devtoolset_version|default("-1") }} + export OLD_ARROW_VERSION={{ old_arrow_version }} docker-compose pull --ignore-pull-failures r docker-compose build r displayName: Docker build diff --git a/dev/tasks/tasks.yml b/dev/tasks/tasks.yml index f2b6094edd7..30b8db938ff 100644 --- a/dev/tasks/tasks.yml +++ b/dev/tasks/tasks.yml @@ -1770,6 +1770,16 @@ tasks: not_cran: "TRUE" devtoolset_version: 8 + test-r-rstudio-r-arrow-1.0.1-compatibility: + ci: azure + template: r/azure.linux.yml + params: + r_org: rstudio + r_image: r-base + r_tag: 3.6-bionic + old_arrow_version: "1.0.1" + run: r-forward-compatibility + test-r-rstudio-r-base-3.6-opensuse15: ci: azure template: r/azure.linux.yml diff --git a/docker-compose.yml b/docker-compose.yml index 381fbad8cd5..dc4c2aa16a4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -854,6 +854,31 @@ services: command: > /bin/bash -c "/arrow/ci/scripts/r_test.sh /arrow" + r-forward-compatibility: + # This lets you test forward compatilbity from old arrow versions (given in OLD_ARROW_VERSION) + # + # Usage: + # R_ORG=rstudio R_IMAGE=r-base R_TAG=3.6-bionic OLD_ARROW_VERSION=1.0.1 docker-compose build r-forward-compatibility + # R_ORG=rstudio R_IMAGE=r-base R_TAG=3.6-bionic OLD_ARROW_VERSION=1.0.1 docker-compose run r-forward-compatibility + image: ${REPO}:r-${R_ORG}-${R_IMAGE}-${R_TAG} + build: + context: . + dockerfile: ci/docker/linux-r.dockerfile + cache_from: + - ${REPO}:r-${R_ORG}-${R_IMAGE}-${R_TAG} + args: + base: ${R_ORG}/${R_IMAGE}:${R_TAG} + r_dev: ${ARROW_R_DEV} + shm_size: *shm-size + environment: + ARROW_R_DEV: ${ARROW_R_DEV} + ARROW_USE_PKG_CONFIG: "false" + OLD_ARROW_VERSION: ${OLD_ARROW_VERSION} + volumes: + - .:/arrow:delegated + command: > + /bin/bash -c "/arrow/ci/scripts/r_test_old_version.sh /arrow" + ubuntu-r-sanitizer: # Only 18.04 and amd64 supported # Usage: diff --git a/r/tests/testthat/parquets/data-arrow2.parquet b/r/tests/testthat/parquets/data-arrow2.parquet new file mode 100644 index 00000000000..002a44fd697 Binary files /dev/null and b/r/tests/testthat/parquets/data-arrow2.parquet differ diff --git a/r/tests/testthat/test-parquet-compatibility.R b/r/tests/testthat/test-parquet-compatibility.R new file mode 100644 index 00000000000..e715acc0602 --- /dev/null +++ b/r/tests/testthat/test-parquet-compatibility.R @@ -0,0 +1,45 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# TODO: skip mostly? Or use this for backwards compat? + +pq_file <- test_path("parquets/data-arrow2.parquet") + +test_that("reading a known Parquet file to dataframe", { + df <- read_parquet(pq_file) + expect_data_frame(df, data.frame(col1 = 1:10)) + expect_identical(dim(df), c(10L, 1L)) + + tab <- read_parquet(pq_file, as_data_frame = FALSE) + expect_s3_class(tab, "Table") + expect_equal( + # unserialize like .unserialize_arrow_r_metadata does (though we can't call + # it directly because it's not exported) + unserialize(charToRaw(tab$metadata$r)), + list( + attributes = list(class = "data.frame"), + columns = list(col1 = NULL) + ) + ) + + # test the workaround + tab$metadata$r <- NULL + df <- as.data.frame(tab) + + expect_data_frame(df, data.frame(col1 = 1:10)) + expect_identical(dim(df), c(10L, 1L)) +})