Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions r/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Collate:
'record-batch-writer.R'
'reexports-bit64.R'
'reexports-tidyselect.R'
'scalar.R'
'schema.R'
'struct.R'
'util.R'
4 changes: 4 additions & 0 deletions r/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ S3method(as.list,Table)
S3method(as.raw,Buffer)
S3method(as.vector,Array)
S3method(as.vector,ChunkedArray)
S3method(as.vector,Scalar)
S3method(as.vector,array_expression)
S3method(c,Dataset)
S3method(dim,Dataset)
Expand All @@ -37,9 +38,11 @@ S3method(head,Table)
S3method(is.na,Array)
S3method(is.na,ChunkedArray)
S3method(is.na,Expression)
S3method(is.na,Scalar)
S3method(is.na,array_expression)
S3method(length,Array)
S3method(length,ChunkedArray)
S3method(length,Scalar)
S3method(length,Schema)
S3method(names,Dataset)
S3method(names,RecordBatch)
Expand Down Expand Up @@ -120,6 +123,7 @@ export(RecordBatchFileWriter)
export(RecordBatchStreamReader)
export(RecordBatchStreamWriter)
export(S3FileSystem)
export(Scalar)
export(Scanner)
export(ScannerBuilder)
export(Schema)
Expand Down
6 changes: 4 additions & 2 deletions r/R/array.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,19 @@ Array <- R6Class("Array",
i <- Array$create(i)
}
if (inherits(i, "ChunkedArray")) {
# Invalid: Kernel does not support chunked array arguments
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wesm I didn't see a JIRA for this but admittedly there are a lot attached to the umbrella ticket so I may have missed it. Is there one for supporting Take with ChunkedArrays (as either the first and/or second argument)? Likewise for Take/Filter on RecordBatch and Table.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# so use the old method
return(shared_ptr(ChunkedArray, Array__TakeChunked(self, i)))
}
assert_is(i, "Array")
Array$create(Array__Take(self, i))
Array$create(call_function("take", self, i))
},
Filter = function(i, keep_na = TRUE) {
if (is.logical(i)) {
i <- Array$create(i)
}
assert_is(i, "Array")
Array$create(Array__Filter(self, i, keep_na))
Array$create(call_function("filter", self, i, options = list(keep_na = keep_na)))
},
RangeEquals = function(other, start_idx, end_idx, other_start_idx = 0L) {
assert_is(other, "Array")
Expand Down
36 changes: 28 additions & 8 deletions r/R/arrowExports.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions r/R/chunked-array.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ ChunkedArray <- R6Class("ChunkedArray", inherit = ArrowObject,
if (is.integer(i)) {
i <- Array$create(i)
}
# Invalid: Kernel does not support chunked array arguments
# so use the old method for both cases
if (inherits(i, "ChunkedArray")) {
return(shared_ptr(ChunkedArray, ChunkedArray__TakeChunked(self, i)))
}
Expand Down
5 changes: 5 additions & 0 deletions r/R/compute.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

#' @include array.R

call_function <- function(function_name, ..., options = list()) {
assert_that(is.string(function_name))
compute__CallFunction(function_name, list(...), options)
}

CastOptions <- R6Class("CastOptions", inherit = ArrowObject)

#' Cast options
Expand Down
3 changes: 1 addition & 2 deletions r/R/expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ Expression$field_ref <- function(name) {
shared_ptr(Expression, dataset___expr__field_ref(name))
}
Expression$scalar <- function(x) {
stopifnot(vec_size(x) == 1L || is.null(x))
shared_ptr(Expression, dataset___expr__scalar(x))
shared_ptr(Expression, dataset___expr__scalar(Scalar$create(x)))
}
Expression$compare <- function(OP, e1, e2) {
comp_func <- comparison_function_map[[OP]]
Expand Down
2 changes: 2 additions & 0 deletions r/R/record-batch.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ RecordBatch <- R6Class("RecordBatch", inherit = ArrowObject,
i <- Array$create(i)
}
assert_is(i, "Array")
# Invalid: Tried executing function with non-value type: RecordBatch
# so use old methods
shared_ptr(RecordBatch, RecordBatch__Take(self, i))
},
Filter = function(i, keep_na = TRUE) {
Expand Down
64 changes: 64 additions & 0 deletions r/R/scalar.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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.

#' @include arrow-package.R

#' @title Arrow scalars
#' @usage NULL
#' @format NULL
#' @docType class
#'
#' @description A `Scalar` holds a single value of an Arrow type.
#'
#' @name Scalar
#' @rdname Scalar
#' @export
Scalar <- R6Class("Scalar", inherit = ArrowObject,
# TODO: document the methods
public = list(
ToString = function() Scalar__ToString(self),
cast = function(target_type) {
Scalar$create(Scalar__CastTo(self, as_type(target_type)))
},
as_vector = function() Scalar__as_vector(self)
),
active = list(
is_valid = function() Scalar__is_valid(self),
type = function() DataType$create(Scalar__type(self))
)
)
Scalar$create <- function(x, type = NULL) {
if (!inherits(x, "externalptr")) {
if (is.null(x)) {
x <- vctrs::unspecified(1)
} else if (length(x) != 1 && !is.data.frame(x)) {
# Wrap in a list type
x <- list(x)
}
x <- Array__GetScalar(Array$create(x, type = type), 0)
}
shared_ptr(Scalar, x)
}

#' @export
length.Scalar <- function(x) 1L

#' @export
is.na.Scalar <- function(x) !x$is_valid

#' @export
as.vector.Scalar <- function(x, mode) x$as_vector()
9 changes: 9 additions & 0 deletions r/man/Scalar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading