From ded44ac3a928a78c8c435ddfa407e029e877ad1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Drago=C8=99=20Moldovan-Gr=C3=BCnfeld?= Date: Thu, 17 Feb 2022 09:51:55 +0000 Subject: [PATCH 1/2] add & export type method for `Expression` + unit test --- r/NAMESPACE | 1 + r/R/type.R | 3 +++ r/tests/testthat/test-type.R | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/r/NAMESPACE b/r/NAMESPACE index f91fe20ccaa..aa487cf60ac 100644 --- a/r/NAMESPACE +++ b/r/NAMESPACE @@ -96,6 +96,7 @@ S3method(tail,RecordBatchReader) S3method(tail,Scanner) S3method(tail,arrow_dplyr_query) S3method(type,ArrowDatum) +S3method(type,Expression) S3method(type,default) S3method(unique,ArrowDatum) S3method(vec_ptype_abbr,arrow_fixed_size_binary) diff --git a/r/R/type.R b/r/R/type.R index c84f1c18fbc..f8b408e4065 100644 --- a/r/R/type.R +++ b/r/R/type.R @@ -77,6 +77,9 @@ type.default <- function(x) Array__infer_type(x) #' @export type.ArrowDatum <- function(x) x$type +#' @export +type.Expression <- function(x) x$type + #----- metadata #' @title class arrow::FixedWidthType diff --git a/r/tests/testthat/test-type.R b/r/tests/testthat/test-type.R index b9613d651a9..19ce976035f 100644 --- a/r/tests/testthat/test-type.R +++ b/r/tests/testthat/test-type.R @@ -229,3 +229,13 @@ test_that("Type strings are correctly canonicalized", { "Unrecognized" ) }) + +test_that("type() gets the right type for Expression", { + x <- Expression$field_ref("x") + y <- Expression$field_ref("y") + y$schema <- Schema$create(y = float64()) + x$schema <- Schema$create(x = int32()) + + b <- Expression$create("add_checked", x, y) + expect_equal(b$type, type(b)) +}) From 24a4a39255fa5c230c85893acf2f5eb79c2181a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Drago=C8=99=20Moldovan-Gr=C3=BCnfeld?= Date: Thu, 17 Feb 2022 10:36:29 +0000 Subject: [PATCH 2/2] update unit tests --- r/tests/testthat/test-type.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/r/tests/testthat/test-type.R b/r/tests/testthat/test-type.R index 19ce976035f..168cdcff690 100644 --- a/r/tests/testthat/test-type.R +++ b/r/tests/testthat/test-type.R @@ -231,11 +231,11 @@ test_that("Type strings are correctly canonicalized", { }) test_that("type() gets the right type for Expression", { - x <- Expression$field_ref("x") - y <- Expression$field_ref("y") - y$schema <- Schema$create(y = float64()) - x$schema <- Schema$create(x = int32()) + x <- Expression$scalar(32L) + y <- Expression$scalar(10) + add_xy <- Expression$create("add", x, y) - b <- Expression$create("add_checked", x, y) - expect_equal(b$type, type(b)) + expect_equal(x$type, type(x)) + expect_equal(y$type, type(y)) + expect_equal(add_xy$type, type(add_xy)) })