MCPcopy Create free account
hub / github.com/apache/arrow / InferSchemaFromDots

Function InferSchemaFromDots

r/src/table.cpp:155–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153namespace r {
154
155arrow::Status InferSchemaFromDots(SEXP lst, SEXP schema_sxp, int num_fields,
156 std::shared_ptr<arrow::Schema>& schema) {
157 // maybe a schema was given
158 if (Rf_inherits(schema_sxp, "Schema")) {
159 schema = cpp11::as_cpp<std::shared_ptr<arrow::Schema>>(schema_sxp);
160 return arrow::Status::OK();
161 }
162
163 if (!Rf_isNull(schema_sxp)) {
164 return arrow::Status::RError("`schema` must be an arrow::Schema or NULL");
165 }
166
167 // infer the schema from the `...`
168 std::vector<std::shared_ptr<arrow::Field>> fields(num_fields);
169
170 auto extract_one_field = [&fields](int j, SEXP x, std::string name) {
171 if (Rf_inherits(x, "ChunkedArray")) {
172 fields[j] = arrow::field(
173 name, cpp11::as_cpp<std::shared_ptr<arrow::ChunkedArray>>(x)->type());
174 } else if (Rf_inherits(x, "Array")) {
175 fields[j] =
176 arrow::field(name, cpp11::as_cpp<std::shared_ptr<arrow::Array>>(x)->type());
177 } else {
178 // TODO: we just need the type at this point
179 fields[j] = arrow::field(name, arrow::r::InferArrowType(x));
180 }
181 };
182 arrow::r::TraverseDots(lst, num_fields, extract_one_field);
183
184 schema = std::make_shared<arrow::Schema>(std::move(fields));
185
186 return arrow::Status::OK();
187}
188
189SEXP arrow_attributes(SEXP x, bool only_top_level) {
190 SEXP call = PROTECT(

Callers 2

RecordBatch__from_arraysFunction · 0.85
Table__from_dotsFunction · 0.85

Calls 6

RErrorFunction · 0.85
TraverseDotsFunction · 0.85
InferArrowTypeFunction · 0.70
OKFunction · 0.50
fieldFunction · 0.50
typeMethod · 0.45

Tested by

no test coverage detected