This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new f171a84d4ac [branch-4.1](variant) Fix compaction failure on no-key
table with variant column uid=0 #62571 (#62657)
f171a84d4ac is described below
commit f171a84d4ac1094a3ccef746770e1e88747c2c86
Author: Chenyang Sun <[email protected]>
AuthorDate: Wed Apr 22 14:50:37 2026 +0800
[branch-4.1](variant) Fix compaction failure on no-key table with variant
column uid=0 #62571 (#62657)
pick from master #62571 #62632
---
be/src/exec/common/variant_util.cpp | 2 +-
be/src/exec/scan/olap_scanner.cpp | 3 +-
.../storage/segment/variant_stats_calculator.cpp | 4 +-
be/src/storage/tablet/tablet_schema.h | 2 +-
.../segment/variant_column_writer_reader_test.cpp | 63 +++++++++++++++++++
.../compaction/test_compaction_nokey_variant.out | 21 +++++++
.../test_compaction_nokey_variant.groovy | 71 ++++++++++++++++++++++
7 files changed, 161 insertions(+), 5 deletions(-)
diff --git a/be/src/exec/common/variant_util.cpp
b/be/src/exec/common/variant_util.cpp
index 4fa9f7da33f..bad21fab488 100644
--- a/be/src/exec/common/variant_util.cpp
+++ b/be/src/exec/common/variant_util.cpp
@@ -401,7 +401,7 @@ Status update_least_common_schema(const
std::vector<TabletSchemaSPtr>& schemas,
for (const TabletSchemaSPtr& schema : schemas) {
for (const TabletColumnPtr& col : schema->columns()) {
// Get subcolumns of this variant
- if (col->has_path_info() && col->parent_unique_id() > 0 &&
+ if (col->has_path_info() && col->parent_unique_id() >= 0 &&
col->parent_unique_id() == variant_col_unique_id) {
subcolumns_types[*col->path_info_ptr()].emplace_back(
DataTypeFactory::instance().create_data_type(*col,
col->is_nullable()));
diff --git a/be/src/exec/scan/olap_scanner.cpp
b/be/src/exec/scan/olap_scanner.cpp
index 71cac389f78..0bcf74c8e47 100644
--- a/be/src/exec/scan/olap_scanner.cpp
+++ b/be/src/exec/scan/olap_scanner.cpp
@@ -530,7 +530,8 @@ Status OlapScanner::_init_return_columns() {
}
const auto& column = tablet_schema->column(index);
- int32_t unique_id = column.unique_id() > 0 ? column.unique_id() :
column.parent_unique_id();
+ int32_t unique_id =
+ column.unique_id() >= 0 ? column.unique_id() :
column.parent_unique_id();
if (!slot->all_access_paths().empty()) {
_tablet_reader_params.all_access_paths.insert({unique_id,
slot->all_access_paths()});
}
diff --git a/be/src/storage/segment/variant_stats_calculator.cpp
b/be/src/storage/segment/variant_stats_calculator.cpp
index 5b9d0bfe679..b1bffb7673d 100644
--- a/be/src/storage/segment/variant_stats_calculator.cpp
+++ b/be/src/storage/segment/variant_stats_calculator.cpp
@@ -37,7 +37,7 @@ VariantStatsCaculator::VariantStatsCaculator(SegmentFooterPB*
footer,
const auto& column = _footer->columns(i);
// path that need to record stats
if (column.has_column_path_info() &&
- column.column_path_info().parrent_column_unique_id() > 0) {
+ column.column_path_info().has_parrent_column_unique_id()) {
_path_to_footer_index[column.column_path_info().parrent_column_unique_id()]
[column.column_path_info().path()] = i;
}
@@ -50,7 +50,7 @@ Status VariantStatsCaculator::calculate_variant_stats(const
Block* block, size_t
const TabletColumn& tablet_column =
_tablet_schema->column(_column_ids[i]);
// Only process sub columns and sparse columns during compaction
if (tablet_column.has_path_info() &&
tablet_column.path_info_ptr()->need_record_stats() &&
- tablet_column.parent_unique_id() > 0) {
+ tablet_column.parent_unique_id() >= 0) {
const std::string& column_path =
tablet_column.path_info_ptr()->get_path();
// Find the parent column in footer
auto it =
_path_to_footer_index.find(tablet_column.parent_unique_id());
diff --git a/be/src/storage/tablet/tablet_schema.h
b/be/src/storage/tablet/tablet_schema.h
index 1fae1a9b8ec..07fed88d2c4 100644
--- a/be/src/storage/tablet/tablet_schema.h
+++ b/be/src/storage/tablet/tablet_schema.h
@@ -193,7 +193,7 @@ public:
const PathInDataPtr& path_info_ptr() const { return _column_path; }
// If it is an extracted column from variant column
bool is_extracted_column() const {
- return _column_path != nullptr && !_column_path->empty() &&
_parent_col_unique_id > 0;
+ return _column_path != nullptr && !_column_path->empty() &&
_parent_col_unique_id >= 0;
};
std::string suffix_path() const {
return is_extracted_column() ? _column_path->get_path() : "";
diff --git a/be/test/storage/segment/variant_column_writer_reader_test.cpp
b/be/test/storage/segment/variant_column_writer_reader_test.cpp
index 653b0c47920..7ffcb46cdf8 100644
--- a/be/test/storage/segment/variant_column_writer_reader_test.cpp
+++ b/be/test/storage/segment/variant_column_writer_reader_test.cpp
@@ -4008,4 +4008,67 @@ TEST_F(VariantColumnWriterReaderTest,
EXPECT_EQ(actual_rows, expected_rows);
}
+// Regression test: compaction on no-key duplicate table with variant column
uid=0.
+// TabletColumn::is_extracted_column() used "_parent_col_unique_id > 0" which
+// incorrectly returned false for subcolumns whose parent has uid=0, causing
+// VariantColumnWriterImpl to duplicate sparse column entries in segment
footer.
+// Without fix: DCHECK(uid >= 0) fires in segment_iterator.cpp because
+// is_extracted_column() wrongly returns false for extracted cols with parent
uid=0,
+// making them take the non-extracted path where uid=-1 violates the check.
+TEST_F(VariantColumnWriterReaderTest, test_compaction_nokey_variant_uid0) {
+ TabletSchemaPB schema_pb;
+ schema_pb.set_keys_type(KeysType::DUP_KEYS);
+ construct_column(schema_pb.add_column(), /*col_unique_id=*/0, "VARIANT",
"v1",
+ /*variant_max_subcolumns_count=*/3);
+ _tablet_schema = std::make_shared<TabletSchema>();
+ _tablet_schema->init_from_pb(schema_pb);
+
+ TabletMetaSharedPtr tablet_meta(new TabletMeta(_tablet_schema));
+ tablet_meta->_tablet_id = 99900;
+ _tablet = std::make_shared<Tablet>(*_engine_ref, tablet_meta,
_data_dir.get());
+ ASSERT_TRUE(_tablet->init().ok());
+
ASSERT_TRUE(io::global_local_filesystem()->delete_directory(_tablet->tablet_path()).ok());
+
ASSERT_TRUE(io::global_local_filesystem()->create_directory(_tablet->tablet_path()).ok());
+
+ auto rs0 = create_variant_rowset(
+ {{R"({"name":"Alice","age":30})", R"({"name":"Bob","age":25})"}},
2);
+ auto rs1 =
+ create_variant_rowset({{R"({"name":"u1","age":10})",
R"({"name":"u2","age":20})"}}, 3);
+
+ std::vector<RowsetSharedPtr> input_rowsets {rs0, rs1};
+ auto input_readers = create_rowset_readers(input_rowsets);
+
+ auto compaction_schema = std::make_shared<TabletSchema>(*_tablet_schema);
+ auto st =
variant_util::VariantCompactionUtil::get_extended_compaction_schema(
+ input_rowsets, compaction_schema);
+ ASSERT_TRUE(st.ok()) << st.to_string();
+
+ RowsetWriterContext ctx;
+ RowsetId rowset_id;
+ rowset_id.init(9999);
+ ctx.rowset_id = rowset_id;
+ ctx.rowset_type = BETA_ROWSET;
+ ctx.data_dir = _data_dir.get();
+ ctx.rowset_state = VISIBLE;
+ ctx.tablet_schema = compaction_schema;
+ ctx.tablet_path = _tablet->tablet_path();
+ ctx.tablet_id = _tablet->tablet_id();
+ ctx.tablet = _tablet;
+ ctx.version = Version(2, 3);
+ ctx.write_type = DataWriteType::TYPE_COMPACTION;
+ auto res = RowsetFactory::create_rowset_writer(*_engine_ref, ctx, true);
+ ASSERT_TRUE(res.has_value()) << res.error();
+ auto output_writer = std::move(res).value();
+
+ Merger::Statistics stats;
+ st = Merger::vertical_merge_rowsets(_tablet,
ReaderType::READER_CUMULATIVE_COMPACTION,
+ *compaction_schema, input_readers,
output_writer.get(),
+ 10000, 2, &stats);
+ ASSERT_TRUE(st.ok()) << st.to_string();
+
+ RowsetSharedPtr output_rowset;
+ ASSERT_TRUE(output_writer->build(output_rowset).ok());
+ ASSERT_EQ(output_rowset->num_rows(), 4);
+}
+
} // namespace doris
diff --git
a/regression-test/data/variant_p0/compaction/test_compaction_nokey_variant.out
b/regression-test/data/variant_p0/compaction/test_compaction_nokey_variant.out
new file mode 100644
index 00000000000..dade1e5e11a
--- /dev/null
+++
b/regression-test/data/variant_p0/compaction/test_compaction_nokey_variant.out
@@ -0,0 +1,21 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !before_compaction --
+{"age":10,"name":"u1"} {"city":"c1"} {"score":10.5}
+{"age":20,"name":"u2"} {"city":"c2"} {"score":20.5}
+{"age":25,"name":"Bob"} {"city":"Shanghai"} {"passed":1,"score":88}
+{"age":30,"name":"Alice"} {"city":"Beijing","zip":100000}
{"passed":1,"score":95.5}
+{"age":30,"name":"u3"} {"city":"c3"} {"score":30.5}
+{"age":40,"name":"u4"} {"city":"c4"} {"score":40.5}
+{"age":50,"name":"u5"} {"city":"c5"} {"score":50.5}
+{"name":"Charlie"} {"city":"Shenzhen","zip":518000}
{"passed":0,"score":72.3}
+
+-- !after_compaction --
+{"age":10,"name":"u1"} {"city":"c1"} {"score":10.5}
+{"age":20,"name":"u2"} {"city":"c2"} {"score":20.5}
+{"age":25,"name":"Bob"} {"city":"Shanghai"} {"passed":1,"score":88}
+{"age":30,"name":"Alice"} {"city":"Beijing","zip":100000}
{"passed":1,"score":95.5}
+{"age":30,"name":"u3"} {"city":"c3"} {"score":30.5}
+{"age":40,"name":"u4"} {"city":"c4"} {"score":40.5}
+{"age":50,"name":"u5"} {"city":"c5"} {"score":50.5}
+{"name":"Charlie"} {"city":"Shenzhen","zip":518000}
{"passed":0,"score":72.3}
+
diff --git
a/regression-test/suites/variant_p0/compaction/test_compaction_nokey_variant.groovy
b/regression-test/suites/variant_p0/compaction/test_compaction_nokey_variant.groovy
new file mode 100644
index 00000000000..5225ce11186
--- /dev/null
+++
b/regression-test/suites/variant_p0/compaction/test_compaction_nokey_variant.groovy
@@ -0,0 +1,71 @@
+// 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.
+
+// Regression test for: compaction fails on no-key duplicate table with only
+// variant columns when the first variant column has unique_id=0.
+// Root cause: TabletColumn::is_extracted_column() used "_parent_col_unique_id
> 0"
+// which incorrectly excluded subcolumns whose parent has unique_id=0.
+
+suite("test_compaction_nokey_variant") {
+ def tableName = "test_compaction_nokey_variant"
+
+ sql "DROP TABLE IF EXISTS ${tableName}"
+ sql """
+ CREATE TABLE ${tableName} (
+ v1 VARIANT,
+ v2 VARIANT,
+ v3 VARIANT
+ )
+ DISTRIBUTED BY RANDOM BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1",
+ "disable_auto_compaction" = "true",
+ "enable_duplicate_without_keys_by_default" = "true"
+ );
+ """
+
+ // Insert multiple batches to create multiple rowsets
+ sql """INSERT INTO ${tableName} VALUES
+ ('{"name":"Alice","age":30}', '{"city":"Beijing","zip":100000}',
'{"score":95.5,"passed":true}'),
+ ('{"name":"Bob","age":25}', '{"city":"Shanghai"}',
'{"score":88.0,"passed":true}'),
+ ('{"name":"Charlie"}', '{"city":"Shenzhen","zip":518000}',
'{"score":72.3,"passed":false}');"""
+
+ sql """INSERT INTO ${tableName} VALUES ('{"name":"u1","age":10}',
'{"city":"c1"}', '{"score":10.5}');"""
+ sql """INSERT INTO ${tableName} VALUES ('{"name":"u2","age":20}',
'{"city":"c2"}', '{"score":20.5}');"""
+ sql """INSERT INTO ${tableName} VALUES ('{"name":"u3","age":30}',
'{"city":"c3"}', '{"score":30.5}');"""
+ sql """INSERT INTO ${tableName} VALUES ('{"name":"u4","age":40}',
'{"city":"c4"}', '{"score":40.5}');"""
+ sql """INSERT INTO ${tableName} VALUES ('{"name":"u5","age":50}',
'{"city":"c5"}', '{"score":50.5}');"""
+
+ // Verify data before compaction
+ qt_before_compaction """SELECT cast(v1 as string) c1, cast(v2 as string)
c2, cast(v3 as string) c3
+ FROM ${tableName} ORDER BY c1;"""
+
+ def rowCountBefore = sql "SELECT count() FROM ${tableName}"
+ assertEquals(8, rowCountBefore[0][0])
+
+ // Trigger cumulative compaction - reproduces the bug when
is_extracted_column() is wrong
+ trigger_and_wait_compaction(tableName, "cumulative")
+
+ // Verify data after compaction
+ qt_after_compaction """SELECT cast(v1 as string) c1, cast(v2 as string)
c2, cast(v3 as string) c3
+ FROM ${tableName} ORDER BY c1;"""
+
+ def rowCountAfter = sql "SELECT count() FROM ${tableName}"
+ assertEquals(8, rowCountAfter[0][0])
+
+ sql "DROP TABLE IF EXISTS ${tableName}"
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]