Skip to content

Commit 4e5c7af

Browse files
romainfrancoiswesm
authored andcommitted
ARROW-3499: [R] Expose arrow::ipc::Message type
Exposing the `arrow::ipc::Message` and `arrow::ipc::MessageReader` classes with some associated functions: ``` r library(arrow) batch <- record_batch(tibble::tibble(x = 1:10)) bytes <- write_record_batch(batch, raw()) reader <- message_reader(bytes) m <- reader$ReadNextMessage() m #> arrow::ipc::Message m$body() #> arrow::Buffer m$type() #> [1] 1 m <- reader$ReadNextMessage() m #> arrow::ipc::Message m$body() #> arrow::Buffer m$type() #> [1] 3 ``` <sup>Created on 2018-11-07 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1.9000)</sup> Author: Romain Francois <romain@purrple.cat> Closes apache#2915 from romainfrancois/ARROW-3499/Message and squashes the following commits: 2561a7e <Romain Francois> ➕ read_schema generic and methods 904f59f <Romain Francois> ➕ read_record_batch.{Message,Schema} method 8632826 <Romain Francois> `Message` exposes `body` and `metadata` as actives instead of methods. closer to 🐍 interface 53b5a25 <Romain Francois> document Message::Type enum fd6775c <Romain Francois> Message and MessageReader e4fe791 <Romain Francois> s/ipc___MessageReader__Create/ipc___MessageReader__Open/ b09811d <Romain Francois> s/construct/shared_ptr/, add unique_ptr R function. support for unique_ptr. 30a0a1a <Romain Francois> expose enum Message::Type 9391a42 <Romain Francois> lint be91970 <Romain Francois> R6 class support for arrow::ipc::Message backed by a unique_ptr 033ab9f <Romain Francois> using struct input_parameter<const std::shared_ptr<T>& instead of the heavier Exporter class
1 parent d5f7b02 commit 4e5c7af

38 files changed

Lines changed: 835 additions & 169 deletions

r/DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Collate:
5757
'dictionary.R'
5858
'io.R'
5959
'memory_pool.R'
60+
'message.R'
6061
'on_exit.R'
6162
'reexports-bit64.R'
6263
'reexports-tibble.R'

r/NAMESPACE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ S3method("==","arrow::Array")
55
S3method("==","arrow::DataType")
66
S3method("==","arrow::Field")
77
S3method("==","arrow::RecordBatch")
8+
S3method("==","arrow::ipc::Message")
89
S3method(as_tibble,"arrow::RecordBatch")
910
S3method(as_tibble,"arrow::Table")
1011
S3method(buffer,default)
@@ -16,15 +17,25 @@ S3method(buffer_reader,default)
1617
S3method(fixed_size_buffer_writer,"arrow::Buffer")
1718
S3method(fixed_size_buffer_writer,default)
1819
S3method(length,"arrow::Array")
20+
S3method(message_reader,"arrow::io::InputStream")
21+
S3method(message_reader,default)
22+
S3method(message_reader,raw)
1923
S3method(names,"arrow::RecordBatch")
2024
S3method(print,"arrow-enum")
25+
S3method(read_message,"arrow::io::InputStream")
26+
S3method(read_message,default)
2127
S3method(read_record_batch,"arrow::io::BufferReader")
2228
S3method(read_record_batch,"arrow::io::RandomAccessFile")
29+
S3method(read_record_batch,"arrow::ipc::Message")
2330
S3method(read_record_batch,"arrow::ipc::RecordBatchFileReader")
2431
S3method(read_record_batch,"arrow::ipc::RecordBatchStreamReader")
2532
S3method(read_record_batch,character)
2633
S3method(read_record_batch,fs_path)
2734
S3method(read_record_batch,raw)
35+
S3method(read_schema,"arrow::Buffer")
36+
S3method(read_schema,"arrow::io::InputStream")
37+
S3method(read_schema,default)
38+
S3method(read_schema,raw)
2839
S3method(read_table,"arrow::io::BufferReader")
2940
S3method(read_table,"arrow::io::RandomAccessFile")
3041
S3method(read_table,"arrow::ipc::RecordBatchFileReader")
@@ -52,6 +63,7 @@ S3method(write_table,fs_path)
5263
S3method(write_table,raw)
5364
export(DateUnit)
5465
export(FileMode)
66+
export(MessageType)
5567
export(StatusCode)
5668
export(TimeUnit)
5769
export(Type)
@@ -77,13 +89,16 @@ export(int32)
7789
export(int64)
7890
export(int8)
7991
export(list_of)
92+
export(message_reader)
8093
export(mmap_create)
8194
export(mmap_open)
8295
export(mock_output_stream)
8396
export(null)
8497
export(print.integer64)
8598
export(read_arrow)
99+
export(read_message)
86100
export(read_record_batch)
101+
export(read_schema)
87102
export(read_table)
88103
export(record_batch)
89104
export(record_batch_file_reader)

r/R/ChunkedArray.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
length = function() ChunkedArray__length(self),
2323
null_count = function() ChunkedArray__null_count(self),
2424
num_chunks = function() ChunkedArray__num_chunks(self),
25-
chunk = function(i) construct(`arrow::Array`, ChunkedArray__chunk(self, i)),
26-
chunks = function() purrr::map(ChunkedArray__chunks(self), construct, class = `arrow::Array`),
25+
chunk = function(i) shared_ptr(`arrow::Array`, ChunkedArray__chunk(self, i)),
26+
chunks = function() purrr::map(ChunkedArray__chunks(self), shared_ptr, class = `arrow::Array`),
2727
type = function() `arrow::DataType`$dispatch(ChunkedArray__type(self)),
2828
as_vector = function() ChunkedArray__as_vector(self),
2929
Slice = function(offset, length = NULL){
3030
if (is.null(length)) {
31-
construct(`arrow::ChunkedArray`, ChunkArray__Slice1(self, offset))
31+
shared_ptr(`arrow::ChunkedArray`, ChunkArray__Slice1(self, offset))
3232
} else {
33-
construct(`arrow::ChunkedArray`, ChunkArray__Slice2(self, offset, length))
33+
shared_ptr(`arrow::ChunkedArray`, ChunkArray__Slice2(self, offset, length))
3434
}
3535
}
3636
)
@@ -42,5 +42,5 @@
4242
#'
4343
#' @export
4444
chunked_array <- function(...){
45-
construct(`arrow::ChunkedArray`, ChunkedArray__from_list(rlang::list2(...)))
45+
shared_ptr(`arrow::ChunkedArray`, ChunkedArray__from_list(rlang::list2(...)))
4646
}

r/R/Column.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
length = function() Column__length(self),
2323
null_count = function() Column__null_count(self),
2424
type = function() `arrow::DataType`$dispatch(Column__type(self)),
25-
data = function() construct(`arrow::ChunkedArray`, Column__data(self))
25+
data = function() shared_ptr(`arrow::ChunkedArray`, Column__data(self))
2626
)
2727
)

r/R/Field.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
}
4242

4343
field <- function(name, type) {
44-
construct(`arrow::Field`, Field__initialize(name, type))
44+
shared_ptr(`arrow::Field`, Field__initialize(name, type))
4545
}
4646

4747
.fields <- function(.list){

r/R/List.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323

2424
#' @rdname DataType
2525
#' @export
26-
list_of <- function(type) construct(`arrow::ListType`, list__(type))
26+
list_of <- function(type) shared_ptr(`arrow::ListType`, list__(type))

r/R/R6.R

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,21 @@
3232
self$`.:xp:.` <- xp
3333
},
3434
print = function(...){
35-
cat(crayon::silver(glue::glue("{cl} <{p}>", cl = class(self)[[1]], p = self$pointer_address())), "\n")
35+
cat(crayon::silver(glue::glue("{cl}", cl = class(self)[[1]])), "\n")
3636
if(!is.null(self$ToString)){
3737
cat(self$ToString(), "\n")
3838
}
3939
invisible(self)
40-
},
41-
pointer_address = function(){
42-
Object__pointer_address(self$pointer())
4340
}
4441
)
4542
)
4643

47-
construct <- function(class, xp) {
48-
if (!xptr_is_null(xp)) class$new(xp)
44+
shared_ptr <- function(class, xp) {
45+
if(!shared_ptr_is_null(xp)) class$new(xp)
46+
}
47+
48+
unique_ptr <- function(class, xp) {
49+
if(!unique_ptr_is_null(xp)) class$new(xp)
4950
}
5051

5152
#' @export
@@ -70,7 +71,7 @@ construct <- function(class, xp) {
7071
DataType__num_children(self)
7172
},
7273
children = function() {
73-
map(DataType__children_pointer(self), construct, class= `arrow::Field`)
74+
map(DataType__children_pointer(self), shared_ptr, class= `arrow::Field`)
7475
},
7576
id = function(){
7677
DataType__id(self)
@@ -94,23 +95,23 @@ construct <- function(class, xp) {
9495
BINARY = stop("Type BINARY not implemented yet"),
9596
DATE32 = date32(),
9697
DATE64 = date64(),
97-
TIMESTAMP = construct(`arrow::Timestamp`,self$pointer()),
98-
TIME32 = construct(`arrow::Time32`,self$pointer()),
99-
TIME64 = construct(`arrow::Time64`,self$pointer()),
98+
TIMESTAMP = shared_ptr(`arrow::Timestamp`,self$pointer()),
99+
TIME32 = shared_ptr(`arrow::Time32`,self$pointer()),
100+
TIME64 = shared_ptr(`arrow::Time64`,self$pointer()),
100101
INTERVAL = stop("Type INTERVAL not implemented yet"),
101-
DECIMAL = construct(`arrow::Decimal128Type`, self$pointer()),
102-
LIST = construct(`arrow::ListType`, self$pointer()),
103-
STRUCT = construct(`arrow::StructType`, self$pointer()),
102+
DECIMAL = shared_ptr(`arrow::Decimal128Type`, self$pointer()),
103+
LIST = shared_ptr(`arrow::ListType`, self$pointer()),
104+
STRUCT = shared_ptr(`arrow::StructType`, self$pointer()),
104105
UNION = stop("Type UNION not implemented yet"),
105-
DICTIONARY = construct(`arrow::DictionaryType`, self$pointer()),
106+
DICTIONARY = shared_ptr(`arrow::DictionaryType`, self$pointer()),
106107
MAP = stop("Type MAP not implemented yet")
107108
)
108109
}
109110
)
110111
)
111112

112113
`arrow::DataType`$dispatch <- function(xp){
113-
construct(`arrow::DataType`, xp)$..dispatch()
114+
shared_ptr(`arrow::DataType`, xp)$..dispatch()
114115
}
115116

116117
#----- metadata
@@ -243,88 +244,88 @@ construct <- function(class, xp) {
243244
#'
244245
#' @rdname DataType
245246
#' @export
246-
int8 <- function() construct(`arrow::Int8`, Int8__initialize())
247+
int8 <- function() shared_ptr(`arrow::Int8`, Int8__initialize())
247248

248249
#' @rdname DataType
249250
#' @export
250-
int16 <- function() construct(`arrow::Int16`, Int16__initialize())
251+
int16 <- function() shared_ptr(`arrow::Int16`, Int16__initialize())
251252

252253
#' @rdname DataType
253254
#' @export
254-
int32 <- function() construct(`arrow::Int32`, Int32__initialize())
255+
int32 <- function() shared_ptr(`arrow::Int32`, Int32__initialize())
255256

256257
#' @rdname DataType
257258
#' @export
258-
int64 <- function() construct(`arrow::Int64`, Int64__initialize())
259+
int64 <- function() shared_ptr(`arrow::Int64`, Int64__initialize())
259260

260261
#' @rdname DataType
261262
#' @export
262-
uint8 <- function() construct(`arrow::UInt8`, UInt8__initialize())
263+
uint8 <- function() shared_ptr(`arrow::UInt8`, UInt8__initialize())
263264

264265
#' @rdname DataType
265266
#' @export
266-
uint16 <- function() construct(`arrow::UInt16`, UInt16__initialize())
267+
uint16 <- function() shared_ptr(`arrow::UInt16`, UInt16__initialize())
267268

268269
#' @rdname DataType
269270
#' @export
270-
uint32 <- function() construct(`arrow::UInt32`, UInt32__initialize())
271+
uint32 <- function() shared_ptr(`arrow::UInt32`, UInt32__initialize())
271272

272273
#' @rdname DataType
273274
#' @export
274-
uint64 <- function() construct(`arrow::UInt64`, UInt64__initialize())
275+
uint64 <- function() shared_ptr(`arrow::UInt64`, UInt64__initialize())
275276

276277
#' @rdname DataType
277278
#' @export
278-
float16 <- function() construct(`arrow::Float16`, Float16__initialize())
279+
float16 <- function() shared_ptr(`arrow::Float16`, Float16__initialize())
279280

280281
#' @rdname DataType
281282
#' @export
282-
float32 <- function() construct(`arrow::Float32`, Float32__initialize())
283+
float32 <- function() shared_ptr(`arrow::Float32`, Float32__initialize())
283284

284285
#' @rdname DataType
285286
#' @export
286-
float64 <- function() construct(`arrow::Float64`, Float64__initialize())
287+
float64 <- function() shared_ptr(`arrow::Float64`, Float64__initialize())
287288

288289
#' @rdname DataType
289290
#' @export
290-
boolean <- function() construct(`arrow::Boolean`, Boolean__initialize())
291+
boolean <- function() shared_ptr(`arrow::Boolean`, Boolean__initialize())
291292

292293
#' @rdname DataType
293294
#' @export
294-
utf8 <- function() construct(`arrow::Utf8`, Utf8__initialize())
295+
utf8 <- function() shared_ptr(`arrow::Utf8`, Utf8__initialize())
295296

296297
#' @rdname DataType
297298
#' @export
298-
date32 <- function() construct(`arrow::Date32`, Date32__initialize())
299+
date32 <- function() shared_ptr(`arrow::Date32`, Date32__initialize())
299300

300301
#' @rdname DataType
301302
#' @export
302-
date64 <- function() construct(`arrow::Date64`, Date64__initialize())
303+
date64 <- function() shared_ptr(`arrow::Date64`, Date64__initialize())
303304

304305
#' @rdname DataType
305306
#' @export
306-
time32 <- function(unit) construct(`arrow::Time32`, Time32__initialize(unit))
307+
time32 <- function(unit) shared_ptr(`arrow::Time32`, Time32__initialize(unit))
307308

308309
#' @rdname DataType
309310
#' @export
310-
time64 <- function(unit) construct(`arrow::Time64`, Time64__initialize(unit))
311+
time64 <- function(unit) shared_ptr(`arrow::Time64`, Time64__initialize(unit))
311312

312313
#' @rdname DataType
313314
#' @export
314-
null <- function() construct(`arrow::Null`, Null__initialize())
315+
null <- function() shared_ptr(`arrow::Null`, Null__initialize())
315316

316317
#' @rdname DataType
317318
#' @export
318319
timestamp <- function(unit, timezone) {
319320
if (missing(timezone)) {
320-
construct(`arrow::Timestamp`, Timestamp__initialize1(unit))
321+
shared_ptr(`arrow::Timestamp`, Timestamp__initialize1(unit))
321322
} else {
322-
construct(`arrow::Timestamp`, Timestamp__initialize2(unit, timezone))
323+
shared_ptr(`arrow::Timestamp`, Timestamp__initialize2(unit, timezone))
323324
}
324325
}
325326

326327
#' @rdname DataType
327328
#' @export
328-
decimal <- function(precision, scale) construct(`arrow::Decimal128Type`, Decimal128Type__initialize(precision, scale))
329+
decimal <- function(precision, scale) shared_ptr(`arrow::Decimal128Type`, Decimal128Type__initialize(precision, scale))
329330

330331
`arrow::NestedType` <- R6Class("arrow::NestedType", inherit = `arrow::DataType`)

r/R/RcppExports.R

Lines changed: 50 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)