diff --git a/cpp/src/parquet/file/file-metadata-test.cc b/cpp/src/parquet/file/file-metadata-test.cc index 0c9d376860703..79e2bb1a2e948 100644 --- a/cpp/src/parquet/file/file-metadata-test.cc +++ b/cpp/src/parquet/file/file-metadata-test.cc @@ -31,7 +31,10 @@ TEST(Metadata, TestBuildAccess) { parquet::schema::NodePtr root; parquet::SchemaDescriptor schema; - std::shared_ptr props = WriterProperties::Builder().build(); + WriterProperties::Builder prop_builder; + + std::shared_ptr props = + prop_builder.version(ParquetVersion::PARQUET_2_0)->build(); fields.push_back(parquet::schema::Int32("int_col", Repetition::REQUIRED)); fields.push_back(parquet::schema::Float("float_col", Repetition::REQUIRED)); @@ -84,7 +87,7 @@ TEST(Metadata, TestBuildAccess) { ASSERT_EQ(nrows, f_accessor->num_rows()); ASSERT_LE(0, f_accessor->size()); ASSERT_EQ(2, f_accessor->num_row_groups()); - ASSERT_EQ(DEFAULT_WRITER_VERSION, f_accessor->version()); + ASSERT_EQ(ParquetVersion::PARQUET_2_0, f_accessor->version()); ASSERT_EQ(DEFAULT_CREATED_BY, f_accessor->created_by()); ASSERT_EQ(3, f_accessor->num_schema_elements()); @@ -110,8 +113,8 @@ TEST(Metadata, TestBuildAccess) { ASSERT_EQ(DEFAULT_COMPRESSION_TYPE, rg1_column2->compression()); ASSERT_EQ(nrows / 2, rg1_column1->num_values()); ASSERT_EQ(nrows / 2, rg1_column2->num_values()); - ASSERT_EQ(2, rg1_column1->encodings().size()); - ASSERT_EQ(2, rg1_column2->encodings().size()); + ASSERT_EQ(3, rg1_column1->encodings().size()); + ASSERT_EQ(3, rg1_column2->encodings().size()); ASSERT_EQ(512, rg1_column1->total_compressed_size()); ASSERT_EQ(512, rg1_column2->total_compressed_size()); ASSERT_EQ(600, rg1_column1->total_uncompressed_size()); @@ -142,8 +145,8 @@ TEST(Metadata, TestBuildAccess) { ASSERT_EQ(nrows / 2, rg2_column2->num_values()); ASSERT_EQ(DEFAULT_COMPRESSION_TYPE, rg2_column1->compression()); ASSERT_EQ(DEFAULT_COMPRESSION_TYPE, rg2_column2->compression()); - ASSERT_EQ(2, rg2_column1->encodings().size()); - ASSERT_EQ(2, rg2_column2->encodings().size()); + ASSERT_EQ(3, rg2_column1->encodings().size()); + ASSERT_EQ(3, rg2_column2->encodings().size()); ASSERT_EQ(512, rg2_column1->total_compressed_size()); ASSERT_EQ(512, rg2_column2->total_compressed_size()); ASSERT_EQ(600, rg2_column1->total_uncompressed_size()); diff --git a/cpp/src/parquet/file/metadata.cc b/cpp/src/parquet/file/metadata.cc index 2e2264904b251..a262b637c367f 100644 --- a/cpp/src/parquet/file/metadata.cc +++ b/cpp/src/parquet/file/metadata.cc @@ -358,8 +358,17 @@ int FileMetaData::num_row_groups() const { return impl_->num_row_groups(); } -int32_t FileMetaData::version() const { - return impl_->version(); +ParquetVersion::type FileMetaData::version() const { + switch (impl_->version()) { + case 1: + return ParquetVersion::PARQUET_1_0; + case 2: + return ParquetVersion::PARQUET_2_0; + default: + // Improperly set version, assuming Parquet 1.0 + break; + } + return ParquetVersion::PARQUET_1_0; } const FileMetaData::Version& FileMetaData::writer_version() const { @@ -656,7 +665,17 @@ class FileMetaDataBuilder::FileMetaDataBuilderImpl { } metadata_->__set_num_rows(total_rows); metadata_->__set_row_groups(row_groups); - metadata_->__set_version(properties_->version()); + + int32_t file_version = 0; + switch (properties_->version()) { + case ParquetVersion::PARQUET_1_0: + file_version = 1; + case ParquetVersion::PARQUET_2_0: + file_version = 2; + default: + break; + } + metadata_->__set_version(file_version); metadata_->__set_created_by(properties_->created_by()); parquet::schema::SchemaFlattener flattener( static_cast(schema_->schema_root().get()), diff --git a/cpp/src/parquet/file/metadata.h b/cpp/src/parquet/file/metadata.h index 43419d2786266..942aa39f6b52f 100644 --- a/cpp/src/parquet/file/metadata.h +++ b/cpp/src/parquet/file/metadata.h @@ -130,7 +130,7 @@ class PARQUET_EXPORT FileMetaData { int num_columns() const; int64_t num_rows() const; int num_row_groups() const; - int32_t version() const; + ParquetVersion::type version() const; const std::string& created_by() const; int num_schema_elements() const; std::unique_ptr RowGroup(int i) const;