-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[fix](iceberg) Honor disabled write metrics #65782
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
Open
Gabriel39
wants to merge
10
commits into
apache:master
Choose a base branch
from
Gabriel39:ai/doris-27023-iceberg-write-metrics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
62adff4
fix(iceberg): honor disabled write metrics
Gabriel39 c95c9d1
fix(iceberg): handle absent metrics in stats
Gabriel39 42d2ca9
fix(iceberg): preserve unknown stats on close failure
Gabriel39 a91df69
fix(iceberg): apply metrics modes to bounds
Gabriel39 1fe01c8
fix(iceberg): address write metrics review feedback
Gabriel39 f05f437
fix(iceberg): detect v3 transaction table format
Gabriel39 53a14e3
fix(iceberg): evaluate metrics for writer schema
Gabriel39 471470f
fix(iceberg): map ORC stats by column id
Gabriel39 d3abdfa
fix(iceberg): narrow ORC statistics column id safely
Gabriel39 d6f2112
fix(iceberg): preserve ORC upper bound fallback
Gabriel39 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
be/test/exec/sink/writer/iceberg/iceberg_partition_writer_test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <optional> | ||
|
|
||
| #include "exec/sink/writer/iceberg/viceberg_partition_writer.h" | ||
|
|
||
| namespace doris { | ||
|
|
||
| namespace { | ||
|
|
||
| class FakeFileFormatTransformer final : public VFileFormatTransformer { | ||
| public: | ||
| explicit FakeFileFormatTransformer(const VExprContextSPtrs& output_exprs) | ||
| : VFileFormatTransformer(nullptr, output_exprs, false) {} | ||
|
|
||
| Status open() override { return Status::OK(); } | ||
| Status write(const Block&) override { return Status::OK(); } | ||
| Status close() override { return Status::OK(); } | ||
| int64_t written_len() override { return 64; } | ||
| }; | ||
|
|
||
| TDataSink make_table_sink(std::optional<bool> collect_column_stats) { | ||
| TIcebergTableSink iceberg_sink; | ||
| if (collect_column_stats.has_value()) { | ||
| iceberg_sink.__set_collect_column_stats(*collect_column_stats); | ||
| } | ||
| TDataSink sink; | ||
| sink.__set_type(TDataSinkType::ICEBERG_TABLE_SINK); | ||
| sink.__set_iceberg_table_sink(iceberg_sink); | ||
| return sink; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| class VIcebergPartitionWriterTest : public testing::Test { | ||
| protected: | ||
| static std::unique_ptr<VIcebergPartitionWriter> make_writer( | ||
| const TDataSink& sink, const VExprContextSPtrs& output_exprs, | ||
| const iceberg::Schema& schema, const std::string* schema_json, | ||
| const std::map<std::string, std::string>& hadoop_conf) { | ||
| IPartitionWriterBase::WriteInfo write_info; | ||
| write_info.file_type = TFileType::FILE_LOCAL; | ||
| return std::make_unique<VIcebergPartitionWriter>( | ||
| sink, std::vector<std::string> {}, output_exprs, schema, schema_json, | ||
| std::vector<std::string> {}, std::move(write_info), "data", 0, | ||
| TFileFormatType::FORMAT_ORC, TFileCompressType::ZLIB, hadoop_conf); | ||
| } | ||
|
|
||
| static void install_fake_transformer(VIcebergPartitionWriter* writer, | ||
| const VExprContextSPtrs& output_exprs) { | ||
| writer->_file_format_transformer = | ||
| std::make_unique<FakeFileFormatTransformer>(output_exprs); | ||
| } | ||
|
|
||
| static Status build_commit_data(VIcebergPartitionWriter* writer, | ||
| TIcebergCommitData* commit_data) { | ||
| return writer->_build_iceberg_commit_data(commit_data); | ||
| } | ||
|
|
||
| static bool collect_column_stats(const VIcebergPartitionWriter& writer) { | ||
| return writer._collect_column_stats; | ||
| } | ||
| }; | ||
|
|
||
| TEST_F(VIcebergPartitionWriterTest, OrcSkipsFooterCollectionWhenMetricsAreDisabled) { | ||
| VExprContextSPtrs output_exprs; | ||
| iceberg::Schema schema(std::vector<iceberg::NestedField> {}); | ||
| std::string schema_json; | ||
| std::map<std::string, std::string> hadoop_conf; | ||
| auto writer = | ||
| make_writer(make_table_sink(false), output_exprs, schema, &schema_json, hadoop_conf); | ||
| install_fake_transformer(writer.get(), output_exprs); | ||
|
|
||
| TIcebergCommitData commit_data; | ||
| ASSERT_TRUE(build_commit_data(writer.get(), &commit_data).ok()); | ||
| EXPECT_FALSE(commit_data.__isset.column_stats); | ||
| } | ||
|
|
||
| TEST_F(VIcebergPartitionWriterTest, MissingPolicyKeepsCollectionEnabledForRollingUpgrade) { | ||
| VExprContextSPtrs output_exprs; | ||
| iceberg::Schema schema(std::vector<iceberg::NestedField> {}); | ||
| std::string schema_json; | ||
| std::map<std::string, std::string> hadoop_conf; | ||
| auto writer = make_writer(make_table_sink(std::nullopt), output_exprs, schema, &schema_json, | ||
| hadoop_conf); | ||
|
|
||
| EXPECT_TRUE(collect_column_stats(*writer)); | ||
| } | ||
|
|
||
| } // namespace doris |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include "format/transformer/vorc_transformer.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include "core/block/block.h" | ||
| #include "core/column/column_string.h" | ||
| #include "core/column/column_struct.h" | ||
| #include "core/column/column_vector.h" | ||
| #include "core/data_type/data_type_number.h" | ||
| #include "core/data_type/data_type_string.h" | ||
| #include "core/data_type/data_type_struct.h" | ||
| #include "format/table/iceberg/schema_parser.h" | ||
| #include "io/fs/local_file_system.h" | ||
| #include "runtime/runtime_state.h" | ||
| #include "testutil/mock/mock_slot_ref.h" | ||
| #include "util/uid_util.h" | ||
|
|
||
| namespace doris { | ||
|
|
||
| class VOrcTransformerTest : public testing::Test { | ||
| protected: | ||
| void SetUp() override { | ||
| _file_path = "./vorc_transformer_" + UniqueId::gen_uid().to_string() + ".orc"; | ||
| _fs = io::global_local_filesystem(); | ||
| } | ||
|
|
||
| void TearDown() override { static_cast<void>(_fs->delete_file(_file_path)); } | ||
|
|
||
| std::string _file_path; | ||
| std::shared_ptr<io::FileSystem> _fs; | ||
| }; | ||
|
|
||
| TEST_F(VOrcTransformerTest, CollectsBoundsForTopLevelFieldAfterStruct) { | ||
| auto int_type = std::make_shared<DataTypeInt32>(); | ||
| auto struct_type = std::make_shared<DataTypeStruct>(DataTypes {int_type}, Strings {"a"}); | ||
| auto string_type = std::make_shared<DataTypeString>(); | ||
| VExprContextSPtrs output_exprs = | ||
| MockSlotRef::create_mock_contexts(DataTypes {struct_type, string_type}); | ||
|
|
||
| const std::string schema_json = R"({ | ||
| "type": "struct", | ||
| "fields": [ | ||
| { | ||
| "id": 1, | ||
| "name": "s", | ||
| "required": true, | ||
| "type": { | ||
| "type": "struct", | ||
| "fields": [ | ||
| {"id": 2, "name": "a", "required": true, "type": "int"} | ||
| ] | ||
| } | ||
| }, | ||
| {"id": 3, "name": "b", "required": true, "type": "string"} | ||
| ] | ||
| })"; | ||
| std::unique_ptr<iceberg::Schema> schema = iceberg::SchemaParser::from_json(schema_json); | ||
|
|
||
| io::FileWriterPtr file_writer; | ||
| ASSERT_TRUE(_fs->create_file(_file_path, &file_writer).ok()); | ||
| RuntimeState state; | ||
| VOrcTransformer transformer(&state, file_writer.get(), output_exprs, "", {"s", "b"}, false, | ||
| TFileCompressType::PLAIN, schema.get(), _fs); | ||
| ASSERT_TRUE(transformer.open().ok()); | ||
|
|
||
| auto nested_column = ColumnInt32::create(); | ||
| nested_column->insert_value(-1); | ||
| Columns struct_columns; | ||
| struct_columns.emplace_back(std::move(nested_column)); | ||
| auto struct_column = ColumnStruct::create(std::move(struct_columns)); | ||
| auto string_column = ColumnString::create(); | ||
| string_column->insert_data("hello", 5); | ||
|
|
||
| Block block; | ||
| block.insert(ColumnWithTypeAndName(std::move(struct_column), struct_type, "s")); | ||
| block.insert(ColumnWithTypeAndName(std::move(string_column), string_type, "b")); | ||
| ASSERT_TRUE(transformer.write(block).ok()); | ||
| ASSERT_TRUE(transformer.close().ok()); | ||
|
|
||
| TIcebergColumnStats stats; | ||
| ASSERT_TRUE(transformer.collect_file_statistics_after_close(&stats).ok()); | ||
| ASSERT_TRUE(stats.__isset.lower_bounds); | ||
| ASSERT_TRUE(stats.__isset.upper_bounds); | ||
| ASSERT_EQ(1, stats.lower_bounds.count(3)); | ||
| ASSERT_EQ(1, stats.upper_bounds.count(3)); | ||
| EXPECT_EQ("hello", stats.lower_bounds.at(3)); | ||
| EXPECT_EQ("hello", stats.upper_bounds.at(3)); | ||
| } | ||
|
|
||
| } // namespace doris |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Evaluate collection against the actual writer field set
This gate can return false even though the writer has enabled metrics outside this primitive user-schema set. For ORC
items list<int>with defaultnoneandcolumn.items=counts, it drops the top-levelitemsfield and only checksitems.element(stillnone), although both Doris and Iceberg ORC metrics publish top-level counts. Separately, for a v3 rewrite/merge with defaultcountsand every user field overridden tonone, this returns false before the binders append_row_idand_last_updated_sequence_number; those appended fields inheritcounts, and the collectors/helper support their reserved IDs. In both cases BE skips the footer and requested manifest metrics disappear. Please evaluate the effective policy against the exact schema/field set sent to the selected writer (including v3 lineage and ORC top-level complex fields), with tests for both triggers.