Skip to content

Commit b09811d

Browse files
s/construct/shared_ptr/, add unique_ptr R function. support for unique_ptr.
1 parent 30a0a1a commit b09811d

24 files changed

Lines changed: 209 additions & 95 deletions

r/NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ S3method(buffer_reader,default)
1616
S3method(fixed_size_buffer_writer,"arrow::Buffer")
1717
S3method(fixed_size_buffer_writer,default)
1818
S3method(length,"arrow::Array")
19+
S3method(message_reader,"arrow::io::InputStream")
20+
S3method(message_reader,default)
1921
S3method(names,"arrow::RecordBatch")
2022
S3method(print,"arrow-enum")
2123
S3method(read_record_batch,"arrow::io::BufferReader")
@@ -52,6 +54,7 @@ S3method(write_table,fs_path)
5254
S3method(write_table,raw)
5355
export(DateUnit)
5456
export(FileMode)
57+
export(MessageType)
5558
export(StatusCode)
5659
export(TimeUnit)
5760
export(Type)
@@ -77,6 +80,7 @@ export(int32)
7780
export(int64)
7881
export(int8)
7982
export(list_of)
83+
export(message_reader)
8084
export(mmap_create)
8185
export(mmap_open)
8286
export(mock_output_stream)

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: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@
4141
)
4242
)
4343

44-
construct <- function(class, xp) {
45-
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)
4650
}
4751

4852
#' @export
@@ -67,7 +71,7 @@ construct <- function(class, xp) {
6771
DataType__num_children(self)
6872
},
6973
children = function() {
70-
map(DataType__children_pointer(self), construct, class= `arrow::Field`)
74+
map(DataType__children_pointer(self), shared_ptr, class= `arrow::Field`)
7175
},
7276
id = function(){
7377
DataType__id(self)
@@ -91,23 +95,23 @@ construct <- function(class, xp) {
9195
BINARY = stop("Type BINARY not implemented yet"),
9296
DATE32 = date32(),
9397
DATE64 = date64(),
94-
TIMESTAMP = construct(`arrow::Timestamp`,self$pointer()),
95-
TIME32 = construct(`arrow::Time32`,self$pointer()),
96-
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()),
97101
INTERVAL = stop("Type INTERVAL not implemented yet"),
98-
DECIMAL = construct(`arrow::Decimal128Type`, self$pointer()),
99-
LIST = construct(`arrow::ListType`, self$pointer()),
100-
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()),
101105
UNION = stop("Type UNION not implemented yet"),
102-
DICTIONARY = construct(`arrow::DictionaryType`, self$pointer()),
106+
DICTIONARY = shared_ptr(`arrow::DictionaryType`, self$pointer()),
103107
MAP = stop("Type MAP not implemented yet")
104108
)
105109
}
106110
)
107111
)
108112

109113
`arrow::DataType`$dispatch <- function(xp){
110-
construct(`arrow::DataType`, xp)$..dispatch()
114+
shared_ptr(`arrow::DataType`, xp)$..dispatch()
111115
}
112116

113117
#----- metadata
@@ -240,88 +244,88 @@ construct <- function(class, xp) {
240244
#'
241245
#' @rdname DataType
242246
#' @export
243-
int8 <- function() construct(`arrow::Int8`, Int8__initialize())
247+
int8 <- function() shared_ptr(`arrow::Int8`, Int8__initialize())
244248

245249
#' @rdname DataType
246250
#' @export
247-
int16 <- function() construct(`arrow::Int16`, Int16__initialize())
251+
int16 <- function() shared_ptr(`arrow::Int16`, Int16__initialize())
248252

249253
#' @rdname DataType
250254
#' @export
251-
int32 <- function() construct(`arrow::Int32`, Int32__initialize())
255+
int32 <- function() shared_ptr(`arrow::Int32`, Int32__initialize())
252256

253257
#' @rdname DataType
254258
#' @export
255-
int64 <- function() construct(`arrow::Int64`, Int64__initialize())
259+
int64 <- function() shared_ptr(`arrow::Int64`, Int64__initialize())
256260

257261
#' @rdname DataType
258262
#' @export
259-
uint8 <- function() construct(`arrow::UInt8`, UInt8__initialize())
263+
uint8 <- function() shared_ptr(`arrow::UInt8`, UInt8__initialize())
260264

261265
#' @rdname DataType
262266
#' @export
263-
uint16 <- function() construct(`arrow::UInt16`, UInt16__initialize())
267+
uint16 <- function() shared_ptr(`arrow::UInt16`, UInt16__initialize())
264268

265269
#' @rdname DataType
266270
#' @export
267-
uint32 <- function() construct(`arrow::UInt32`, UInt32__initialize())
271+
uint32 <- function() shared_ptr(`arrow::UInt32`, UInt32__initialize())
268272

269273
#' @rdname DataType
270274
#' @export
271-
uint64 <- function() construct(`arrow::UInt64`, UInt64__initialize())
275+
uint64 <- function() shared_ptr(`arrow::UInt64`, UInt64__initialize())
272276

273277
#' @rdname DataType
274278
#' @export
275-
float16 <- function() construct(`arrow::Float16`, Float16__initialize())
279+
float16 <- function() shared_ptr(`arrow::Float16`, Float16__initialize())
276280

277281
#' @rdname DataType
278282
#' @export
279-
float32 <- function() construct(`arrow::Float32`, Float32__initialize())
283+
float32 <- function() shared_ptr(`arrow::Float32`, Float32__initialize())
280284

281285
#' @rdname DataType
282286
#' @export
283-
float64 <- function() construct(`arrow::Float64`, Float64__initialize())
287+
float64 <- function() shared_ptr(`arrow::Float64`, Float64__initialize())
284288

285289
#' @rdname DataType
286290
#' @export
287-
boolean <- function() construct(`arrow::Boolean`, Boolean__initialize())
291+
boolean <- function() shared_ptr(`arrow::Boolean`, Boolean__initialize())
288292

289293
#' @rdname DataType
290294
#' @export
291-
utf8 <- function() construct(`arrow::Utf8`, Utf8__initialize())
295+
utf8 <- function() shared_ptr(`arrow::Utf8`, Utf8__initialize())
292296

293297
#' @rdname DataType
294298
#' @export
295-
date32 <- function() construct(`arrow::Date32`, Date32__initialize())
299+
date32 <- function() shared_ptr(`arrow::Date32`, Date32__initialize())
296300

297301
#' @rdname DataType
298302
#' @export
299-
date64 <- function() construct(`arrow::Date64`, Date64__initialize())
303+
date64 <- function() shared_ptr(`arrow::Date64`, Date64__initialize())
300304

301305
#' @rdname DataType
302306
#' @export
303-
time32 <- function(unit) construct(`arrow::Time32`, Time32__initialize(unit))
307+
time32 <- function(unit) shared_ptr(`arrow::Time32`, Time32__initialize(unit))
304308

305309
#' @rdname DataType
306310
#' @export
307-
time64 <- function(unit) construct(`arrow::Time64`, Time64__initialize(unit))
311+
time64 <- function(unit) shared_ptr(`arrow::Time64`, Time64__initialize(unit))
308312

309313
#' @rdname DataType
310314
#' @export
311-
null <- function() construct(`arrow::Null`, Null__initialize())
315+
null <- function() shared_ptr(`arrow::Null`, Null__initialize())
312316

313317
#' @rdname DataType
314318
#' @export
315319
timestamp <- function(unit, timezone) {
316320
if (missing(timezone)) {
317-
construct(`arrow::Timestamp`, Timestamp__initialize1(unit))
321+
shared_ptr(`arrow::Timestamp`, Timestamp__initialize1(unit))
318322
} else {
319-
construct(`arrow::Timestamp`, Timestamp__initialize2(unit, timezone))
323+
shared_ptr(`arrow::Timestamp`, Timestamp__initialize2(unit, timezone))
320324
}
321325
}
322326

323327
#' @rdname DataType
324328
#' @export
325-
decimal <- function(precision, scale) construct(`arrow::Decimal128Type`, Decimal128Type__initialize(precision, scale))
329+
decimal <- function(precision, scale) shared_ptr(`arrow::Decimal128Type`, Decimal128Type__initialize(precision, scale))
326330

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

r/R/RcppExports.R

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

r/R/RecordBatch.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@
2121
public = list(
2222
num_columns = function() RecordBatch__num_columns(self),
2323
num_rows = function() RecordBatch__num_rows(self),
24-
schema = function() construct(`arrow::Schema`, RecordBatch__schema(self)),
25-
column = function(i) construct(`arrow::Array`, RecordBatch__column(self, i)),
24+
schema = function() shared_ptr(`arrow::Schema`, RecordBatch__schema(self)),
25+
column = function(i) shared_ptr(`arrow::Array`, RecordBatch__column(self, i)),
2626
column_name = function(i) RecordBatch__column_name(self, i),
2727
names = function() RecordBatch__names(self),
2828
Equals = function(other) {
2929
assert_that(inherits(other, "arrow::RecordBatch"))
3030
RecordBatch__Equals(self, other)
3131
},
3232
RemoveColumn = function(i){
33-
construct(`arrow::RecordBatch`, RecordBatch__RemoveColumn(self, i))
33+
shared_ptr(`arrow::RecordBatch`, RecordBatch__RemoveColumn(self, i))
3434
},
3535
Slice = function(offset, length = NULL) {
3636
if (is.null(length)) {
37-
construct(`arrow::RecordBatch`, RecordBatch__Slice1(self, offset))
37+
shared_ptr(`arrow::RecordBatch`, RecordBatch__Slice1(self, offset))
3838
} else {
39-
construct(`arrow::RecordBatch`, RecordBatch__Slice2(self, offset, length))
39+
shared_ptr(`arrow::RecordBatch`, RecordBatch__Slice2(self, offset, length))
4040
}
4141
},
4242

@@ -65,5 +65,5 @@
6565
#'
6666
#' @export
6767
record_batch <- function(.data){
68-
construct(`arrow::RecordBatch`, RecordBatch__from_dataframe(.data))
68+
shared_ptr(`arrow::RecordBatch`, RecordBatch__from_dataframe(.data))
6969
}

r/R/RecordBatchReader.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
`arrow::RecordBatchReader` <- R6Class("arrow::RecordBatchReader", inherit = `arrow::Object`,
2121
public = list(
22-
schema = function() construct(`arrow::Schema`, RecordBatchReader__schema(self)),
22+
schema = function() shared_ptr(`arrow::Schema`, RecordBatchReader__schema(self)),
2323
ReadNext = function() {
24-
construct(`arrow::RecordBatch`, RecordBatchReader__ReadNext(self))
24+
shared_ptr(`arrow::RecordBatch`, RecordBatchReader__ReadNext(self))
2525
}
2626
)
2727
)
@@ -30,9 +30,9 @@
3030

3131
`arrow::ipc::RecordBatchFileReader` <- R6Class("arrow::ipc::RecordBatchFileReader", inherit = `arrow::Object`,
3232
public = list(
33-
schema = function() construct(`arrow::Schema`, ipc___RecordBatchFileReader__schema(self)),
33+
schema = function() shared_ptr(`arrow::Schema`, ipc___RecordBatchFileReader__schema(self)),
3434
num_record_batches = function() ipc___RecordBatchFileReader__num_record_batches(self),
35-
ReadRecordBatch = function(i) construct(`arrow::RecordBatch`, ipc___RecordBatchFileReader__ReadRecordBatch(self, i))
35+
ReadRecordBatch = function(i) shared_ptr(`arrow::RecordBatch`, ipc___RecordBatchFileReader__ReadRecordBatch(self, i))
3636
)
3737
)
3838

@@ -47,7 +47,7 @@ record_batch_stream_reader <- function(stream){
4747

4848
#' @export
4949
`record_batch_stream_reader.arrow::io::InputStream` <- function(stream) {
50-
construct(`arrow::ipc::RecordBatchStreamReader`, ipc___RecordBatchStreamReader__Open(stream))
50+
shared_ptr(`arrow::ipc::RecordBatchStreamReader`, ipc___RecordBatchStreamReader__Open(stream))
5151
}
5252

5353
#' @export
@@ -67,7 +67,7 @@ record_batch_file_reader <- function(file) {
6767

6868
#' @export
6969
`record_batch_file_reader.arrow::io::RandomAccessFile` <- function(file) {
70-
construct(`arrow::ipc::RecordBatchFileReader`, ipc___RecordBatchFileReader__Open(file))
70+
shared_ptr(`arrow::ipc::RecordBatchFileReader`, ipc___RecordBatchFileReader__Open(file))
7171
}
7272

7373
#' @export
@@ -166,12 +166,12 @@ read_table.fs_path <- function(stream) {
166166

167167
#' @export
168168
`read_table.arrow::ipc::RecordBatchFileReader` <- function(stream) {
169-
construct(`arrow::Table`, Table__from_RecordBatchFileReader(stream))
169+
shared_ptr(`arrow::Table`, Table__from_RecordBatchFileReader(stream))
170170
}
171171

172172
#' @export
173173
`read_table.arrow::ipc::RecordBatchStreamReader` <- function(stream) {
174-
construct(`arrow::Table`, Table__from_RecordBatchStreamReader(stream))
174+
shared_ptr(`arrow::Table`, Table__from_RecordBatchStreamReader(stream))
175175
}
176176

177177
#' @export

r/R/RecordBatchWriter.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ record_batch_file_writer <- function(stream, schema) {
4141
inherits(stream, "arrow::io::OutputStream"),
4242
inherits(schema, "arrow::Schema")
4343
)
44-
construct(`arrow::ipc::RecordBatchFileWriter`, ipc___RecordBatchFileWriter__Open(stream, schema))
44+
shared_ptr(`arrow::ipc::RecordBatchFileWriter`, ipc___RecordBatchFileWriter__Open(stream, schema))
4545
}
4646

4747
#' Create a record batch stream writer
@@ -55,7 +55,7 @@ record_batch_stream_writer <- function(stream, schema) {
5555
inherits(stream, "arrow::io::OutputStream"),
5656
inherits(schema, "arrow::Schema")
5757
)
58-
construct(`arrow::ipc::RecordBatchStreamWriter`, ipc___RecordBatchStreamWriter__Open(stream, schema))
58+
shared_ptr(`arrow::ipc::RecordBatchStreamWriter`, ipc___RecordBatchStreamWriter__Open(stream, schema))
5959
}
6060

6161
#-------- write_record_batch

0 commit comments

Comments
 (0)