Skip to content

Commit

Permalink
GH-39336: [C++][Parquet] Minor: Style enhancement for parquet::FileMe…
Browse files Browse the repository at this point in the history
…taData (#39337)

### Rationale for this change

Enhance the style of `parquet::FileMetaData::Subset`.

### Are these changes tested?

Already tested

### Are there any user-facing changes?

no

* Closes: #39336

Lead-authored-by: mwish <maplewish117@gmail.com>
Co-authored-by: mwish <1506118561@qq.com>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Signed-off-by: mwish <maplewish117@gmail.com>
  • Loading branch information
3 people authored Jan 17, 2024
1 parent 96645eb commit f15a700
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cpp/src/arrow/util/bit_stream_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class BitReader {

/// Returns the number of bytes left in the stream, not including the current
/// byte (i.e., there may be an additional fraction of a byte).
int bytes_left() {
int bytes_left() const {
return max_bytes_ -
(byte_offset_ + static_cast<int>(bit_util::BytesForBits(bit_offset_)));
}
Expand Down
18 changes: 10 additions & 8 deletions cpp/src/parquet/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ class FileMetaData::FileMetaDataImpl {
return metadata_->row_groups[i];
}

void AppendRowGroups(const std::unique_ptr<FileMetaDataImpl>& other) {
void AppendRowGroups(FileMetaDataImpl* other) {
std::ostringstream diff_output;
if (!schema()->Equals(*other->schema(), &diff_output)) {
auto msg = "AppendRowGroups requires equal schemas.\n" + diff_output.str();
Expand Down Expand Up @@ -800,6 +800,7 @@ class FileMetaData::FileMetaDataImpl {
metadata->schema = metadata_->schema;

metadata->row_groups.resize(row_groups.size());

int i = 0;
for (int selected_index : row_groups) {
metadata->num_rows += row_group(selected_index).num_rows;
Expand All @@ -822,7 +823,7 @@ class FileMetaData::FileMetaDataImpl {
}

void set_file_decryptor(std::shared_ptr<InternalFileDecryptor> file_decryptor) {
file_decryptor_ = file_decryptor;
file_decryptor_ = std::move(file_decryptor);
}

private:
Expand Down Expand Up @@ -886,13 +887,14 @@ std::shared_ptr<FileMetaData> FileMetaData::Make(
const void* metadata, uint32_t* metadata_len,
std::shared_ptr<InternalFileDecryptor> file_decryptor) {
return std::shared_ptr<FileMetaData>(new FileMetaData(
metadata, metadata_len, default_reader_properties(), file_decryptor));
metadata, metadata_len, default_reader_properties(), std::move(file_decryptor)));
}

FileMetaData::FileMetaData(const void* metadata, uint32_t* metadata_len,
const ReaderProperties& properties,
std::shared_ptr<InternalFileDecryptor> file_decryptor)
: impl_(new FileMetaDataImpl(metadata, metadata_len, properties, file_decryptor)) {}
: impl_(new FileMetaDataImpl(metadata, metadata_len, properties,
std::move(file_decryptor))) {}

FileMetaData::FileMetaData() : impl_(new FileMetaDataImpl()) {}

Expand Down Expand Up @@ -942,7 +944,7 @@ const std::string& FileMetaData::footer_signing_key_metadata() const {

void FileMetaData::set_file_decryptor(
std::shared_ptr<InternalFileDecryptor> file_decryptor) {
impl_->set_file_decryptor(file_decryptor);
impl_->set_file_decryptor(std::move(file_decryptor));
}

ParquetVersion::type FileMetaData::version() const {
Expand Down Expand Up @@ -975,7 +977,7 @@ const std::shared_ptr<const KeyValueMetadata>& FileMetaData::key_value_metadata(
void FileMetaData::set_file_path(const std::string& path) { impl_->set_file_path(path); }

void FileMetaData::AppendRowGroups(const FileMetaData& other) {
impl_->AppendRowGroups(other.impl_);
impl_->AppendRowGroups(other.impl_.get());
}

std::shared_ptr<FileMetaData> FileMetaData::Subset(
Expand Down Expand Up @@ -1839,7 +1841,7 @@ class FileMetaDataBuilder::FileMetaDataBuilderImpl {
std::unique_ptr<FileMetaData> Finish(
const std::shared_ptr<const KeyValueMetadata>& key_value_metadata) {
int64_t total_rows = 0;
for (auto row_group : row_groups_) {
for (const auto& row_group : row_groups_) {
total_rows += row_group.num_rows;
}
metadata_->__set_num_rows(total_rows);
Expand All @@ -1858,7 +1860,7 @@ class FileMetaDataBuilder::FileMetaDataBuilderImpl {
format::KeyValue kv_pair;
kv_pair.__set_key(key_value_metadata_->key(i));
kv_pair.__set_value(key_value_metadata_->value(i));
metadata_->key_value_metadata.push_back(kv_pair);
metadata_->key_value_metadata.push_back(std::move(kv_pair));
}
metadata_->__isset.key_value_metadata = true;
}
Expand Down
8 changes: 7 additions & 1 deletion cpp/src/parquet/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,15 @@ class PARQUET_EXPORT FileMetaData {
int num_schema_elements() const;

/// \brief The total number of rows.
///
/// If the FileMetaData was obtained by calling `SubSet()`, this is the total
/// number of rows in the selected row groups.
int64_t num_rows() const;

/// \brief The number of row groups in the file.
///
/// If the FileMetaData was obtained by calling `SubSet()`, this is the number
/// of selected row groups.
int num_row_groups() const;

/// \brief Return the RowGroupMetaData of the corresponding row group ordinal.
Expand Down Expand Up @@ -338,7 +344,7 @@ class PARQUET_EXPORT FileMetaData {
/// \brief Size of the original thrift encoded metadata footer.
uint32_t size() const;

/// \brief Indicate if all of the FileMetadata's RowGroups can be decompressed.
/// \brief Indicate if all of the FileMetaData's RowGroups can be decompressed.
///
/// This will return false if any of the RowGroup's page is compressed with a
/// compression format which is not compiled in the current parquet library.
Expand Down

0 comments on commit f15a700

Please sign in to comment.