Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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: 5 additions & 0 deletions cpp/src/parquet/metadata_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ void WriteMetadataSetArgs(benchmark::internal::Benchmark* bench) {
for (int num_row_groups : {1, 100}) {
bench->Args({/*num_columns=*/1000, num_row_groups});
}

// Stress very wide schemas separately with a single row group.
for (int num_columns : {5000, 10000, 20000, 50000}) {
bench->Args({num_columns, /*num_row_groups=*/1});
}
}

void ReadMetadataSetArgs(benchmark::internal::Benchmark* bench) {
Expand Down
19 changes: 14 additions & 5 deletions cpp/src/parquet/schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,9 @@ void SchemaDescriptor::Init(NodePtr schema) {
group_node_ = static_cast<const GroupNode*>(schema_.get());
leaves_.clear();

std::string path;
for (int i = 0; i < group_node_->field_count(); ++i) {
BuildTree(group_node_->field(i), 0, 0, group_node_->field(i));
BuildTree(group_node_->field(i), 0, 0, group_node_->field(i), path);
}
}

Expand Down Expand Up @@ -853,7 +854,14 @@ bool SchemaDescriptor::Equals(const SchemaDescriptor& other,
}

void SchemaDescriptor::BuildTree(const NodePtr& node, int16_t max_def_level,
int16_t max_rep_level, const NodePtr& base) {
int16_t max_rep_level, const NodePtr& base,
std::string& path) {
const size_t path_size = path.size();
if (!path.empty()) {
path.push_back('.');
}
path.append(node->name());

if (node->is_optional()) {
++max_def_level;
} else if (node->is_repeated()) {
Expand All @@ -867,7 +875,7 @@ void SchemaDescriptor::BuildTree(const NodePtr& node, int16_t max_def_level,
if (node->is_group()) {
const GroupNode* group = static_cast<const GroupNode*>(node.get());
for (int i = 0; i < group->field_count(); ++i) {
BuildTree(group->field(i), max_def_level, max_rep_level, base);
BuildTree(group->field(i), max_def_level, max_rep_level, base, path);
}
} else {
node_to_leaf_index_[static_cast<const PrimitiveNode*>(node.get())] =
Expand All @@ -876,9 +884,10 @@ void SchemaDescriptor::BuildTree(const NodePtr& node, int16_t max_def_level,
// Primitive node, append to leaves
leaves_.push_back(ColumnDescriptor(node, max_def_level, max_rep_level, this));
leaf_to_base_.emplace(static_cast<int>(leaves_.size()) - 1, base);
leaf_to_idx_.emplace(node->path()->ToDotString(),
static_cast<int>(leaves_.size()) - 1);
leaf_to_idx_.emplace(path, static_cast<int>(leaves_.size()) - 1);
}

path.resize(path_size);
}

int SchemaDescriptor::GetColumnIndex(const PrimitiveNode& node) const {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/parquet/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ class PARQUET_EXPORT SchemaDescriptor {
const schema::GroupNode* group_node_;

void BuildTree(const schema::NodePtr& node, int16_t max_def_level,
int16_t max_rep_level, const schema::NodePtr& base);
int16_t max_rep_level, const schema::NodePtr& base, std::string& path);

// Result of leaf node / tree analysis
std::vector<ColumnDescriptor> leaves_;
Expand Down
16 changes: 16 additions & 0 deletions cpp/src/parquet/schema_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,22 @@ TEST_F(TestSchemaDescriptor, BuildTree) {
ASSERT_EQ(nleaves, descr_.num_columns());
}

TEST_F(TestSchemaDescriptor, ColumnIndexDuplicatePath) {
NodePtr first = Int32("duplicate", Repetition::REQUIRED);
NodePtr second = Int64("duplicate", Repetition::OPTIONAL);
NodePtr schema = GroupNode::Make("schema", Repetition::REQUIRED, {first, second});

descr_.Init(schema);

ASSERT_EQ(2, descr_.num_columns());
ASSERT_EQ("duplicate", descr_.Column(0)->path()->ToDotString());
ASSERT_EQ("duplicate", descr_.Column(1)->path()->ToDotString());

// Duplicate paths are disambiguated by node identity.
ASSERT_EQ(0, descr_.ColumnIndex(*first));
ASSERT_EQ(1, descr_.ColumnIndex(*second));
}

TEST_F(TestSchemaDescriptor, HasRepeatedFields) {
NodeVector fields;
NodePtr schema;
Expand Down
Loading