This is an automated email from the ASF dual-hosted git repository.
suxiaogang223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 2b3344209fa [opt](parquet) Use terminal residuals to prune nested
Variant paths (#71337)
2b3344209fa is described below
commit 2b3344209fa4f377cfacdd1683e8f8a23529d162
Author: Socrates <[email protected]>
AuthorDate: Fri Dec 4 15:29:20 2026 +0800
[opt](parquet) Use terminal residuals to prune nested Variant paths (#71337)
### Background
A shredded Parquet Variant stores selected fields in typed columns and
the remaining values in residual columns. Doris can use the typed leaf's
footer statistics and page index to skip data when its residual cannot
supply a matching value.
### What problem does this PR solve?
Issue Number: None
Related PR: #66413 (typed statistics guards), #66575 (deep leaf
projection), #69016 (deep leaf projection backport)
PR Type: Performance
Problem Summary:
Predicates on nested shredded fields miss row-group and page pruning
when an ancestor residual contains sibling keys outside the predicate's
path. Use the terminal residual to decide whether the typed leaf can
supply all values for the predicate. Most of the diff adds metadata
cases and a real-file reader test.
### Details
- **Change map:** 26 changed lines in Parquet statistics (9 added, 17
removed) and 276 in tests (233 added, 43 removed). The tests cover the
metadata decision at both pruning levels and compare native reader
output on a file with a populated ancestor residual.
- **Why it was slow:** Both pruning paths required every residual along
the path to be all NULL. A partially shredded object often keeps
unrelated keys in an ancestor residual, making that requirement fail
even when the scalar leaf is fully shredded.
- **Optimization:** Apply the existing row-group null-count proof to the
terminal residual for both pruning paths. Parquet's shredded object
format keeps keys represented in `typed_value` out of the corresponding
object's residual.
- **Results:** The Fedora ASAN native reader scanned a real 128-row
Parquet file with two row groups and evaluated `v.a.b > 95`. With
metadata pruning disabled, the Profile recorded zero row groups and zero
rows pruned by page index. With pruning enabled, the Profile recorded
one row group pruned by min/max and rows skipped by page index in the
surviving group. Both full Variant reads and leaf-only projections
returned the same 32 rows (IDs 96–127) in both modes. The comparison
measures pruning counters and result equality.
- **Applicability and cost:** This applies to supported scalar paths
whose terminal residual is proven all NULL for the row group. A
populated terminal residual or missing null count keeps the candidate
data. Both paths reuse the existing metadata and require no additional
reads or configuration.
### Testing
- Fedora ASAN BE: `./run-be-ut.sh --run -j 8 --filter
'NativeParquetStatisticsTest.*:NewParquetReaderTest.*'` passed all 109
tests (20 statistics and 89 reader tests). The test target was scoped to
the two suites and their shared test support.
- `ShreddedVariantPruningUsesOnlyTerminalFallback` covers row-group and
page exclusion with a populated ancestor residual, plus retention when
the terminal residual has a value or its null count is absent.
- `PrunesNestedVariantWithNonEmptyAncestorResidual` writes the Parquet
fixture with real page indexes, compares every returned ID and Variant
value with pruning enabled and disabled, and verifies pruning and leaf
projection via Profile counters.
- Clang-format 16, build hygiene, diff whitespace checks, and clang-tidy
on changed lines passed.
### Release note
Nested Parquet Variant predicates can skip more row groups and pages
when ancestor objects have unrelated residual fields.
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Ready
### AI Disclosure
- Tool: OpenAI Codex (GPT-6)
- Generated: Implementation, tests, verification, and PR description.
- Human review: The author approved the design. Implementation review
was not stated.
---
be/src/format_v2/parquet/parquet_statistics.cpp | 26 +--
be/test/format_v2/parquet/parquet_reader_test.cpp | 209 +++++++++++++++++++--
.../format_v2/parquet/parquet_statistics_test.cpp | 67 ++++---
3 files changed, 242 insertions(+), 60 deletions(-)
diff --git a/be/src/format_v2/parquet/parquet_statistics.cpp
b/be/src/format_v2/parquet/parquet_statistics.cpp
index 478bbbce026..4e51fd6fc44 100644
--- a/be/src/format_v2/parquet/parquet_statistics.cpp
+++ b/be/src/format_v2/parquet/parquet_statistics.cpp
@@ -751,7 +751,7 @@ const ParquetColumnSchema* child_named(const
ParquetColumnSchema& parent, std::s
}
struct ResolvedVariantShredding {
- std::vector<const ParquetColumnSchema*> fallback_values;
+ const ParquetColumnSchema* fallback_value = nullptr;
const ParquetColumnSchema* typed_value = nullptr;
};
@@ -853,7 +853,7 @@ std::optional<ResolvedVariantShredding>
resolve_variant_shredding(
if (wrapper == nullptr || wrapper->kind !=
ParquetColumnSchemaKind::VARIANT) {
return std::nullopt;
}
- std::vector<const ParquetColumnSchema*> fallbacks;
+ const ParquetColumnSchema* fallback = nullptr;
for (const auto& component : predicate.path) {
const auto* typed_object = child_named(*wrapper, "typed_value");
if (typed_object == nullptr || typed_object->kind !=
ParquetColumnSchemaKind::STRUCT) {
@@ -863,19 +863,18 @@ std::optional<ResolvedVariantShredding>
resolve_variant_shredding(
if (wrapper == nullptr || wrapper->kind !=
ParquetColumnSchemaKind::STRUCT) {
return std::nullopt;
}
- const auto* fallback = child_named(*wrapper, "value");
+ fallback = child_named(*wrapper, "value");
if (fallback == nullptr || fallback->kind !=
ParquetColumnSchemaKind::PRIMITIVE) {
return std::nullopt;
}
- // A residual at any wrapper can contribute to the descendant path, so
deepest-leaf
- // bounds are safe only when every fallback encountered during descent
is absent.
- fallbacks.push_back(fallback);
}
+ // A shredded object's residual cannot contain keys represented by its
typed_value fields.
+ // Only the terminal wrapper's residual can supply the requested leaf.
const auto* typed = child_named(*wrapper, "typed_value");
const auto typed_primitive = typed == nullptr || typed->type == nullptr
? INVALID_TYPE
:
remove_nullable(typed->type)->get_primitive_type();
- if (fallbacks.empty() || typed == nullptr ||
+ if (fallback == nullptr || typed == nullptr ||
typed->kind != ParquetColumnSchemaKind::PRIMITIVE ||
typed->max_repetition_level != 0 ||
// Parquet float statistics do not prove that a page contains no NaN.
Min/max pruning in
// the presence of NaN is not order preserving, so keep those pages
until such proof exists.
@@ -884,7 +883,7 @@ std::optional<ResolvedVariantShredding>
resolve_variant_shredding(
!expr_zonemap::data_types_compatible(predicate.comparison_type,
predicate.literal_type)) {
return std::nullopt;
}
- return ResolvedVariantShredding {.fallback_values = std::move(fallbacks),
.typed_value = typed};
+ return ResolvedVariantShredding {.fallback_value = fallback, .typed_value
= typed};
}
bool fallback_is_all_null(const tparquet::RowGroup& row_group,
@@ -900,13 +899,6 @@ bool fallback_is_all_null(const tparquet::RowGroup&
row_group,
chunk.meta_data.statistics.null_count == chunk.meta_data.num_values;
}
-bool fallbacks_are_all_null(const tparquet::RowGroup& row_group,
- const std::vector<const ParquetColumnSchema*>&
fallbacks) {
- return std::ranges::all_of(fallbacks, [&](const auto* fallback) {
- return fallback != nullptr && fallback_is_all_null(row_group,
*fallback);
- });
-}
-
bool variant_statistics_exclude(const VariantShreddedPredicate& predicate,
const ParquetColumnStatistics& statistics) {
if (!statistics.has_any_statistics()) {
@@ -1299,7 +1291,7 @@ bool check_shredded_variant_statistics(
const auto shredding = resolve_variant_shredding(file_schema, request,
*predicate);
if (!shredding.has_value() || shredding->typed_value->leaf_column_id <
0 ||
shredding->typed_value->leaf_column_id >=
static_cast<int>(row_group.columns.size()) ||
- !fallbacks_are_all_null(row_group, shredding->fallback_values) ||
+ !fallback_is_all_null(row_group, *shredding->fallback_value) ||
!variant_metadata_predicate_is_type_safe(*shredding->typed_value)
||
!detail::has_supported_type_defined_order(metadata,
shredding->typed_value->leaf_column_id)) {
@@ -2325,7 +2317,7 @@ Status select_row_group_ranges_by_native_page_index(
}
const auto shredding = resolve_variant_shredding(file_schema, request,
*predicate);
if (!shredding.has_value() || shredding->typed_value->leaf_column_id <
0 ||
- !fallbacks_are_all_null(row_group, shredding->fallback_values) ||
+ !fallback_is_all_null(row_group, *shredding->fallback_value) ||
!variant_metadata_predicate_is_type_safe(*shredding->typed_value)
||
!detail::has_supported_type_defined_order(metadata,
shredding->typed_value->leaf_column_id)) {
diff --git a/be/test/format_v2/parquet/parquet_reader_test.cpp
b/be/test/format_v2/parquet/parquet_reader_test.cpp
index 3968dadfdca..df2984d5e27 100644
--- a/be/test/format_v2/parquet/parquet_reader_test.cpp
+++ b/be/test/format_v2/parquet/parquet_reader_test.cpp
@@ -328,11 +328,11 @@ private:
class VariantInt32PathGreaterThanExpr final : public VariantPathMetadataExpr {
public:
- VariantInt32PathGreaterThanExpr(int column_id, std::string key, int32_t
value)
+ VariantInt32PathGreaterThanExpr(int column_id, std::vector<std::string>
keys, int32_t value)
: VariantPathMetadataExpr("gt", std::make_shared<DataTypeUInt8>(),
TExprNodeType::BINARY_PRED),
_column_id(column_id),
- _key(std::move(key)),
+ _keys(std::move(keys)),
_value(value) {}
Status execute_column_impl(VExprContext*, const Block* block, const
Selector* selector,
@@ -340,8 +340,11 @@ public:
const auto& nullable =
assert_cast<const
ColumnNullable&>(*block->get_by_position(_column_id).column);
const auto& variants = assert_cast<const
ColumnVariantV2&>(nullable.get_nested_column());
- const std::array path {VariantShreddedPathSegment {
- .kind = VariantShreddedPathSegment::Kind::OBJECT_KEY, .key =
StringRef(_key)}};
+ std::vector<VariantShreddedPathSegment> path;
+ for (const auto& key : _keys) {
+ path.push_back(
+ {.kind = VariantShreddedPathSegment::Kind::OBJECT_KEY,
.key = StringRef(key)});
+ }
const auto typed = variants.find_shredded_typed_value(path);
if (!typed.has_value()) {
return Status::InternalError("Expected the projected Variant typed
leaf");
@@ -363,26 +366,28 @@ public:
private:
int _column_id;
- std::string _key;
+ std::vector<std::string> _keys;
int32_t _value;
};
-VExprContextSPtr create_variant_int32_path_greater_than_conjunct(int
column_id, std::string key,
+VExprContextSPtr create_variant_int32_path_greater_than_conjunct(int column_id,
+
std::vector<std::string> keys,
int32_t
value) {
- auto slot = VSlotRef::create_shared(0, column_id, -1,
-
make_nullable(std::make_shared<DataTypeVariantV2>()), "v");
- auto key_literal =
VLiteral::create_shared(std::make_shared<DataTypeString>(),
-
Field::create_field<TYPE_STRING>(key));
- auto element_at = std::make_shared<VariantPathMetadataExpr>(
- "element_at",
make_nullable(std::make_shared<DataTypeVariantV2>()));
- element_at->add_child(slot);
- element_at->add_child(key_literal);
+ const auto variant_type =
make_nullable(std::make_shared<DataTypeVariantV2>());
+ VExprSPtr path = VSlotRef::create_shared(0, column_id, -1, variant_type,
"v");
+ for (const auto& key : keys) {
+ auto element_at =
std::make_shared<VariantPathMetadataExpr>("element_at", variant_type);
+ element_at->add_child(path);
+
element_at->add_child(VLiteral::create_shared(std::make_shared<DataTypeString>(),
+
Field::create_field<TYPE_STRING>(key)));
+ path = std::move(element_at);
+ }
auto cast = std::make_shared<VariantPathMetadataExpr>(
"CAST", make_nullable(std::make_shared<DataTypeInt32>()),
TExprNodeType::CAST_EXPR);
- cast->add_child(element_at);
+ cast->add_child(path);
auto literal = VLiteral::create_shared(std::make_shared<DataTypeInt32>(),
Field::create_field<TYPE_INT>(value));
- auto gt = std::make_shared<VariantInt32PathGreaterThanExpr>(column_id,
std::move(key), value);
+ auto gt = std::make_shared<VariantInt32PathGreaterThanExpr>(column_id,
std::move(keys), value);
gt->add_child(cast);
gt->add_child(literal);
return VExprContext::create_shared(std::move(gt));
@@ -1086,6 +1091,57 @@ void write_mixed_variant_row_groups(const std::string&
file_path) {
annotate_variant_schema(file_path);
}
+void write_nested_variant_pruning_file(const std::string& file_path) {
+ constexpr int64_t row_count = 128;
+ std::vector<int32_t> ids(row_count);
+ std::iota(ids.begin(), ids.end(), 0);
+ arrow::BinaryBuilder null_builder;
+ ASSERT_TRUE(null_builder.AppendNulls(row_count).ok());
+ const auto nulls = finish_array(&null_builder);
+ auto make_struct = [&](const arrow::FieldVector& fields, const
arrow::ArrayVector& arrays) {
+ return std::make_shared<arrow::StructArray>(arrow::struct_(fields),
row_count, arrays);
+ };
+
+ // The metadata dictionary contains a, b and extra. a.value encodes
{"extra":"x"}.
+ const std::string metadata(
+ "\x11\x03\x00\x01\x02\x07"
+ "abextra",
+ 13);
+ const std::string residual("\x02\x01\x02\x00\x02\x05x", 7);
+ auto b = make_struct(
+ {arrow::field("value", arrow::binary()),
arrow::field("typed_value", arrow::int32())},
+ {nulls, build_int32_array(ids)});
+ auto a_typed = make_struct({arrow::field("b", b->type(), false)}, {b});
+ auto a = make_struct(
+ {arrow::field("value", arrow::binary()),
arrow::field("typed_value", a_typed->type())},
+ {build_binary_array(std::vector<std::string>(row_count,
residual)), a_typed});
+ auto root_typed = make_struct({arrow::field("a", a->type(), false)}, {a});
+ auto variant = make_struct(
+ {arrow::field("metadata", arrow::binary(), false),
+ arrow::field("value", arrow::binary()),
+ arrow::field("typed_value", root_typed->type())},
+ {build_binary_array(std::vector<std::string>(row_count,
metadata)), nulls, root_typed});
+ auto schema = arrow::schema(
+ {arrow::field("id", arrow::int32(), false), arrow::field("v",
variant->type(), false)});
+ auto table = arrow::Table::Make(schema, {build_int32_array(ids), variant});
+
+ auto file_result = arrow::io::FileOutputStream::Open(file_path);
+ ASSERT_TRUE(file_result.ok()) << file_result.status();
+ auto out = *file_result;
+ ::parquet::WriterProperties::Builder properties;
+ properties.version(::parquet::ParquetVersion::PARQUET_2_6);
+ properties.data_page_version(::parquet::ParquetDataPageVersion::V2);
+ properties.compression(::parquet::Compression::UNCOMPRESSED);
+ properties.disable_dictionary();
+ properties.enable_write_page_index();
+ properties.write_batch_size(8);
+ properties.data_pagesize(10);
+ PARQUET_THROW_NOT_OK(::parquet::arrow::WriteTable(*table,
arrow::default_memory_pool(), out, 64,
+ properties.build()));
+ ASSERT_TRUE(out->Close().ok());
+ annotate_variant_schema(file_path);
+}
+
void write_unannotated_binary_parquet_file(const std::string& file_path) {
auto schema = arrow::schema({arrow::field("raw_bytes", arrow::binary(),
false)});
auto table = arrow::Table::Make(schema, {build_binary_array({"否", "是",
"测试"})});
@@ -3515,7 +3571,7 @@ TEST_F(NewParquetReaderTest,
ShreddedVariantPredicateUsesTypedLeafPageIndexWithR
format::LocalIndex(0));
request->local_positions.emplace(format::LocalColumnId(schema[1].local_id),
format::LocalIndex(1));
-
request->conjuncts.push_back(create_variant_int32_path_greater_than_conjunct(1,
"n", 3000));
+
request->conjuncts.push_back(create_variant_int32_path_greater_than_conjunct(1,
{"n"}, 3000));
ASSERT_TRUE(reader->open(request).ok());
size_t rows = 0;
@@ -3545,6 +3601,123 @@ TEST_F(NewParquetReaderTest,
ShreddedVariantPredicateUsesTypedLeafPageIndexWithR
EXPECT_GT(profile.get_counter("VariantReconstructionTime")->value(), 0);
}
+TEST_F(NewParquetReaderTest, PrunesNestedVariantWithNonEmptyAncestorResidual) {
+ _file_path = (_test_dir / "nested_variant_pruning.parquet").string();
+ ASSERT_NO_FATAL_FAILURE(write_nested_variant_pruning_file(_file_path));
+
+ using Row = std::pair<int32_t, std::string>;
+ auto scan = [&](bool narrow, bool pruning, std::vector<Row>* result) {
+ SCOPED_TRACE(pruning);
+ RuntimeProfile profile("nested_variant_pruning");
+ RuntimeState state {TQueryOptions(), TQueryGlobals()};
+ auto reader = create_reader(0, -1, &profile);
+ ASSERT_TRUE(reader->init(&state).ok());
+ std::vector<format::ColumnDefinition> schema;
+ ASSERT_TRUE(reader->get_schema(&schema).ok());
+ ASSERT_EQ(schema.size(), 2);
+
+ auto request = std::make_shared<format::FileScanRequest>();
+ request->non_predicate_columns.push_back(
+
format::LocalColumnIndex::top_level(format::LocalColumnId(schema[0].local_id)));
+ auto projection =
+
format::LocalColumnIndex::top_level(format::LocalColumnId(schema[1].local_id));
+ if (narrow) {
+ projection =
format::LocalColumnIndex::partial_local(schema[1].local_id);
+ const format::ColumnDefinition* field = &schema[1];
+ auto* projected = &projection;
+ for (std::string_view name : {"typed_value", "a", "typed_value",
"b"}) {
+ const auto child =
+ std::ranges::find(field->children, name,
&format::ColumnDefinition::name);
+ ASSERT_NE(child, field->children.end());
+ field = &*child;
+ projected->children.push_back(
+
format::LocalColumnIndex::partial_local(field->local_id));
+ projected = &projected->children.back();
+ }
+ const auto typed = std::ranges::find(field->children,
"typed_value",
+
&format::ColumnDefinition::name);
+ ASSERT_NE(typed, field->children.end());
+
projected->children.push_back(format::LocalColumnIndex::local(typed->local_id));
+ }
+ request->predicate_columns.push_back(std::move(projection));
+
request->local_positions.emplace(format::LocalColumnId(schema[0].local_id),
+ format::LocalIndex(0));
+
request->local_positions.emplace(format::LocalColumnId(schema[1].local_id),
+ format::LocalIndex(1));
+ request->conjuncts.push_back(
+ create_variant_int32_path_greater_than_conjunct(1, {"a", "b"},
95));
+ request->metadata_pruning_safe_conjunct_count = pruning ? 1 : 0;
+ ASSERT_TRUE(reader->open(request).ok());
+
+ const std::array path {
+ VariantShreddedPathSegment {.kind =
VariantShreddedPathSegment::Kind::OBJECT_KEY,
+ .key = StringRef("a")},
+ VariantShreddedPathSegment {.kind =
VariantShreddedPathSegment::Kind::OBJECT_KEY,
+ .key = StringRef("b")}};
+ const auto serde = schema[1].type->get_serde();
+ auto options = DataTypeSerDe::get_default_format_options();
+ bool eof = false;
+ while (!eof) {
+ Block block = build_file_block(schema);
+ size_t rows = 0;
+ ASSERT_TRUE(reader->get_block(&block, &rows, &eof).ok());
+ if (rows == 0) {
+ continue;
+ }
+ const auto ids = remove_nullable(block.get_by_position(0).column);
+ const auto& values = *block.get_by_position(1).column;
+ if (narrow) {
+ const auto& variants = assert_cast<const ColumnVariantV2&>(
+ assert_cast<const
ColumnNullable&>(values).get_nested_column());
+ const auto leaf = variants.find_shredded_typed_value(path);
+ ASSERT_TRUE(leaf.has_value());
+ const auto typed = remove_nullable(leaf->column);
+ for (size_t row = 0; row < rows; ++row) {
+ ASSERT_FALSE(leaf->column->is_null_at(row));
+ result->emplace_back(ids->get_int(row),
std::to_string(typed->get_int(row)));
+ }
+ } else {
+ auto serialized = ColumnString::create();
+ BufferWritable writer(*serialized);
+ for (size_t row = 0; row < rows; ++row) {
+ ASSERT_TRUE(
+ serde->serialize_one_cell_to_json(values, row,
writer, options).ok());
+ writer.commit();
+ result->emplace_back(ids->get_int(row),
+
serialized->get_data_at(row).to_string());
+ }
+ }
+ }
+ const auto* row_groups =
profile.get_counter("RowGroupsFilteredByMinMax");
+ const auto* page_rows = profile.get_counter("FilteredRowsByPage");
+ const auto* leaf_groups =
profile.get_counter("VariantLeafProjectionRowGroupColumns");
+ ASSERT_NE(row_groups, nullptr);
+ ASSERT_NE(page_rows, nullptr);
+ ASSERT_NE(leaf_groups, nullptr);
+ const int expected_pruned_groups = pruning ? 1 : 0;
+ EXPECT_EQ(row_groups->value(), expected_pruned_groups);
+ EXPECT_EQ(page_rows->value() > 0, pruning);
+ EXPECT_EQ(leaf_groups->value(), narrow ? 2 - expected_pruned_groups :
0);
+ };
+
+ for (bool narrow : {false, true}) {
+ SCOPED_TRACE(narrow);
+ std::vector<Row> baseline;
+ std::vector<Row> pruned;
+ ASSERT_NO_FATAL_FAILURE(scan(narrow, false, &baseline));
+ ASSERT_NO_FATAL_FAILURE(scan(narrow, true, &pruned));
+ EXPECT_EQ(pruned, baseline);
+ ASSERT_EQ(pruned.size(), 32);
+ for (size_t row = 0; row < pruned.size(); ++row) {
+ const auto expected = 96 + cast_set<int32_t>(row);
+ EXPECT_EQ(pruned[row].first, expected);
+ EXPECT_EQ(pruned[row].second,
+ narrow ? std::to_string(expected)
+ :
fmt::format(R"({{"a":{{"b":{},"extra":"x"}}}})", expected));
+ }
+ }
+}
+
TEST_F(NewParquetReaderTest,
ReadsVariantPredicateLeafBeforeDeferredRootOutput) {
const char* source_root = std::getenv("ROOT");
ASSERT_NE(source_root, nullptr);
@@ -3592,7 +3765,7 @@ TEST_F(NewParquetReaderTest,
ReadsVariantPredicateLeafBeforeDeferredRootOutput)
format::LocalIndex(0));
request->non_predicate_positions.emplace(format::LocalColumnId(schema[1].local_id),
format::LocalIndex(1));
-
request->conjuncts.push_back(create_variant_int32_path_greater_than_conjunct(0,
"n", 3000));
+
request->conjuncts.push_back(create_variant_int32_path_greater_than_conjunct(0,
{"n"}, 3000));
ASSERT_TRUE(reader->open(request).ok());
size_t rows = 0;
diff --git a/be/test/format_v2/parquet/parquet_statistics_test.cpp
b/be/test/format_v2/parquet/parquet_statistics_test.cpp
index ddba7a742ed..7323256c46a 100644
--- a/be/test/format_v2/parquet/parquet_statistics_test.cpp
+++ b/be/test/format_v2/parquet/parquet_statistics_test.cpp
@@ -2665,7 +2665,7 @@ TEST(NativeParquetStatisticsTest,
ShreddedVariantTypedValueDrivesPageFiltering)
EXPECT_EQ(selected_ranges[0].length, 100);
}
-TEST(NativeParquetStatisticsTest,
ShreddedVariantAncestorFallbackDisablesPruning) {
+TEST(NativeParquetStatisticsTest,
ShreddedVariantPruningUsesOnlyTerminalFallback) {
auto encode_int32 = [](int32_t value) {
std::string bytes(sizeof(value), '\0');
memcpy(bytes.data(), &value, sizeof(value));
@@ -2720,11 +2720,13 @@ TEST(NativeParquetStatisticsTest,
ShreddedVariantAncestorFallbackDisablesPruning
std::vector<std::unique_ptr<format::parquet::ParquetColumnSchema>> schema;
schema.push_back(std::move(variant));
- auto chunk = [&](tparquet::Type::type type, int64_t null_count,
+ auto chunk = [&](tparquet::Type::type type, std::optional<int64_t>
null_count,
std::optional<int32_t> min_value = std::nullopt,
std::optional<int32_t> max_value = std::nullopt) {
tparquet::Statistics statistics;
- statistics.__set_null_count(null_count);
+ if (null_count.has_value()) {
+ statistics.__set_null_count(*null_count);
+ }
if (min_value.has_value() && max_value.has_value()) {
statistics.__set_min_value(encode_int32(*min_value));
statistics.__set_max_value(encode_int32(*max_value));
@@ -2754,35 +2756,50 @@ TEST(NativeParquetStatisticsTest,
ShreddedVariantAncestorFallbackDisablesPruning
request.predicate_columns =
{format::LocalColumnIndex::top_level(format::LocalColumnId(0))};
request.conjuncts = {nested_variant_path_gt_conjunct(50)};
- std::vector<int> selected_row_groups;
- ASSERT_TRUE(format::parquet::select_row_groups_by_metadata(
- metadata, schema, request, nullptr,
&selected_row_groups, false, nullptr,
- nullptr, nullptr, nullptr, {},
- format::parquet::ParquetMetadataProbeMode::FOOTER_ONLY)
- .ok());
- EXPECT_EQ(selected_row_groups, std::vector<int>({0}));
-
format::parquet::NativeParquetPageIndex typed_pages;
- typed_pages.column_index.__set_min_values({encode_int32(1)});
- typed_pages.column_index.__set_max_values({encode_int32(2)});
- typed_pages.column_index.__set_null_pages({false});
- typed_pages.column_index.__set_null_counts({0});
+ typed_pages.column_index.__set_min_values({encode_int32(1),
encode_int32(51)});
+ typed_pages.column_index.__set_max_values({encode_int32(2),
encode_int32(52)});
+ typed_pages.column_index.__set_null_pages({false, false});
+ typed_pages.column_index.__set_null_counts({0, 0});
tparquet::PageLocation location;
location.__set_offset(0);
location.__set_compressed_page_size(10);
location.__set_first_row_index(0);
- typed_pages.offset_index.__set_page_locations({location});
+ auto second_location = location;
+ second_location.__set_offset(10);
+ second_location.__set_first_row_index(50);
+ typed_pages.offset_index.__set_page_locations({location, second_location});
std::unordered_map<int, format::parquet::NativeParquetPageIndex>
page_indexes;
page_indexes.emplace(4, std::move(typed_pages));
- std::vector<format::parquet::RowRange> selected_ranges;
- std::map<int, format::parquet::ParquetPageSkipPlan> skip_plans;
- ASSERT_TRUE(format::parquet::select_row_group_ranges_by_native_page_index(
- metadata, metadata.row_groups[0], page_indexes,
schema, request, 100,
- &selected_ranges, &skip_plans, nullptr)
- .ok());
- ASSERT_EQ(selected_ranges.size(), 1);
- EXPECT_EQ(selected_ranges[0].start, 0);
- EXPECT_EQ(selected_ranges[0].length, 100);
+
+ for (const auto null_count :
+ std::initializer_list<std::optional<int64_t>> {100, 99,
std::nullopt}) {
+ SCOPED_TRACE(null_count.value_or(-1));
+ const bool may_prune = null_count == 100;
+ auto& columns = metadata.row_groups[0].columns;
+ columns[3] = chunk(tparquet::Type::BYTE_ARRAY, null_count);
+ columns[4] = chunk(tparquet::Type::INT32, 0, 1, 2);
+
+ std::vector<int> selected_row_groups;
+ ASSERT_TRUE(format::parquet::select_row_groups_by_metadata(
+ metadata, schema, request, nullptr,
&selected_row_groups, false,
+ nullptr, nullptr, nullptr, nullptr, {},
+
format::parquet::ParquetMetadataProbeMode::FOOTER_ONLY)
+ .ok());
+ EXPECT_EQ(selected_row_groups, may_prune ? std::vector<int> {} :
std::vector<int> {0});
+
+ // The second page matches the predicate, so the row group cannot be
removed at the footer.
+ columns[4] = chunk(tparquet::Type::INT32, 0, 1, 52);
+ std::vector<format::parquet::RowRange> selected_ranges;
+ std::map<int, format::parquet::ParquetPageSkipPlan> skip_plans;
+
ASSERT_TRUE(format::parquet::select_row_group_ranges_by_native_page_index(
+ metadata, metadata.row_groups[0], page_indexes,
schema, request, 100,
+ &selected_ranges, &skip_plans, nullptr)
+ .ok());
+ ASSERT_EQ(selected_ranges.size(), 1);
+ EXPECT_EQ(selected_ranges[0].start, may_prune ? 50 : 0);
+ EXPECT_EQ(selected_ranges[0].length, may_prune ? 50 : 100);
+ }
}
} // namespace
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]