This is an automated email from the ASF dual-hosted git repository.
wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 6067992 ARROW-3562: [R] Disallow creation of objects with
shared_ptr<T>(nullptr), use bits64::integer64
6067992 is described below
commit 606799215cae84c029e803645bca8c6a59cb5ef2
Author: Romain Francois <[email protected]>
AuthorDate: Sat Oct 20 09:51:09 2018 -0400
ARROW-3562: [R] Disallow creation of objects with shared_ptr<T>(nullptr),
use bits64::integer64
Follow up to #2749 with the following fixes:
- shared_ptr of `nullptr` don't construct R6 objects
- int64 uses `bit64::integer64`, based on
https://github.com/r-lib/vctrs/pull/121
Author: Romain Francois <[email protected]>
Closes #2795 from romainfrancois/ARROW-3553/int64 and squashes the
following commits:
49c34bb6d <Romain Francois> using lower case cpp files
cf359941a <Romain Francois> lint
018092ac9 <Romain Francois> bounds check on
RecordBatchFileReader$ReadRecordBatch
3200352da <Romain Francois> - test
089f951b9 <Romain Francois> additional check
72ccdcba9 <Romain Francois> replace direct class$new(.) by construct(class,
.)
5b10dd17a <Romain Francois> R -> bit64::integer64
3e6bc9ae8 <Romain Francois> using integer64 class for arrow (int64) -> R
conversion.
---
r/DESCRIPTION | 7 +-
r/R/ChunkedArray.R | 10 +--
r/R/Column.R | 2 +-
r/R/Field.R | 2 +-
r/R/List.R | 2 +-
r/R/R6.R | 66 ++++++++-------
r/R/RcppExports.R | 8 +-
r/R/RecordBatch.R | 12 +--
r/R/RecordBatchReader.R | 16 ++--
r/R/RecordBatchWriter.R | 4 +-
r/R/Schema.R | 2 +-
r/R/Struct.R | 2 +-
r/R/Table.R | 6 +-
r/R/array.R | 10 +--
r/R/buffer.R | 6 +-
r/R/dictionary.R | 4 +-
r/R/io.R | 20 ++---
r/R/memory_pool.R | 2 +-
r/src/RcppExports.cpp | 24 +++---
r/src/array.cpp | 95 ++++++++++++++++++++--
r/src/{ArrayData.cpp => arraydata.cpp} | 0
r/src/{ChunkedArray.cpp => chunkedarray.cpp} | 0
r/src/{Column.cpp => column.cpp} | 0
r/src/{DataType.cpp => datatype.cpp} | 8 +-
r/src/{MemoryPool.cpp => memorypool.cpp} | 0
r/src/{RecordBatch.cpp => recordbatch.cpp} | 0
...RecordBatchReader.cpp => recordbatchreader.cpp} | 4 +-
...RecordBatchWriter.cpp => recordbatchwriter.cpp} | 0
r/src/{Table.cpp => table.cpp} | 0
r/tests/testthat/test-Array.R | 14 ++++
r/tests/testthat/test-RecordBatch.R | 4 +-
31 files changed, 215 insertions(+), 115 deletions(-)
diff --git a/r/DESCRIPTION b/r/DESCRIPTION
index 66fc42a..1ab47cc 100644
--- a/r/DESCRIPTION
+++ b/r/DESCRIPTION
@@ -27,14 +27,15 @@ Imports:
crayon,
withr
Remotes:
- r-lib/vctrs,
+ romainfrancois/vctrs@bit64,
RcppCore/Rcpp,
- romainfrancois/withr@bug-79/defer
+ r-lib/withr
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.0.9000
Suggests:
testthat,
- lubridate
+ lubridate,
+ bit64
Collate:
'enums.R'
'R6.R'
diff --git a/r/R/ChunkedArray.R b/r/R/ChunkedArray.R
index a93e7f8..56bf198 100644
--- a/r/R/ChunkedArray.R
+++ b/r/R/ChunkedArray.R
@@ -22,15 +22,15 @@
length = function() ChunkedArray__length(self),
null_count = function() ChunkedArray__null_count(self),
num_chunks = function() ChunkedArray__num_chunks(self),
- chunk = function(i) `arrow::Array`$new(ChunkedArray__chunk(self, i)),
- chunks = function() purrr::map(ChunkedArray__chunks(self),
`arrow::Array`$new),
+ chunk = function(i) construct(`arrow::Array`, ChunkedArray__chunk(self,
i)),
+ chunks = function() purrr::map(ChunkedArray__chunks(self), construct,
class = `arrow::Array`),
type = function() `arrow::DataType`$dispatch(ChunkedArray__type(self)),
as_vector = function() ChunkedArray__as_vector(self),
Slice = function(offset, length = NULL){
if (is.null(length)) {
- `arrow::ChunkedArray`$new(ChunkArray__Slice1(self, offset))
+ construct(`arrow::ChunkedArray`, ChunkArray__Slice1(self, offset))
} else {
- `arrow::ChunkedArray`$new(ChunkArray__Slice2(self, offset, length))
+ construct(`arrow::ChunkedArray`, ChunkArray__Slice2(self, offset,
length))
}
}
)
@@ -42,5 +42,5 @@
#'
#' @export
chunked_array <- function(...){
- `arrow::ChunkedArray`$new(ChunkedArray__from_list(rlang::list2(...)))
+ construct(`arrow::ChunkedArray`, ChunkedArray__from_list(rlang::list2(...)))
}
diff --git a/r/R/Column.R b/r/R/Column.R
index bab6f17..86edade 100644
--- a/r/R/Column.R
+++ b/r/R/Column.R
@@ -22,6 +22,6 @@
length = function() Column__length(self),
null_count = function() Column__null_count(self),
type = function() `arrow::DataType`$dispatch(Column__type(self)),
- data = function() `arrow::ChunkedArray`$new(Column__data(self))
+ data = function() construct(`arrow::ChunkedArray`, Column__data(self))
)
)
diff --git a/r/R/Field.R b/r/R/Field.R
index e01eb1a..e2f01b1 100644
--- a/r/R/Field.R
+++ b/r/R/Field.R
@@ -41,7 +41,7 @@
}
field <- function(name, type) {
- `arrow::Field`$new(Field__initialize(name, type))
+ construct(`arrow::Field`, Field__initialize(name, type))
}
.fields <- function(.list){
diff --git a/r/R/List.R b/r/R/List.R
index 5360401..68bcd0f 100644
--- a/r/R/List.R
+++ b/r/R/List.R
@@ -23,4 +23,4 @@
#' @rdname DataType
#' @export
-list_of <- function(type) `arrow::ListType`$new(list__(type))
+list_of <- function(type) construct(`arrow::ListType`, list__(type))
diff --git a/r/R/R6.R b/r/R/R6.R
index 752ad59..5687daa 100644
--- a/r/R/R6.R
+++ b/r/R/R6.R
@@ -40,14 +40,14 @@
},
pointer_address = function(){
Object__pointer_address(self$pointer())
- },
-
- is_null = function(){
- Object__is_null(self)
}
)
)
+construct <- function(class, xp) {
+ if (!xptr_is_null(xp)) class$new(xp)
+}
+
#' @export
`!=.arrow::Object` <- function(lhs, rhs){
!(lhs == rhs)
@@ -70,7 +70,7 @@
DataType__num_children(self)
},
children = function() {
- map(DataType__children_pointer(self), ~`arrow::Field`$new(xp=.x))
+ map(DataType__children_pointer(self), construct, class= `arrow::Field`)
},
id = function(){
DataType__id(self)
@@ -94,13 +94,13 @@
BINARY = stop("Type BINARY not implemented yet"),
DATE32 = date32(),
DATE64 = date64(),
- TIMESTAMP = `arrow::Timestamp`$new(self$pointer()),
+ TIMESTAMP = construct(`arrow::Timestamp`,self$pointer()),
INTERVAL = stop("Type INTERVAL not implemented yet"),
- DECIMAL = `arrow::Decimal128Type`$new(self$pointer()),
- LIST = `arrow::ListType`$new(self$pointer()),
- STRUCT = `arrow::StructType`$new(self$pointer()),
+ DECIMAL = construct(`arrow::Decimal128Type`, self$pointer()),
+ LIST = construct(`arrow::ListType`, self$pointer()),
+ STRUCT = construct(`arrow::StructType`, self$pointer()),
UNION = stop("Type UNION not implemented yet"),
- DICTIONARY = `arrow::DictionaryType`$new(self$pointer()),
+ DICTIONARY = construct(`arrow::DictionaryType`, self$pointer()),
MAP = stop("Type MAP not implemented yet")
)
}
@@ -108,7 +108,7 @@
)
`arrow::DataType`$dispatch <- function(xp){
- `arrow::DataType`$new(xp)$..dispatch()
+ construct(`arrow::DataType`, xp)$..dispatch()
}
#----- metadata
@@ -241,90 +241,88 @@
#'
#' @rdname DataType
#' @export
-int8 <- function() `arrow::Int8`$new(Int8__initialize())
+int8 <- function() construct(`arrow::Int8`, Int8__initialize())
#' @rdname DataType
#' @export
-int16 <- function() `arrow::Int16`$new(Int16__initialize())
+int16 <- function() construct(`arrow::Int16`, Int16__initialize())
#' @rdname DataType
#' @export
-int32 <- function() `arrow::Int32`$new(Int32__initialize())
+int32 <- function() construct(`arrow::Int32`, Int32__initialize())
#' @rdname DataType
#' @export
-int64 <- function() `arrow::Int64`$new(Int64__initialize())
+int64 <- function() construct(`arrow::Int64`, Int64__initialize())
#' @rdname DataType
#' @export
-uint8 <- function() `arrow::UInt8`$new(UInt8__initialize())
+uint8 <- function() construct(`arrow::UInt8`, UInt8__initialize())
#' @rdname DataType
#' @export
-uint16 <- function() `arrow::UInt16`$new(UInt16__initialize())
+uint16 <- function() construct(`arrow::UInt16`, UInt16__initialize())
#' @rdname DataType
#' @export
-uint32 <- function() `arrow::UInt32`$new(UInt32__initialize())
+uint32 <- function() construct(`arrow::UInt32`, UInt32__initialize())
#' @rdname DataType
#' @export
-uint64 <- function() `arrow::UInt64`$new(UInt64__initialize())
+uint64 <- function() construct(`arrow::UInt64`, UInt64__initialize())
#' @rdname DataType
#' @export
-float16 <- function() `arrow::Float16`$new(Float16__initialize())
+float16 <- function() construct(`arrow::Float16`, Float16__initialize())
#' @rdname DataType
#' @export
-float32 <- function() `arrow::Float32`$new(Float32__initialize())
+float32 <- function() construct(`arrow::Float32`, Float32__initialize())
#' @rdname DataType
#' @export
-float64 <- function() `arrow::Float64`$new(Float64__initialize())
+float64 <- function() construct(`arrow::Float64`, Float64__initialize())
#' @rdname DataType
#' @export
-boolean <- function() `arrow::Boolean`$new(Boolean__initialize())
+boolean <- function() construct(`arrow::Boolean`, Boolean__initialize())
#' @rdname DataType
#' @export
-utf8 <- function() `arrow::Utf8`$new(Utf8__initialize())
+utf8 <- function() construct(`arrow::Utf8`, Utf8__initialize())
#' @rdname DataType
#' @export
-date32 <- function() `arrow::Date32`$new(Date32__initialize())
+date32 <- function() construct(`arrow::Date32`, Date32__initialize())
#' @rdname DataType
#' @export
-date64 <- function() `arrow::Date64`$new(Date64__initialize())
+date64 <- function() construct(`arrow::Date64`, Date64__initialize())
#' @rdname DataType
#' @export
-time32 <- function(unit) {
- `arrow::Time32`$new(Time32__initialize(unit))
-}
+time32 <- function(unit) construct(`arrow::Time32`, Time32__initialize(unit))
#' @rdname DataType
#' @export
-time64 <- function(unit) `arrow::Time64`$new(Time64__initialize(unit))
+time64 <- function(unit) construct(`arrow::Time64`, Time64__initialize(unit))
#' @rdname DataType
#' @export
-null <- function() `arrow::Null`$new(Null__initialize())
+null <- function() construct(`arrow::Null`, Null__initialize())
#' @rdname DataType
#' @export
timestamp <- function(unit, timezone) {
if (missing(timezone)) {
- `arrow::Timestamp`$new(Timestamp__initialize1(unit))
+ construct(`arrow::Timestamp`, Timestamp__initialize1(unit))
} else {
- `arrow::Timestamp`$new(Timestamp__initialize2(unit, timezone))
+ construct(`arrow::Timestamp`, Timestamp__initialize2(unit, timezone))
}
}
#' @rdname DataType
#' @export
-decimal <- function(precision, scale)
`arrow::Decimal128Type`$new(Decimal128Type__initialize(precision, scale))
+decimal <- function(precision, scale) construct(`arrow::Decimal128Type`,
Decimal128Type__initialize(precision, scale))
`arrow::NestedType` <- R6Class("arrow::NestedType", inherit =
`arrow::DataType`)
diff --git a/r/R/RcppExports.R b/r/R/RcppExports.R
index 915cd4d..7a9f872 100644
--- a/r/R/RcppExports.R
+++ b/r/R/RcppExports.R
@@ -169,6 +169,10 @@ Column__data <- function(column) {
.Call(`_arrow_Column__data`, column)
}
+xptr_is_null <- function(xp) {
+ .Call(`_arrow_xptr_is_null`, xp)
+}
+
Int8__initialize <- function() {
.Call(`_arrow_Int8__initialize`)
}
@@ -333,10 +337,6 @@ Object__pointer_address <- function(obj) {
.Call(`_arrow_Object__pointer_address`, obj)
}
-Object__is_null <- function(obj) {
- .Call(`_arrow_Object__is_null`, obj)
-}
-
DictionaryType__initialize <- function(type, array, ordered) {
.Call(`_arrow_DictionaryType__initialize`, type, array, ordered)
}
diff --git a/r/R/RecordBatch.R b/r/R/RecordBatch.R
index e0866f6..4ac8213 100644
--- a/r/R/RecordBatch.R
+++ b/r/R/RecordBatch.R
@@ -21,8 +21,8 @@
public = list(
num_columns = function() RecordBatch__num_columns(self),
num_rows = function() RecordBatch__num_rows(self),
- schema = function() `arrow::Schema`$new(RecordBatch__schema(self)),
- column = function(i) `arrow::Array`$new(RecordBatch__column(self, i)),
+ schema = function() construct(`arrow::Schema`, RecordBatch__schema(self)),
+ column = function(i) construct(`arrow::Array`, RecordBatch__column(self,
i)),
column_name = function(i) RecordBatch__column_name(self, i),
names = function() RecordBatch__names(self),
Equals = function(other) {
@@ -30,13 +30,13 @@
RecordBatch__Equals(self, other)
},
RemoveColumn = function(i){
- `arrow::RecordBatch`$new(RecordBatch__RemoveColumn(self, i))
+ construct(`arrow::RecordBatch`, RecordBatch__RemoveColumn(self, i))
},
Slice = function(offset, length = NULL) {
if (is.null(length)) {
- `arrow::RecordBatch`$new(RecordBatch__Slice1(self, offset))
+ construct(`arrow::RecordBatch`, RecordBatch__Slice1(self, offset))
} else {
- `arrow::RecordBatch`$new(RecordBatch__Slice2(self, offset, length))
+ construct(`arrow::RecordBatch`, RecordBatch__Slice2(self, offset,
length))
}
},
@@ -65,5 +65,5 @@
#'
#' @export
record_batch <- function(.data){
- `arrow::RecordBatch`$new(RecordBatch__from_dataframe(.data))
+ construct(`arrow::RecordBatch`, RecordBatch__from_dataframe(.data))
}
diff --git a/r/R/RecordBatchReader.R b/r/R/RecordBatchReader.R
index b7c8b00..4232b73 100644
--- a/r/R/RecordBatchReader.R
+++ b/r/R/RecordBatchReader.R
@@ -19,9 +19,9 @@
`arrow::RecordBatchReader` <- R6Class("arrow::RecordBatchReader", inherit =
`arrow::Object`,
public = list(
- schema = function() `arrow::Schema`$new(RecordBatchReader__schema(self)),
+ schema = function() construct(`arrow::Schema`,
RecordBatchReader__schema(self)),
ReadNext = function() {
- `arrow::RecordBatch`$new(RecordBatchReader__ReadNext(self))
+ construct(`arrow::RecordBatch`, RecordBatchReader__ReadNext(self))
}
)
)
@@ -30,9 +30,9 @@
`arrow::ipc::RecordBatchFileReader` <-
R6Class("arrow::ipc::RecordBatchFileReader", inherit = `arrow::Object`,
public = list(
- schema = function()
`arrow::Schema`$new(ipc___RecordBatchFileReader__schema(self)),
+ schema = function() construct(`arrow::Schema`,
ipc___RecordBatchFileReader__schema(self)),
num_record_batches = function()
ipc___RecordBatchFileReader__num_record_batches(self),
- ReadRecordBatch = function(i)
`arrow::RecordBatch`$new(ipc___RecordBatchFileReader__ReadRecordBatch(self, i))
+ ReadRecordBatch = function(i) construct(`arrow::RecordBatch`,
ipc___RecordBatchFileReader__ReadRecordBatch(self, i))
)
)
@@ -47,7 +47,7 @@ record_batch_stream_reader <- function(stream){
#' @export
`record_batch_stream_reader.arrow::io::InputStream` <- function(stream) {
-
`arrow::ipc::RecordBatchStreamReader`$new(ipc___RecordBatchStreamReader__Open(stream))
+ construct(`arrow::ipc::RecordBatchStreamReader`,
ipc___RecordBatchStreamReader__Open(stream))
}
#' @export
@@ -67,7 +67,7 @@ record_batch_file_reader <- function(file) {
#' @export
`record_batch_file_reader.arrow::io::RandomAccessFile` <- function(file) {
-
`arrow::ipc::RecordBatchFileReader`$new(ipc___RecordBatchFileReader__Open(file))
+ construct(`arrow::ipc::RecordBatchFileReader`,
ipc___RecordBatchFileReader__Open(file))
}
#' @export
@@ -166,12 +166,12 @@ read_table.fs_path <- function(stream) {
#' @export
`read_table.arrow::ipc::RecordBatchFileReader` <- function(stream) {
- `arrow::Table`$new(Table__from_RecordBatchFileReader(stream))
+ construct(`arrow::Table`, Table__from_RecordBatchFileReader(stream))
}
#' @export
`read_table.arrow::ipc::RecordBatchStreamReader` <- function(stream) {
- `arrow::Table`$new(Table__from_RecordBatchStreamReader(stream))
+ construct(`arrow::Table`, Table__from_RecordBatchStreamReader(stream))
}
#' @export
diff --git a/r/R/RecordBatchWriter.R b/r/R/RecordBatchWriter.R
index f1ab29d..687c830 100644
--- a/r/R/RecordBatchWriter.R
+++ b/r/R/RecordBatchWriter.R
@@ -41,7 +41,7 @@ record_batch_file_writer <- function(stream, schema) {
inherits(stream, "arrow::io::OutputStream"),
inherits(schema, "arrow::Schema")
)
-
`arrow::ipc::RecordBatchFileWriter`$new(ipc___RecordBatchFileWriter__Open(stream,
schema))
+ construct(`arrow::ipc::RecordBatchFileWriter`,
ipc___RecordBatchFileWriter__Open(stream, schema))
}
#' Create a record batch stream writer
@@ -55,7 +55,7 @@ record_batch_stream_writer <- function(stream, schema) {
inherits(stream, "arrow::io::OutputStream"),
inherits(schema, "arrow::Schema")
)
-
`arrow::ipc::RecordBatchStreamWriter`$new(ipc___RecordBatchStreamWriter__Open(stream,
schema))
+ construct(`arrow::ipc::RecordBatchStreamWriter`,
ipc___RecordBatchStreamWriter__Open(stream, schema))
}
#-------- write_record_batch
diff --git a/r/R/Schema.R b/r/R/Schema.R
index 7f1635d..064a7f0 100644
--- a/r/R/Schema.R
+++ b/r/R/Schema.R
@@ -27,5 +27,5 @@
#' @rdname DataType
#' @export
schema <- function(...){
- `arrow::Schema`$new(schema_(.fields(list(...))))
+ construct(`arrow::Schema`, schema_(.fields(list(...))))
}
diff --git a/r/R/Struct.R b/r/R/Struct.R
index 52e7d6f..047cddc 100644
--- a/r/R/Struct.R
+++ b/r/R/Struct.R
@@ -24,5 +24,5 @@
#' @rdname DataType
#' @export
struct <- function(...){
- `arrow::StructType`$new(struct_(.fields(list(...))))
+ construct(`arrow::StructType`, struct_(.fields(list(...))))
}
diff --git a/r/R/Table.R b/r/R/Table.R
index 62011fc..0d401b9 100644
--- a/r/R/Table.R
+++ b/r/R/Table.R
@@ -21,8 +21,8 @@
public = list(
num_columns = function() Table__num_columns(self),
num_rows = function() Table__num_rows(self),
- schema = function() `arrow::Schema`$new(Table__schema(self)),
- column = function(i) `arrow::Column`$new(Table__column(self, i)),
+ schema = function() construct(`arrow::Schema`, Table__schema(self)),
+ column = function(i) construct(`arrow::Column`, Table__column(self, i)),
serialize = function(output_stream, ...) write_table(self, output_stream,
...)
)
@@ -34,7 +34,7 @@
#'
#' @export
table <- function(.data){
- `arrow::Table`$new(Table__from_dataframe(.data))
+ construct(`arrow::Table`, Table__from_dataframe(.data))
}
#' @export
diff --git a/r/R/array.R b/r/R/array.R
index 7e64daf..a514df2 100644
--- a/r/R/array.R
+++ b/r/R/array.R
@@ -29,14 +29,14 @@
type_id = function() Array__type_id(self),
Equals = function(other) Array__Equals(self, other),
ApproxEquals = function(othet) Array__ApproxEquals(self, other),
- data = function() `arrow::ArrayData`$new(Array__data(self)),
+ data = function() construct(`arrow::ArrayData`, Array__data(self)),
as_vector = function() Array__as_vector(self),
ToString = function() Array__ToString(self),
Slice = function(offset, length = NULL){
if (is.null(length)) {
- `arrow::Array`$new(Array__Slice1(self, offset))
+ construct(`arrow::Array`, Array__Slice1(self, offset))
} else {
- `arrow::Array`$new(Array__Slice2(self, offset, length))
+ construct(`arrow::Array`, Array__Slice2(self, offset, length))
}
},
RangeEquals = function(other, start_idx, end_idx, other_start_idx) {
@@ -47,9 +47,9 @@
)
`arrow::Array`$dispatch <- function(xp){
- a <- `arrow::Array`$new(xp)
+ a <- construct(`arrow::Array`, xp)
if(a$type_id() == Type$DICTIONARY){
- a <- `arrow::DictionaryArray`$new(xp)
+ a <- construct(`arrow::DictionaryArray`, xp)
}
a
}
diff --git a/r/R/buffer.R b/r/R/buffer.R
index 5f65721..3c012d8 100644
--- a/r/R/buffer.R
+++ b/r/R/buffer.R
@@ -47,15 +47,15 @@ buffer.default <- function(x) {
#' @export
buffer.raw <- function(x) {
- `arrow::Buffer`$new(r___RBuffer__initialize(x))
+ construct(`arrow::Buffer`, r___RBuffer__initialize(x))
}
#' @export
buffer.numeric <- function(x) {
- `arrow::Buffer`$new(r___RBuffer__initialize(x))
+ construct(`arrow::Buffer`, r___RBuffer__initialize(x))
}
#' @export
buffer.integer <- function(x) {
- `arrow::Buffer`$new(r___RBuffer__initialize(x))
+ construct(`arrow::Buffer`, r___RBuffer__initialize(x))
}
diff --git a/r/R/dictionary.R b/r/R/dictionary.R
index 4dea59c..28147f8 100644
--- a/r/R/dictionary.R
+++ b/r/R/dictionary.R
@@ -22,7 +22,7 @@
public = list(
index_type = function()
`arrow::DataType`$dispatch(DictionaryType__index_type(self)),
name = function() DictionaryType__name(self),
- dictionary = function()
`arrow::Array`$new(DictionaryType__dictionary(self)),
+ dictionary = function() construct(`arrow::Array`,
DictionaryType__dictionary(self)),
ordered = function() DictionaryType__ordered(self)
)
@@ -40,5 +40,5 @@ dictionary <- function(type, values, ordered = FALSE) {
inherits(type, "arrow::DataType"),
inherits(values, "arrow::Array")
)
- `arrow::DictionaryType`$new(DictionaryType__initialize(type, values,
ordered))
+ construct(`arrow::DictionaryType`, DictionaryType__initialize(type, values,
ordered))
}
diff --git a/r/R/io.R b/r/R/io.R
index 1516bd3..9b0c2cd 100644
--- a/r/R/io.R
+++ b/r/R/io.R
@@ -21,7 +21,7 @@
`arrow::io::Readable` <- R6Class("arrow::io::Readable", inherit =
`arrow::Object`,
public = list(
- Read = function(nbytes) `arrow::Buffer`$new(io___Readable__Read(self,
nbytes))
+ Read = function(nbytes) construct(`arrow::Buffer`,
io___Readable__Read(self, nbytes))
)
)
@@ -50,7 +50,7 @@
`arrow::io::BufferOutputStream` <- R6Class("arrow::io::BufferOutputStream",
inherit = `arrow::io::OutputStream`,
public = list(
capacity = function() io___BufferOutputStream__capacity(self),
- Finish = function()
`arrow::Buffer`$new(io___BufferOutputStream__Finish(self)),
+ Finish = function() construct(`arrow::Buffer`,
io___BufferOutputStream__Finish(self)),
Write = function(bytes) io___BufferOutputStream__Write(self, bytes),
Tell = function() io___BufferOutputStream__Tell(self)
)
@@ -88,38 +88,38 @@
#' @rdname io
#' @export
mmap_create <- `arrow::io::MemoryMappedFile`$create <- function(path, size) {
-
`arrow::io::MemoryMappedFile`$new(io___MemoryMappedFile__Create(fs::path_abs(path),
size))
+ construct(`arrow::io::MemoryMappedFile`,
io___MemoryMappedFile__Create(fs::path_abs(path), size))
}
#' @rdname io
#' @export
mmap_open <- `arrow::io::MemoryMappedFile`$open <- function(path, mode =
c("read", "write", "readwrite")) {
mode <- match(match.arg(mode), c("read", "write", "readwrite")) - 1L
-
`arrow::io::MemoryMappedFile`$new(io___MemoryMappedFile__Open(fs::path_abs(path),
mode))
+ construct(`arrow::io::MemoryMappedFile`,
io___MemoryMappedFile__Open(fs::path_abs(path), mode))
}
#' @rdname io
#' @export
file_open <- `arrow::io::ReadableFile`$open <- function(path) {
- `arrow::io::ReadableFile`$new(io___ReadableFile__Open(fs::path_abs(path)))
+ construct(`arrow::io::ReadableFile`,
io___ReadableFile__Open(fs::path_abs(path)))
}
#' @rdname io
#' @export
file_output_stream <- function(path) {
- `arrow::io::FileOutputStream`$new(io___FileOutputStream__Open(path))
+ construct(`arrow::io::FileOutputStream`, io___FileOutputStream__Open(path))
}
#' @rdname io
#' @export
mock_output_stream <- function() {
- `arrow::io::MockOutputStream`$new(io___MockOutputStream__initialize())
+ construct(`arrow::io::MockOutputStream`, io___MockOutputStream__initialize())
}
#' @rdname io
#' @export
buffer_output_stream <- function(initial_capacity = 0L) {
-
`arrow::io::BufferOutputStream`$new(io___BufferOutputStream__Create(initial_capacity))
+ construct(`arrow::io::BufferOutputStream`,
io___BufferOutputStream__Create(initial_capacity))
}
#' @rdname io
@@ -136,7 +136,7 @@ fixed_size_buffer_writer.default <- function(buffer){
#' @export
`fixed_size_buffer_writer.arrow::Buffer` <- function(buffer){
assert_that(buffer$is_mutable())
-
`arrow::io::FixedSizeBufferWriter`$new(io___FixedSizeBufferWriter__initialize(buffer))
+ construct(`arrow::io::FixedSizeBufferWriter`,
io___FixedSizeBufferWriter__initialize(buffer))
}
#' Create a `arrow::BufferReader`
@@ -150,7 +150,7 @@ buffer_reader <- function(x) {
#' @export
`buffer_reader.arrow::Buffer` <- function(x) {
- `arrow::io::BufferReader`$new(io___BufferReader__initialize(x))
+ construct(`arrow::io::BufferReader`, io___BufferReader__initialize(x))
}
#' @export
diff --git a/r/R/memory_pool.R b/r/R/memory_pool.R
index c738c00..cc2fcc7 100644
--- a/r/R/memory_pool.R
+++ b/r/R/memory_pool.R
@@ -29,5 +29,5 @@
)
default_memory_pool <- function() {
- `arrow::MemoryPool`$new(MemoryPool__default())
+ construct(`arrow::MemoryPool`, MemoryPool__default())
}
diff --git a/r/src/RcppExports.cpp b/r/src/RcppExports.cpp
index 8b4c89a..949ce71 100644
--- a/r/src/RcppExports.cpp
+++ b/r/src/RcppExports.cpp
@@ -482,6 +482,17 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
+// xptr_is_null
+bool xptr_is_null(SEXP xp);
+RcppExport SEXP _arrow_xptr_is_null(SEXP xpSEXP) {
+BEGIN_RCPP
+ Rcpp::RObject rcpp_result_gen;
+ Rcpp::RNGScope rcpp_rngScope_gen;
+ Rcpp::traits::input_parameter< SEXP >::type xp(xpSEXP);
+ rcpp_result_gen = Rcpp::wrap(xptr_is_null(xp));
+ return rcpp_result_gen;
+END_RCPP
+}
// Int8__initialize
std::shared_ptr<arrow::DataType> Int8__initialize();
RcppExport SEXP _arrow_Int8__initialize() {
@@ -920,17 +931,6 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
-// Object__is_null
-bool Object__is_null(const std::shared_ptr<void>& obj);
-RcppExport SEXP _arrow_Object__is_null(SEXP objSEXP) {
-BEGIN_RCPP
- Rcpp::RObject rcpp_result_gen;
- Rcpp::RNGScope rcpp_rngScope_gen;
- Rcpp::traits::input_parameter< const std::shared_ptr<void>& >::type
obj(objSEXP);
- rcpp_result_gen = Rcpp::wrap(Object__is_null(obj));
- return rcpp_result_gen;
-END_RCPP
-}
// DictionaryType__initialize
std::shared_ptr<arrow::DataType> DictionaryType__initialize(const
std::shared_ptr<arrow::DataType>& type, const std::shared_ptr<arrow::Array>&
array, bool ordered);
RcppExport SEXP _arrow_DictionaryType__initialize(SEXP typeSEXP, SEXP
arraySEXP, SEXP orderedSEXP) {
@@ -1704,6 +1704,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_arrow_Column__null_count", (DL_FUNC) &_arrow_Column__null_count, 1},
{"_arrow_Column__type", (DL_FUNC) &_arrow_Column__type, 1},
{"_arrow_Column__data", (DL_FUNC) &_arrow_Column__data, 1},
+ {"_arrow_xptr_is_null", (DL_FUNC) &_arrow_xptr_is_null, 1},
{"_arrow_Int8__initialize", (DL_FUNC) &_arrow_Int8__initialize, 0},
{"_arrow_Int16__initialize", (DL_FUNC) &_arrow_Int16__initialize, 0},
{"_arrow_Int32__initialize", (DL_FUNC) &_arrow_Int32__initialize, 0},
@@ -1745,7 +1746,6 @@ static const R_CallMethodDef CallEntries[] = {
{"_arrow_TimestampType__timezone", (DL_FUNC)
&_arrow_TimestampType__timezone, 1},
{"_arrow_TimestampType__unit", (DL_FUNC) &_arrow_TimestampType__unit, 1},
{"_arrow_Object__pointer_address", (DL_FUNC)
&_arrow_Object__pointer_address, 1},
- {"_arrow_Object__is_null", (DL_FUNC) &_arrow_Object__is_null, 1},
{"_arrow_DictionaryType__initialize", (DL_FUNC)
&_arrow_DictionaryType__initialize, 3},
{"_arrow_DictionaryType__index_type", (DL_FUNC)
&_arrow_DictionaryType__index_type, 1},
{"_arrow_DictionaryType__name", (DL_FUNC) &_arrow_DictionaryType__name, 1},
diff --git a/r/src/array.cpp b/r/src/array.cpp
index 71bdb52..e885b66 100644
--- a/r/src/array.cpp
+++ b/r/src/array.cpp
@@ -23,6 +23,9 @@ using namespace arrow;
namespace arrow {
namespace r {
+// the integer64 sentinel
+static const int64_t NA_INT64 = std::numeric_limits<int64_t>::min();
+
template <int RTYPE, typename Type>
std::shared_ptr<Array> SimpleArray(SEXP x) {
Rcpp::Vector<RTYPE> vec(x);
@@ -329,6 +332,47 @@ std::shared_ptr<Array> Date64Array_From_POSIXct(SEXP x) {
return std::make_shared<Date64Array>(data);
}
+std::shared_ptr<arrow::Array> Int64Array(SEXP x) {
+ auto p_vec_start = reinterpret_cast<int64_t*>(REAL(x));
+ auto n = Rf_xlength(x);
+ int64_t null_count = 0;
+
+ std::vector<std::shared_ptr<Buffer>> buffers{nullptr,
+
std::make_shared<RBuffer<REALSXP>>(x)};
+
+ auto p_vec = std::find(p_vec_start, p_vec_start + n, NA_INT64);
+ auto first_na = p_vec - p_vec_start;
+ if (first_na < n) {
+ R_ERROR_NOT_OK(AllocateBuffer(BitUtil::BytesForBits(n), &buffers[0]));
+ internal::FirstTimeBitmapWriter bitmap_writer(buffers[0]->mutable_data(),
0, n);
+
+ // first loop to clear all the bits before the first NA
+ int i = 0;
+ for (; i < first_na; i++, bitmap_writer.Next()) {
+ bitmap_writer.Set();
+ }
+
+ // then finish
+ for (; i < n; i++, bitmap_writer.Next(), ++p_vec) {
+ if (*p_vec == NA_INT64) {
+ bitmap_writer.Clear();
+ null_count++;
+ } else {
+ bitmap_writer.Set();
+ }
+ }
+
+ bitmap_writer.Finish();
+ }
+
+ auto data = ArrayData::Make(
+ std::make_shared<Int64Type>(), n, std::move(buffers), null_count, 0
/*offset*/
+ );
+
+ // return the right Array class
+ return std::make_shared<typename TypeTraits<Int64Type>::ArrayType>(data);
+}
+
} // namespace r
} // namespace arrow
@@ -355,6 +399,9 @@ std::shared_ptr<arrow::Array> Array__from_vector(SEXP x) {
if (Rf_inherits(x, "POSIXct")) {
return arrow::r::Date64Array_From_POSIXct<REALSXP>(x);
}
+ if (Rf_inherits(x, "integer64")) {
+ return arrow::r::Int64Array(x);
+ }
return arrow::r::SimpleArray<REALSXP, arrow::DoubleType>(x);
case RAWSXP:
return arrow::r::SimpleArray<RAWSXP, arrow::Int8Type>(x);
@@ -596,11 +643,19 @@ SEXP promotion_Array_to_Vector(const
std::shared_ptr<Array>& array) {
using value_type = typename TypeTraits<Type>::ArrayType::value_type;
auto n = array->length();
- auto start = reinterpret_cast<const
value_type*>(array->data()->buffers[1]->data()) +
- array->offset();
-
Rcpp::Vector<RTYPE> vec(no_init(n));
- if (array->null_count()) {
+ if (n == 0) {
+ return vec;
+ }
+ auto null_count = array->null_count();
+ if (null_count == n) {
+ std::fill(vec.begin(), vec.end(), NA_REAL);
+ return vec;
+ }
+
+ auto start = GetValuesSafely<value_type>(array->data(), 1, array->offset());
+
+ if (null_count) {
internal::BitmapReader bitmap_reader(array->null_bitmap()->data(),
array->offset(),
n);
for (size_t i = 0; i < n; i++, bitmap_reader.Next()) {
@@ -615,6 +670,34 @@ SEXP promotion_Array_to_Vector(const
std::shared_ptr<Array>& array) {
return vec;
}
+SEXP Int64Array(const std::shared_ptr<Array>& array) {
+ auto n = array->length();
+ NumericVector vec(n);
+ vec.attr("class") = "integer64";
+ if (n == 0) {
+ return vec;
+ }
+ auto null_count = array->null_count();
+ if (null_count == n) {
+ std::fill(vec.begin(), vec.end(), NA_REAL);
+ return vec;
+ }
+ auto p_values = GetValuesSafely<int64_t>(array->data(), 1, array->offset());
+ auto p_vec = reinterpret_cast<int64_t*>(vec.begin());
+
+ if (array->null_count()) {
+ internal::BitmapReader bitmap_reader(array->null_bitmap()->data(),
array->offset(),
+ n);
+ for (size_t i = 0; i < n; i++, bitmap_reader.Next()) {
+ p_vec[i] = bitmap_reader.IsNotSet() ? NA_INT64 : p_values[i];
+ }
+ } else {
+ std::copy_n(p_values, n, p_vec);
+ }
+
+ return vec;
+}
+
} // namespace r
} // namespace arrow
@@ -664,9 +747,7 @@ SEXP Array__as_vector(const std::shared_ptr<arrow::Array>&
array) {
// lossy promotions to numeric vector
case Type::INT64:
- return arrow::r::promotion_Array_to_Vector<REALSXP,
arrow::Int64Type>(array);
- case Type::UINT64:
- return arrow::r::promotion_Array_to_Vector<REALSXP,
arrow::UInt64Type>(array);
+ return arrow::r::Int64Array(array);
default:
break;
diff --git a/r/src/ArrayData.cpp b/r/src/arraydata.cpp
similarity index 100%
rename from r/src/ArrayData.cpp
rename to r/src/arraydata.cpp
diff --git a/r/src/ChunkedArray.cpp b/r/src/chunkedarray.cpp
similarity index 100%
rename from r/src/ChunkedArray.cpp
rename to r/src/chunkedarray.cpp
diff --git a/r/src/Column.cpp b/r/src/column.cpp
similarity index 100%
rename from r/src/Column.cpp
rename to r/src/column.cpp
diff --git a/r/src/DataType.cpp b/r/src/datatype.cpp
similarity index 98%
rename from r/src/DataType.cpp
rename to r/src/datatype.cpp
index 595dee3..90378f7 100644
--- a/r/src/DataType.cpp
+++ b/r/src/datatype.cpp
@@ -20,6 +20,11 @@
using namespace Rcpp;
// [[Rcpp::export]]
+bool xptr_is_null(SEXP xp) {
+ return reinterpret_cast<std::shared_ptr<void>*>(EXTPTR_PTR(xp))->get() ==
nullptr;
+}
+
+// [[Rcpp::export]]
std::shared_ptr<arrow::DataType> Int8__initialize() { return arrow::int8(); }
// [[Rcpp::export]]
@@ -215,9 +220,6 @@ std::string Object__pointer_address(SEXP obj) {
}
// [[Rcpp::export]]
-bool Object__is_null(const std::shared_ptr<void>& obj) { return obj.get() ==
nullptr; }
-
-// [[Rcpp::export]]
std::shared_ptr<arrow::DataType> DictionaryType__initialize(
const std::shared_ptr<arrow::DataType>& type,
const std::shared_ptr<arrow::Array>& array, bool ordered) {
diff --git a/r/src/MemoryPool.cpp b/r/src/memorypool.cpp
similarity index 100%
rename from r/src/MemoryPool.cpp
rename to r/src/memorypool.cpp
diff --git a/r/src/RecordBatch.cpp b/r/src/recordbatch.cpp
similarity index 100%
rename from r/src/RecordBatch.cpp
rename to r/src/recordbatch.cpp
diff --git a/r/src/RecordBatchReader.cpp b/r/src/recordbatchreader.cpp
similarity index 97%
rename from r/src/RecordBatchReader.cpp
rename to r/src/recordbatchreader.cpp
index 1ddc397..9ab31c8 100644
--- a/r/src/RecordBatchReader.cpp
+++ b/r/src/recordbatchreader.cpp
@@ -59,7 +59,9 @@ int ipc___RecordBatchFileReader__num_record_batches(
std::shared_ptr<arrow::RecordBatch>
ipc___RecordBatchFileReader__ReadRecordBatch(
const std::shared_ptr<arrow::ipc::RecordBatchFileReader>& reader, int i) {
std::shared_ptr<arrow::RecordBatch> batch;
- R_ERROR_NOT_OK(reader->ReadRecordBatch(i, &batch));
+ if (i >= 0 && i < reader->num_record_batches()) {
+ R_ERROR_NOT_OK(reader->ReadRecordBatch(i, &batch));
+ }
return batch;
}
diff --git a/r/src/RecordBatchWriter.cpp b/r/src/recordbatchwriter.cpp
similarity index 100%
rename from r/src/RecordBatchWriter.cpp
rename to r/src/recordbatchwriter.cpp
diff --git a/r/src/Table.cpp b/r/src/table.cpp
similarity index 100%
rename from r/src/Table.cpp
rename to r/src/table.cpp
diff --git a/r/tests/testthat/test-Array.R b/r/tests/testthat/test-Array.R
index d562435..0bcc935 100644
--- a/r/tests/testthat/test-Array.R
+++ b/r/tests/testthat/test-Array.R
@@ -242,3 +242,17 @@ test_that("array supports POSIXct (ARROW-3340)", {
expect_true(a$IsNull(4))
})
+test_that("array supports integer64", {
+ x <- bit64::as.integer64(1:10)
+ a <- array(x)
+ expect_equal(a$type(), int64())
+ expect_equal(a$length(), 10L)
+ expect_equal(a$as_vector(), x)
+
+ x[4] <- NA
+ a <- array(x)
+ expect_equal(a$type(), int64())
+ expect_equal(a$length(), 10L)
+ expect_equal(a$as_vector(), x)
+ expect_true(a$IsNull(3L))
+})
diff --git a/r/tests/testthat/test-RecordBatch.R
b/r/tests/testthat/test-RecordBatch.R
index c6a31bb..2f535c3 100644
--- a/r/tests/testthat/test-RecordBatch.R
+++ b/r/tests/testthat/test-RecordBatch.R
@@ -135,15 +135,17 @@ test_that("read_record_batch handles various streams
(ARROW-3450, ARROW-3505)",
mmap_file <- close_on_exit(mmap_open(tf))
batch4 <- read_record_batch(mmap_file)
-
batch5 <- read_record_batch(bytes)
batch6 <- read_record_batch(buf_reader)
+ expect_error(read_record_batch(buf_reader))
stream_reader <- record_batch_stream_reader(bytes)
batch7 <- read_record_batch(stream_reader)
+ expect_null(read_record_batch(stream_reader))
file_reader <- record_batch_file_reader(tf)
batch8 <- read_record_batch(file_reader)
+ expect_null(read_record_batch(file_reader, i = 2))
expect_equal(batch, batch1)
expect_equal(batch, batch2)