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

Method WriteTable

cpp/src/parquet/arrow/writer.cc:394–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

392 std::shared_ptr<::arrow::Schema> schema() const override { return schema_; }
393
394 Status WriteTable(const Table& table, int64_t chunk_size) override {
395 RETURN_NOT_OK(CheckClosed());
396 RETURN_NOT_OK(table.Validate());
397
398 if (chunk_size <= 0 && table.num_rows() > 0) {
399 return Status::Invalid("chunk size per row_group must be greater than 0");
400 } else if (!table.schema()->Equals(*schema_, false)) {
401 return Status::Invalid("table schema does not match this writer's. table:'",
402 table.schema()->ToString(), "' this:'", schema_->ToString(),
403 "'");
404 } else if (chunk_size > this->properties().max_row_group_length()) {
405 chunk_size = this->properties().max_row_group_length();
406 }
407
408 auto WriteRowGroup = [&](int64_t offset, int64_t size) {
409 RETURN_NOT_OK(NewRowGroup());
410 for (int i = 0; i < table.num_columns(); i++) {
411 RETURN_NOT_OK(WriteColumnChunk(table.column(i), offset, size));
412 }
413 return Status::OK();
414 };
415
416 if (table.num_rows() == 0) {
417 // Append a row group with 0 rows
418 RETURN_NOT_OK(
419 WriteRowGroup(0, 0).OrElse([&](auto&&) { PARQUET_IGNORE_NOT_OK(Close()); }));
420 }
421
422 for (int chunk = 0; chunk * chunk_size < table.num_rows(); chunk++) {
423 int64_t offset = chunk * chunk_size;
424 RETURN_NOT_OK(WriteRowGroup(offset, std::min(chunk_size, table.num_rows() - offset))
425 .OrElse([&](auto&&) { PARQUET_IGNORE_NOT_OK(Close()); }));
426 }
427 return Status::OK();
428 }
429
430 Status NewBufferedRowGroup() override {
431 RETURN_NOT_OK(CheckClosed());

Callers 8

WriteFileMethod · 0.45
TESTFunction · 0.45
TEST_PFunction · 0.45
WriteFileMethod · 0.45
TEST_FFunction · 0.45
TEST_PFunction · 0.45
TESTFunction · 0.45
WriteTableFunction · 0.45

Calls 12

CheckClosedFunction · 0.50
InvalidFunction · 0.50
OKFunction · 0.50
CloseFunction · 0.50
ValidateMethod · 0.45
num_rowsMethod · 0.45
EqualsMethod · 0.45
schemaMethod · 0.45
ToStringMethod · 0.45
propertiesMethod · 0.45
num_columnsMethod · 0.45
columnMethod · 0.45

Tested by 7

WriteFileMethod · 0.36
TESTFunction · 0.36
TEST_PFunction · 0.36
WriteFileMethod · 0.36
TEST_FFunction · 0.36
TEST_PFunction · 0.36
TESTFunction · 0.36