| 87 | } |
| 88 | |
| 89 | TEST(Metadata, TestBuildAccess) { |
| 90 | parquet::schema::NodeVector fields; |
| 91 | parquet::schema::NodePtr root; |
| 92 | parquet::SchemaDescriptor schema; |
| 93 | |
| 94 | WriterProperties::Builder prop_builder; |
| 95 | |
| 96 | std::shared_ptr<WriterProperties> props = |
| 97 | prop_builder.version(ParquetVersion::PARQUET_2_6)->build(); |
| 98 | |
| 99 | fields.push_back(parquet::schema::Int32("int_col", Repetition::REQUIRED)); |
| 100 | fields.push_back(parquet::schema::Float("float_col", Repetition::REQUIRED)); |
| 101 | root = parquet::schema::GroupNode::Make("schema", Repetition::REPEATED, fields); |
| 102 | schema.Init(root); |
| 103 | |
| 104 | int64_t nrows = 1000; |
| 105 | int32_t int_min = 100, int_max = 200; |
| 106 | EncodedStatistics stats_int; |
| 107 | stats_int.set_null_count(0) |
| 108 | .set_distinct_count(nrows) |
| 109 | .set_min(std::string(reinterpret_cast<const char*>(&int_min), 4)) |
| 110 | .set_max(std::string(reinterpret_cast<const char*>(&int_max), 4)); |
| 111 | EncodedStatistics stats_float; |
| 112 | float float_min = 100.100f, float_max = 200.200f; |
| 113 | stats_float.set_null_count(0) |
| 114 | .set_distinct_count(nrows) |
| 115 | .set_min(std::string(reinterpret_cast<const char*>(&float_min), 4)) |
| 116 | .set_max(std::string(reinterpret_cast<const char*>(&float_max), 4)); |
| 117 | |
| 118 | // Generate the metadata |
| 119 | auto f_accessor = GenerateTableMetaData(schema, props, nrows, stats_int, stats_float); |
| 120 | |
| 121 | std::string f_accessor_serialized_metadata = f_accessor->SerializeToString(); |
| 122 | uint32_t expected_len = static_cast<uint32_t>(f_accessor_serialized_metadata.length()); |
| 123 | |
| 124 | // decoded_len is an in-out parameter |
| 125 | uint32_t decoded_len = expected_len; |
| 126 | auto f_accessor_copy = |
| 127 | FileMetaData::Make(f_accessor_serialized_metadata.data(), &decoded_len); |
| 128 | |
| 129 | // Check that all of the serialized data is consumed |
| 130 | ASSERT_EQ(expected_len, decoded_len); |
| 131 | |
| 132 | // Run this block twice, one for f_accessor, one for f_accessor_copy. |
| 133 | // To make sure SerializedMetadata was deserialized correctly. |
| 134 | std::vector<FileMetaData*> f_accessors = {f_accessor.get(), f_accessor_copy.get()}; |
| 135 | for (int loop_index = 0; loop_index < 2; loop_index++) { |
| 136 | // file metadata |
| 137 | ASSERT_EQ(nrows, f_accessors[loop_index]->num_rows()); |
| 138 | ASSERT_LE(0, static_cast<int>(f_accessors[loop_index]->size())); |
| 139 | ASSERT_EQ(2, f_accessors[loop_index]->num_row_groups()); |
| 140 | ASSERT_EQ(ParquetVersion::PARQUET_2_6, f_accessors[loop_index]->version()); |
| 141 | ASSERT_EQ(DEFAULT_CREATED_BY, f_accessors[loop_index]->created_by()); |
| 142 | ASSERT_EQ(3, f_accessors[loop_index]->num_schema_elements()); |
| 143 | |
| 144 | // row group1 metadata |
| 145 | auto rg1_accessor = f_accessors[loop_index]->RowGroup(0); |
| 146 | ASSERT_EQ(2, rg1_accessor->num_columns()); |
nothing calls this directly
no test coverage detected