Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fields to Parquet Statistics structure that were added in parquet-format 2.10 #15412

Merged
merged 20 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cpp/src/io/parquet/compact_protocol_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,13 +746,16 @@ void CompactProtocolReader::read(Statistics* s)
{
using optional_binary = parquet_field_optional<std::vector<uint8_t>, parquet_field_binary>;
using optional_int64 = parquet_field_optional<int64_t, parquet_field_int64>;
using optional_bool = parquet_field_optional<bool, parquet_field_bool>;

auto op = std::make_tuple(optional_binary(1, s->max),
optional_binary(2, s->min),
optional_int64(3, s->null_count),
optional_int64(4, s->distinct_count),
optional_binary(5, s->max_value),
optional_binary(6, s->min_value));
optional_binary(6, s->min_value),
optional_bool(7, s->is_max_value_exact),
optional_bool(8, s->is_min_value_exact));
function_builder(this, op);
}

Expand Down
2 changes: 2 additions & 0 deletions cpp/src/io/parquet/compact_protocol_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ size_t CompactProtocolWriter::write(Statistics const& s)
if (s.distinct_count.has_value()) { c.field_int(4, s.distinct_count.value()); }
if (s.max_value.has_value()) { c.field_binary(5, s.max_value.value()); }
if (s.min_value.has_value()) { c.field_binary(6, s.min_value.value()); }
if (s.is_max_value_exact.has_value()) { c.field_bool(7, s.is_max_value_exact.value()); }
if (s.is_min_value_exact.has_value()) { c.field_bool(8, s.is_min_value_exact.value()); }
return c.value();
}

Expand Down
3 changes: 3 additions & 0 deletions cpp/src/io/parquet/page_enc.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2926,6 +2926,9 @@ __device__ uint8_t* EncodeStatistics(uint8_t* start,
auto const [min_ptr, min_size] =
get_extremum(&s->min_value, dtype, scratch, true, NO_TRUNC_STATS);
encoder.field_binary(6, min_ptr, min_size);
// cudf min/max statistics are always exact (i.e. not truncated)
encoder.field_bool(7, true);
encoder.field_bool(8, true);
Comment on lines +2947 to +2949
Copy link
Contributor

@karthikeyann karthikeyann Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can both of these fields be present (as true) even if the stats does not have min and max value?
I hope, other parquet readers don't break if this is true when min and max values are missing in stats.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...good point. As currently written, the stats encoding will always write something in the min and max fields if s->has_minmax is true, so I think it's safe to always set the exact fields to true here.

That said, the rules around when min/max should have values encoded and not have been in flux (and as with everything Parquet, are not well documented), so it would probably be a good idea to make sure we're following all of the rules properly. I'm not sure if that's in scope for this PR or should be a separate issue.

}
encoder.end(&end);
return end;
Expand Down
6 changes: 5 additions & 1 deletion cpp/src/io/parquet/parquet.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION.
* Copyright (c) 2018-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -259,6 +259,10 @@ struct Statistics {
thrust::optional<std::vector<uint8_t>> max_value;
// min value for column determined by ColumnOrder
thrust::optional<std::vector<uint8_t>> min_value;
// If true, max_value is the actual maximum value for a column
thrust::optional<bool> is_max_value_exact;
// If true, min_value is the actual minimum value for a column
thrust::optional<bool> is_min_value_exact;
};

/**
Expand Down
6 changes: 6 additions & 0 deletions cpp/tests/io/parquet_writer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,12 @@ TEST_F(ParquetWriterTest, CheckColumnIndexTruncation)
ASSERT_TRUE(stats.min_value.has_value());
ASSERT_TRUE(stats.max_value.has_value());

// check that min and max for the column chunk are exact (i.e. not truncated)
ASSERT_TRUE(stats.is_max_value_exact.has_value());
EXPECT_TRUE(stats.is_max_value_exact.value());
ASSERT_TRUE(stats.is_min_value_exact.has_value());
EXPECT_TRUE(stats.is_min_value_exact.value());

// check trunc(page.min) <= stats.min && trun(page.max) >= stats.max
auto const ptype = fmd.schema[c + 1].type;
auto const ctype = fmd.schema[c + 1].converted_type;
Expand Down
Loading