Skip to content

Commit b8dac54

Browse files
+RecordBatch$schema
1 parent 1fc3cc2 commit b8dac54

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

r/R/R6.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,12 @@ field <- function(name, type) `arrow::Field`$new(name, type)
522522
print = function(...) {
523523
cat( glue( "{s}", s = Schema_ToString(self)))
524524
},
525-
initialize = function(...){
526-
self$set_pointer(schema_(.fields(list(...))))
525+
initialize = function(..., .xp){
526+
if(missing(.xp)){
527+
self$set_pointer(schema_(.fields(list(...))))
528+
} else {
529+
self$set_pointer(.xp)
530+
}
527531
}
528532
)
529533
)

r/R/RcppExports.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ RecordBatch_num_rows <- function(x) {
8181
.Call(`_arrow_RecordBatch_num_rows`, x)
8282
}
8383

84+
RecordBatch_schema <- function(x) {
85+
.Call(`_arrow_RecordBatch_schema`, x)
86+
}
87+
8488
Field_initialize <- function(name, type, nullable = TRUE) {
8589
.Call(`_arrow_Field_initialize`, name, type, nullable)
8690
}

r/R/array.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ array <- function(...){
9393
self$set_pointer(dataframe_to_RecordBatch(.data))
9494
},
9595
num_columns = function() RecordBatch_num_columns(self),
96-
num_rows = function() RecordBatch_num_rows(self)
96+
num_rows = function() RecordBatch_num_rows(self),
97+
schema = function() schema(.xp = RecordBatch_schema(self))
9798
)
9899
)
99100

r/src/RcppExports.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,17 @@ BEGIN_RCPP
233233
return rcpp_result_gen;
234234
END_RCPP
235235
}
236+
// RecordBatch_schema
237+
std::shared_ptr<arrow::Schema> RecordBatch_schema(const std::shared_ptr<arrow::RecordBatch>& x);
238+
RcppExport SEXP _arrow_RecordBatch_schema(SEXP xSEXP) {
239+
BEGIN_RCPP
240+
Rcpp::RObject rcpp_result_gen;
241+
Rcpp::RNGScope rcpp_rngScope_gen;
242+
Rcpp::traits::input_parameter< const std::shared_ptr<arrow::RecordBatch>& >::type x(xSEXP);
243+
rcpp_result_gen = Rcpp::wrap(RecordBatch_schema(x));
244+
return rcpp_result_gen;
245+
END_RCPP
246+
}
236247
// Field_initialize
237248
std::shared_ptr<arrow::Field> Field_initialize(const std::string& name, const std::shared_ptr<arrow::DataType>& type, bool nullable);
238249
RcppExport SEXP _arrow_Field_initialize(SEXP nameSEXP, SEXP typeSEXP, SEXP nullableSEXP) {
@@ -1538,6 +1549,7 @@ static const R_CallMethodDef CallEntries[] = {
15381549
{"_arrow_dataframe_to_RecordBatch", (DL_FUNC) &_arrow_dataframe_to_RecordBatch, 1},
15391550
{"_arrow_RecordBatch_num_columns", (DL_FUNC) &_arrow_RecordBatch_num_columns, 1},
15401551
{"_arrow_RecordBatch_num_rows", (DL_FUNC) &_arrow_RecordBatch_num_rows, 1},
1552+
{"_arrow_RecordBatch_schema", (DL_FUNC) &_arrow_RecordBatch_schema, 1},
15411553
{"_arrow_Field_initialize", (DL_FUNC) &_arrow_Field_initialize, 3},
15421554
{"_arrow_Field_ToString", (DL_FUNC) &_arrow_Field_ToString, 1},
15431555
{"_arrow_Field_name", (DL_FUNC) &_arrow_Field_name, 1},

r/src/buffer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,8 @@ int RecordBatch_num_columns(const std::shared_ptr<arrow::RecordBatch>& x){
106106
int RecordBatch_num_rows(const std::shared_ptr<arrow::RecordBatch>& x){
107107
return x->num_rows();
108108
}
109+
110+
// [[Rcpp::export]]
111+
std::shared_ptr<arrow::Schema> RecordBatch_schema(const std::shared_ptr<arrow::RecordBatch>& x){
112+
return x->schema();
113+
}

0 commit comments

Comments
 (0)