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

Method Flush

cpp/src/arrow/table_builder.cc:53–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53Result<std::shared_ptr<RecordBatch>> RecordBatchBuilder::Flush(bool reset_builders) {
54 std::vector<std::shared_ptr<Array>> fields;
55 fields.resize(this->num_fields());
56
57 int64_t length = 0;
58 for (int i = 0; i < this->num_fields(); ++i) {
59 RETURN_NOT_OK(raw_field_builders_[i]->Finish(&fields[i]));
60 if (i > 0 && fields[i]->length() != length) {
61 return Status::Invalid("All fields must be same length when calling Flush");
62 }
63 length = fields[i]->length();
64 }
65
66 // For certain types like dictionaries, types may not be fully
67 // determined before we have flushed. Make sure that the RecordBatch
68 // gets the correct types in schema.
69 // See: #ARROW-9969
70 std::vector<std::shared_ptr<Field>> schema_fields(schema_->fields());
71 for (int i = 0; i < this->num_fields(); ++i) {
72 if (!schema_fields[i]->type()->Equals(fields[i]->type())) {
73 schema_fields[i] = schema_fields[i]->WithType(fields[i]->type());
74 }
75 }
76 std::shared_ptr<Schema> schema =
77 std::make_shared<Schema>(std::move(schema_fields), schema_->metadata());
78
79 std::shared_ptr<RecordBatch> batch =
80 RecordBatch::Make(std::move(schema), length, std::move(fields));
81
82 if (reset_builders) {
83 ARROW_RETURN_NOT_OK(InitBuilders());
84 }
85
86 return batch;
87}
88
89Result<std::shared_ptr<RecordBatch>> RecordBatchBuilder::Flush() { return Flush(true); }
90

Callers

nothing calls this directly

Calls 12

FlushFunction · 0.85
resizeMethod · 0.80
WithTypeMethod · 0.80
InvalidFunction · 0.70
MakeFunction · 0.70
num_fieldsMethod · 0.45
FinishMethod · 0.45
lengthMethod · 0.45
fieldsMethod · 0.45
EqualsMethod · 0.45
typeMethod · 0.45
metadataMethod · 0.45

Tested by

no test coverage detected