Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit c26508d

Browse files
author
Artem Tarasov
committed
use PrimitiveTypedTest for the test
1 parent bdf6a2d commit c26508d

1 file changed

Lines changed: 37 additions & 56 deletions

File tree

src/parquet/column/statistics-test.cc

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,27 @@ using schema::GroupNode;
4646
namespace test {
4747

4848
template <typename TestType>
49-
class TestRowGroupStatistics : public ::testing::Test {
49+
class TestRowGroupStatistics : public PrimitiveTypedTest<TestType> {
5050
public:
5151
using T = typename TestType::c_type;
5252
using TypedStats = TypedRowGroupStatistics<TestType>;
5353

54-
void SetUp() {
55-
node_ = PrimitiveNode::Make("column", Repetition::REQUIRED, TestType::type_num,
56-
LogicalType::NONE, FLBA_LENGTH);
57-
schema_ = std::make_shared<ColumnDescriptor>(node_, 0, 0);
58-
}
59-
60-
T* GetValuesPointer(std::vector<T>&);
6154
std::vector<T> GetDeepCopy(
6255
const std::vector<T>&); // allocates new memory for FLBA/ByteArray
63-
void DeepFree(std::vector<T>&);
6456

65-
void GenerateData(int64_t num_values) {
66-
values_.resize(num_values);
67-
InitValues<T>(num_values, values_, buffer_);
68-
values_ptr_ = GetValuesPointer(values_);
69-
}
57+
T* GetValuesPointer(std::vector<T>&);
58+
void DeepFree(std::vector<T>&);
7059

7160
void TestMinMaxEncode() {
72-
GenerateData(1000);
61+
this->GenerateData(1000);
7362

74-
TypedStats statistics1(schema_.get());
75-
statistics1.Update(values_ptr_, values_.size(), 0);
63+
TypedStats statistics1(this->descr_.get());
64+
statistics1.Update(this->values_ptr_, this->values_.size(), 0);
7665
std::string encoded_min = statistics1.EncodedMin();
7766
std::string encoded_max = statistics1.EncodedMax();
7867

79-
TypedStats statistics2(schema_.get(), encoded_min, encoded_max, values_.size(), 0, 0);
68+
TypedStats statistics2(
69+
this->descr_.get(), encoded_min, encoded_max, this->values_.size(), 0, 0);
8070

8171
ASSERT_EQ(encoded_min, statistics2.EncodedMin());
8272
ASSERT_EQ(encoded_max, statistics2.EncodedMax());
@@ -85,11 +75,11 @@ class TestRowGroupStatistics : public ::testing::Test {
8575
}
8676

8777
void TestReset() {
88-
GenerateData(1000);
78+
this->GenerateData(1000);
8979

90-
TypedStats statistics(schema_.get());
91-
statistics.Update(values_ptr_, values_.size(), 0);
92-
ASSERT_EQ(values_.size(), statistics.num_values());
80+
TypedStats statistics(this->descr_.get());
81+
statistics.Update(this->values_ptr_, this->values_.size(), 0);
82+
ASSERT_EQ(this->values_.size(), statistics.num_values());
9383

9484
statistics.Reset();
9585
ASSERT_EQ(0, statistics.null_count());
@@ -102,41 +92,37 @@ class TestRowGroupStatistics : public ::testing::Test {
10292
int num_null[2];
10393
random_numbers(2, 42, 0, 100, num_null);
10494

105-
TypedStats statistics1(schema_.get());
106-
GenerateData(1000);
107-
statistics1.Update(values_ptr_, values_.size() - num_null[0], num_null[0]);
95+
TypedStats statistics1(this->descr_.get());
96+
this->GenerateData(1000);
97+
statistics1.Update(
98+
this->values_ptr_, this->values_.size() - num_null[0], num_null[0]);
10899

109-
TypedStats statistics2(schema_.get());
110-
GenerateData(1000);
111-
statistics2.Update(values_ptr_, values_.size() - num_null[1], num_null[1]);
100+
TypedStats statistics2(this->descr_.get());
101+
this->GenerateData(1000);
102+
statistics2.Update(
103+
this->values_ptr_, this->values_.size() - num_null[1], num_null[1]);
112104

113-
TypedStats total(schema_.get());
105+
TypedStats total(this->descr_.get());
114106
total.Merge(statistics1);
115107
total.Merge(statistics2);
116108

117109
ASSERT_EQ(num_null[0] + num_null[1], total.null_count());
118-
ASSERT_EQ(values_.size() * 2 - num_null[0] - num_null[1], total.num_values());
110+
ASSERT_EQ(this->values_.size() * 2 - num_null[0] - num_null[1], total.num_values());
119111
ASSERT_EQ(total.min(), std::min(statistics1.min(), statistics2.min()));
120112
ASSERT_EQ(total.max(), std::max(statistics1.max(), statistics2.max()));
121113
}
122114

123115
void TestFullRoundtrip(int64_t num_values, int64_t null_count) {
124-
auto node = PrimitiveNode::Make("column", Repetition::OPTIONAL, TestType::type_num,
125-
LogicalType::NONE, FLBA_LENGTH);
126-
auto gnode = std::static_pointer_cast<GroupNode>(
127-
GroupNode::Make("schema", Repetition::REQUIRED, std::vector<NodePtr>({node})));
128-
129-
GenerateData(num_values);
116+
this->GenerateData(num_values);
130117

131118
// compute statistics for the whole batch
132-
const int max_def_level = 1, max_rep_level = 0;
133-
const ColumnDescriptor descr(node, max_def_level, max_rep_level);
134-
TypedStats expected_stats(&descr);
135-
expected_stats.Update(values_ptr_, num_values - null_count, null_count);
119+
TypedStats expected_stats(this->descr_.get());
120+
expected_stats.Update(this->values_ptr_, num_values - null_count, null_count);
136121

137122
auto sink = std::make_shared<InMemoryOutputStream>();
123+
auto gnode = std::static_pointer_cast<GroupNode>(this->node_);
138124
std::shared_ptr<WriterProperties> writer_properties =
139-
WriterProperties::Builder().collect_statistics("schema.column")->build();
125+
WriterProperties::Builder().collect_statistics("column")->build();
140126
auto file_writer = ParquetFileWriter::Open(sink, gnode, writer_properties);
141127
auto row_group_writer = file_writer->AppendRowGroup(num_values);
142128
auto column_writer =
@@ -151,14 +137,13 @@ class TestRowGroupStatistics : public ::testing::Test {
151137
std::vector<int16_t> definition_levels(batch_null_count, 0);
152138
definition_levels.insert(
153139
definition_levels.end(), batch_num_values - batch_null_count, 1);
154-
auto beg = values_.begin() + i * num_values / 2;
140+
auto beg = this->values_.begin() + i * num_values / 2;
155141
auto end = beg + batch_num_values;
156142
std::vector<T> batch = GetDeepCopy(std::vector<T>(beg, end));
157143
T* batch_values_ptr = GetValuesPointer(batch);
158144
column_writer->WriteBatch(
159145
batch_num_values, definition_levels.data(), nullptr, batch_values_ptr);
160146
DeepFree(batch);
161-
bool_buffer_.clear();
162147
}
163148
column_writer->Close();
164149
row_group_writer->Close();
@@ -176,16 +161,6 @@ class TestRowGroupStatistics : public ::testing::Test {
176161
ASSERT_EQ(expected_stats.EncodedMin(), stats->EncodedMin());
177162
ASSERT_EQ(expected_stats.EncodedMax(), stats->EncodedMax());
178163
}
179-
180-
protected:
181-
std::vector<T> values_;
182-
std::vector<uint8_t> buffer_;
183-
std::vector<uint8_t> bool_buffer_;
184-
T* values_ptr_;
185-
186-
private:
187-
NodePtr node_;
188-
std::shared_ptr<ColumnDescriptor> schema_;
189164
};
190165

191166
template <typename TestType>
@@ -196,9 +171,11 @@ typename TestType::c_type* TestRowGroupStatistics<TestType>::GetValuesPointer(
196171

197172
template <>
198173
bool* TestRowGroupStatistics<BooleanType>::GetValuesPointer(std::vector<bool>& values) {
199-
bool_buffer_.resize(values.size());
200-
std::copy(values.begin(), values.end(), bool_buffer_.begin());
201-
return reinterpret_cast<bool*>(bool_buffer_.data());
174+
static std::vector<uint8_t> bool_buffer;
175+
bool_buffer.clear();
176+
bool_buffer.resize(values.size());
177+
std::copy(values.begin(), values.end(), bool_buffer.begin());
178+
return reinterpret_cast<bool*>(bool_buffer.data());
202179
}
203180

204181
template <typename TestType>
@@ -264,14 +241,17 @@ using TestTypes = ::testing::Types<Int32Type, Int64Type, Int96Type, FloatType, D
264241
TYPED_TEST_CASE(TestRowGroupStatistics, TestTypes);
265242

266243
TYPED_TEST(TestRowGroupStatistics, MinMaxEncode) {
244+
this->SetUpSchemaRequired();
267245
this->TestMinMaxEncode();
268246
}
269247

270248
TYPED_TEST(TestRowGroupStatistics, Reset) {
249+
this->SetUpSchemaRequired();
271250
this->TestReset();
272251
}
273252

274253
TYPED_TEST(TestRowGroupStatistics, FullRoundtrip) {
254+
this->SetUpSchemaOptional();
275255
this->TestFullRoundtrip(100, 31);
276256
this->TestFullRoundtrip(1000, 415);
277257
this->TestFullRoundtrip(10000, 926);
@@ -285,6 +265,7 @@ using NumericTypes = ::testing::Types<Int32Type, Int64Type, FloatType, DoubleTyp
285265
TYPED_TEST_CASE(TestNumericRowGroupStatistics, NumericTypes);
286266

287267
TYPED_TEST(TestNumericRowGroupStatistics, Merge) {
268+
this->SetUpSchemaOptional();
288269
this->TestMerge();
289270
}
290271

0 commit comments

Comments
 (0)