MCPcopy Create free account
hub / github.com/apache/arrow / TEST

Function TEST

cpp/src/parquet/metadata_test.cc:93–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

GenerateTableMetaDataFunction · 0.85
AssertEncodingsFunction · 0.85
ParseMetadataFunction · 0.85
SerializeMetadataFunction · 0.85
EncodeInt32Function · 0.85
AssertColumnChunkMinMaxFunction · 0.85
CreateOutputStreamFunction · 0.85
to_stringFunction · 0.85
get_data_dirFunction · 0.85
OpenFileFunction · 0.85

Tested by

no test coverage detected