| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| |
| #include "parquet/file/writer.h" |
| |
| #include "parquet/file/writer-internal.h" |
| #include "parquet/util/memory.h" |
| |
| using parquet::schema::GroupNode; |
| |
| namespace parquet { |
| |
| // ---------------------------------------------------------------------- |
| // RowGroupWriter public API |
| |
| RowGroupWriter::RowGroupWriter(std::unique_ptr<Contents> contents) |
| : contents_(std::move(contents)) {} |
| |
| void RowGroupWriter::Close() { |
| if (contents_) { |
| contents_->Close(); |
| } |
| } |
| |
| ColumnWriter* RowGroupWriter::NextColumn() { return contents_->NextColumn(); } |
| |
| int RowGroupWriter::current_column() { return contents_->current_column(); } |
| |
| int RowGroupWriter::num_columns() const { return contents_->num_columns(); } |
| |
| int64_t RowGroupWriter::num_rows() const { return contents_->num_rows(); } |
| |
| // ---------------------------------------------------------------------- |
| // ParquetFileWriter public API |
| |
| ParquetFileWriter::ParquetFileWriter() {} |
| |
| ParquetFileWriter::~ParquetFileWriter() { |
| try { |
| Close(); |
| } catch (...) { |
| } |
| } |
| |
| std::unique_ptr<ParquetFileWriter> ParquetFileWriter::Open( |
| const std::shared_ptr<::arrow::io::OutputStream>& sink, |
| const std::shared_ptr<GroupNode>& schema, |
| const std::shared_ptr<WriterProperties>& properties, |
| const std::shared_ptr<const KeyValueMetadata>& key_value_metadata) { |
| return Open(std::make_shared<ArrowOutputStream>(sink), schema, properties, |
| key_value_metadata); |
| } |
| |
| std::unique_ptr<ParquetFileWriter> ParquetFileWriter::Open( |
| const std::shared_ptr<OutputStream>& sink, |
| const std::shared_ptr<schema::GroupNode>& schema, |
| const std::shared_ptr<WriterProperties>& properties, |
| const std::shared_ptr<const KeyValueMetadata>& key_value_metadata) { |
| auto contents = FileSerializer::Open(sink, schema, properties, key_value_metadata); |
| std::unique_ptr<ParquetFileWriter> result(new ParquetFileWriter()); |
| result->Open(std::move(contents)); |
| return result; |
| } |
| |
| const SchemaDescriptor* ParquetFileWriter::schema() const { return contents_->schema(); } |
| |
| const ColumnDescriptor* ParquetFileWriter::descr(int i) const { |
| return contents_->schema()->Column(i); |
| } |
| |
| int ParquetFileWriter::num_columns() const { return contents_->num_columns(); } |
| |
| int64_t ParquetFileWriter::num_rows() const { return contents_->num_rows(); } |
| |
| int ParquetFileWriter::num_row_groups() const { return contents_->num_row_groups(); } |
| |
| const std::shared_ptr<const KeyValueMetadata>& ParquetFileWriter::key_value_metadata() |
| const { |
| return contents_->key_value_metadata(); |
| } |
| |
| void ParquetFileWriter::Open(std::unique_ptr<ParquetFileWriter::Contents> contents) { |
| contents_ = std::move(contents); |
| } |
| |
| void ParquetFileWriter::Close() { |
| if (contents_) { |
| contents_->Close(); |
| contents_.reset(); |
| } |
| } |
| |
| RowGroupWriter* ParquetFileWriter::AppendRowGroup() { |
| return contents_->AppendRowGroup(); |
| } |
| |
| RowGroupWriter* ParquetFileWriter::AppendRowGroup(int64_t num_rows) { |
| return AppendRowGroup(); |
| } |
| |
| const std::shared_ptr<WriterProperties>& ParquetFileWriter::properties() const { |
| return contents_->properties(); |
| } |
| |
| } // namespace parquet |