Skip to content

Commit f15a700

Browse files
mapleFUpitrou
andauthored
GH-39336: [C++][Parquet] Minor: Style enhancement for parquet::FileMetaData (#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>
1 parent 96645eb commit f15a700

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

cpp/src/arrow/util/bit_stream_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class BitReader {
183183

184184
/// Returns the number of bytes left in the stream, not including the current
185185
/// byte (i.e., there may be an additional fraction of a byte).
186-
int bytes_left() {
186+
int bytes_left() const {
187187
return max_bytes_ -
188188
(byte_offset_ + static_cast<int>(bit_util::BytesForBits(bit_offset_)));
189189
}

cpp/src/parquet/metadata.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ class FileMetaData::FileMetaDataImpl {
761761
return metadata_->row_groups[i];
762762
}
763763

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

802802
metadata->row_groups.resize(row_groups.size());
803+
803804
int i = 0;
804805
for (int selected_index : row_groups) {
805806
metadata->num_rows += row_group(selected_index).num_rows;
@@ -822,7 +823,7 @@ class FileMetaData::FileMetaDataImpl {
822823
}
823824

824825
void set_file_decryptor(std::shared_ptr<InternalFileDecryptor> file_decryptor) {
825-
file_decryptor_ = file_decryptor;
826+
file_decryptor_ = std::move(file_decryptor);
826827
}
827828

828829
private:
@@ -886,13 +887,14 @@ std::shared_ptr<FileMetaData> FileMetaData::Make(
886887
const void* metadata, uint32_t* metadata_len,
887888
std::shared_ptr<InternalFileDecryptor> file_decryptor) {
888889
return std::shared_ptr<FileMetaData>(new FileMetaData(
889-
metadata, metadata_len, default_reader_properties(), file_decryptor));
890+
metadata, metadata_len, default_reader_properties(), std::move(file_decryptor)));
890891
}
891892

892893
FileMetaData::FileMetaData(const void* metadata, uint32_t* metadata_len,
893894
const ReaderProperties& properties,
894895
std::shared_ptr<InternalFileDecryptor> file_decryptor)
895-
: impl_(new FileMetaDataImpl(metadata, metadata_len, properties, file_decryptor)) {}
896+
: impl_(new FileMetaDataImpl(metadata, metadata_len, properties,
897+
std::move(file_decryptor))) {}
896898

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

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

943945
void FileMetaData::set_file_decryptor(
944946
std::shared_ptr<InternalFileDecryptor> file_decryptor) {
945-
impl_->set_file_decryptor(file_decryptor);
947+
impl_->set_file_decryptor(std::move(file_decryptor));
946948
}
947949

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

977979
void FileMetaData::AppendRowGroups(const FileMetaData& other) {
978-
impl_->AppendRowGroups(other.impl_);
980+
impl_->AppendRowGroups(other.impl_.get());
979981
}
980982

981983
std::shared_ptr<FileMetaData> FileMetaData::Subset(
@@ -1839,7 +1841,7 @@ class FileMetaDataBuilder::FileMetaDataBuilderImpl {
18391841
std::unique_ptr<FileMetaData> Finish(
18401842
const std::shared_ptr<const KeyValueMetadata>& key_value_metadata) {
18411843
int64_t total_rows = 0;
1842-
for (auto row_group : row_groups_) {
1844+
for (const auto& row_group : row_groups_) {
18431845
total_rows += row_group.num_rows;
18441846
}
18451847
metadata_->__set_num_rows(total_rows);
@@ -1858,7 +1860,7 @@ class FileMetaDataBuilder::FileMetaDataBuilderImpl {
18581860
format::KeyValue kv_pair;
18591861
kv_pair.__set_key(key_value_metadata_->key(i));
18601862
kv_pair.__set_value(key_value_metadata_->value(i));
1861-
metadata_->key_value_metadata.push_back(kv_pair);
1863+
metadata_->key_value_metadata.push_back(std::move(kv_pair));
18621864
}
18631865
metadata_->__isset.key_value_metadata = true;
18641866
}

cpp/src/parquet/metadata.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,15 @@ class PARQUET_EXPORT FileMetaData {
306306
int num_schema_elements() const;
307307

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

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

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

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

0 commit comments

Comments
 (0)