airborne12 commented on code in PR #62848:
URL: https://github.com/apache/doris/pull/62848#discussion_r3159611897
##########
be/src/exec/common/variant_util.cpp:
##########
@@ -259,6 +260,132 @@ bool glob_match_re2(const std::string& glob_pattern,
const std::string& candidat
return RE2::FullMatch(candidate_path, *compiled);
}
+bool is_regular_ng_compaction_subpath(const PathInData& path) {
+ const std::string& relative_path = path.get_path();
+ return !relative_path.empty() && !path.get_is_typed() &&
!path.has_nested_part() &&
Review Comment:
This predicate filters out typed paths (`!path.get_is_typed()`), but the NG
compaction branch later relies on this path to preserve existing extracted
subcolumns. As a result, typed/predefined paths under an NG root are excluded
before `keep_existing_ng_compaction_subcolumn()` can add them to
`typed_path_set`, and the NG branch then skips the generic
`get_compaction_typed_columns()` path. This can drop typed extracted columns
and their indexes from the compaction output schema. Please preserve typed
extracted paths explicitly in the NG branch, or run the generic typed-path
preservation before the NG `continue`.
##########
be/src/exec/common/variant_util.cpp:
##########
@@ -259,6 +260,132 @@ bool glob_match_re2(const std::string& glob_pattern,
const std::string& candidat
return RE2::FullMatch(candidate_path, *compiled);
}
+bool is_regular_ng_compaction_subpath(const PathInData& path) {
+ const std::string& relative_path = path.get_path();
+ return !relative_path.empty() && !path.get_is_typed() &&
!path.has_nested_part() &&
+ !segment_v2::contains_nested_group_marker(relative_path) &&
+ !segment_v2::is_root_nested_group_path(relative_path) &&
Review Comment:
This only rejects the exact root marker path.
`strip_root_nested_group_path()` treats both `__D0_root__` and `__D0_root__.*`
as internal root-NG paths, so `__D0_root__.child` can still pass this
regular-subpath predicate and be materialized as a user regular path. Please
add/use a child-aware helper, e.g. `is_root_nested_group_path_or_child()`, in
both compaction and reader path classification.
##########
be/src/core/column/column_variant.cpp:
##########
@@ -413,6 +420,11 @@ void ColumnVariant::Subcolumn::insert_range_from(const
Subcolumn& src, size_t st
Status st = variant_util::cast_column({column, column_type, ""},
least_common_type.get(),
&casted_column);
if (!st.ok()) {
+ if (is_nested_group_type(least_common_type.get()) &&
Review Comment:
The earlier branch only discards true scalar sources, but this cast-failure
fallback no longer checks `src_is_scalar`. With
`variant_nested_group_discard_scalar_on_conflict=true`, a non-scalar
array/object source that fails casting to the NG-compatible type will be
silently replaced with defaults. Please carry the scalar-source decision into
both cast-failure branches and surface the cast error for non-scalar sources.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java:
##########
@@ -185,6 +185,11 @@ public String toSql() {
.append(String.valueOf(variantSparseHashShardCount))
.append("\"");
}
+ if (enableNestedGroup) {
Review Comment:
This serializes `variant_enable_nested_group=true`, but `LogicalPlanBuilder`
currently rejects that property, while catalog `VariantType.toSql()`
intentionally omits it. This makes Nereids-generated type SQL
non-round-trippable. Please either omit this property here until DDL support is
enabled, or support the property end-to-end in the parser/validator. If
`enableNestedGroup` remains storage/API-affecting metadata, it should also be
included consistently in `equals()` / `hashCode()`.
##########
be/src/exec/common/variant_util.cpp:
##########
@@ -259,6 +260,132 @@ bool glob_match_re2(const std::string& glob_pattern,
const std::string& candidat
return RE2::FullMatch(candidate_path, *compiled);
}
+bool is_regular_ng_compaction_subpath(const PathInData& path) {
+ const std::string& relative_path = path.get_path();
+ return !relative_path.empty() && !path.get_is_typed() &&
!path.has_nested_part() &&
+ !segment_v2::contains_nested_group_marker(relative_path) &&
+ !segment_v2::is_root_nested_group_path(relative_path) &&
+ relative_path != SPARSE_COLUMN_PATH &&
+ relative_path.find(DOC_VALUE_COLUMN_PATH) == std::string::npos;
+}
+
+bool should_keep_existing_ng_compaction_subcolumn(const TabletColumn& column) {
+ if (!column.is_extracted_column()) {
+ return false;
+ }
+ return
is_regular_ng_compaction_subpath(column.path_info_ptr()->copy_pop_front());
+}
+
+TabletIndexes clone_tablet_indexes(const std::vector<const TabletIndex*>&
indexes) {
+ TabletIndexes cloned_indexes;
+ cloned_indexes.reserve(indexes.size());
+ for (const auto* index : indexes) {
+ cloned_indexes.emplace_back(std::make_shared<TabletIndex>(*index));
+ }
+ return cloned_indexes;
+}
+
+void keep_existing_ng_compaction_subcolumn(const TabletSchemaSPtr&
source_schema,
+ const TabletColumnPtr&
extracted_column,
+ TabletSchemaSPtr& output_schema,
+ TabletSchema::PathsSetInfo&
paths_set_info) {
+ DCHECK(extracted_column->is_extracted_column());
+ DCHECK(should_keep_existing_ng_compaction_subcolumn(*extracted_column));
+
+ auto relative_path = extracted_column->path_info_ptr()->copy_pop_front();
+ const std::string path = relative_path.get_path();
+ output_schema->append_column(*extracted_column);
+
+ auto indexes =
clone_tablet_indexes(source_schema->inverted_indexs(*extracted_column));
+ if (extracted_column->path_info_ptr()->get_is_typed()) {
+ TabletSchema::SubColumnInfo sub_column_info {.column =
*extracted_column,
+ .indexes =
std::move(indexes)};
+ paths_set_info.typed_path_set.emplace(path,
std::move(sub_column_info));
+ return;
+ }
+
+ paths_set_info.sub_path_set.emplace(path);
+ if (!indexes.empty()) {
+ paths_set_info.subcolumn_indexes.emplace(path, std::move(indexes));
+ }
+}
+
+using ExistingNgCompactionSubcolumns = std::unordered_map<int32_t,
std::vector<TabletColumnPtr>>;
+
+struct NestedGroupCompactionMaterializationPlan {
+ std::vector<TabletColumnPtr> preserved_regular_subcolumns;
+ PathSet materialized_regular_paths;
+ PathToDataTypes additional_regular_path_to_data_types;
+};
+
+bool should_preserve_existing_ng_compaction_subcolumns(
+ const TabletColumnPtr& column,
+ const std::unordered_map<int32_t, VariantExtendedInfo>&
uid_to_variant_extended_info) {
+ const auto info_it =
uid_to_variant_extended_info.find(column->unique_id());
+ return column->variant_enable_nested_group() ||
+ (info_it != uid_to_variant_extended_info.end() &&
info_it->second.has_nested_group);
+}
+
+std::unordered_set<int32_t> collect_ng_compaction_root_uids(
+ const TabletSchemaSPtr& target,
+ const std::unordered_map<int32_t, VariantExtendedInfo>&
uid_to_variant_extended_info) {
+ std::unordered_set<int32_t> root_uids;
+ for (const TabletColumnPtr& column : target->columns()) {
+ if (column->is_variant_type() &&
should_preserve_existing_ng_compaction_subcolumns(
+ column,
uid_to_variant_extended_info)) {
+ root_uids.insert(column->unique_id());
+ }
+ }
+ return root_uids;
+}
+
+ExistingNgCompactionSubcolumns collect_existing_ng_compaction_subcolumns(
+ const TabletSchemaSPtr& target, const std::unordered_set<int32_t>&
ng_root_uids) {
+ ExistingNgCompactionSubcolumns uid_to_existing_subcolumns;
+ for (const TabletColumnPtr& column : target->columns()) {
+ if (!column->is_extracted_column() ||
!ng_root_uids.contains(column->parent_unique_id()) ||
+ !should_keep_existing_ng_compaction_subcolumn(*column)) {
+ continue;
+ }
+
uid_to_existing_subcolumns[column->parent_unique_id()].push_back(column);
+ }
+ return uid_to_existing_subcolumns;
+}
+
+NestedGroupCompactionMaterializationPlan
build_nested_group_compaction_materialization_plan(
+ const std::vector<TabletColumnPtr>& existing_subcolumns,
+ const VariantExtendedInfo& extended_info) {
+ NestedGroupCompactionMaterializationPlan plan;
+ plan.preserved_regular_subcolumns = existing_subcolumns;
+ for (const auto& column : existing_subcolumns) {
+ plan.materialized_regular_paths.emplace(
+ column->path_info_ptr()->copy_pop_front().get_path());
+ }
+ for (const auto& [path, data_types] : extended_info.path_to_data_types) {
Review Comment:
This plan depends on `extended_info.path_to_data_types`, but
`get_extended_compaction_schema()` only populates `extended_info` when some
target Variant column passes `should_check_variant_path_stats()`. That helper
returns false for NG Variant columns, so a table with only NG Variant columns
will not collect this type metadata at all, while adding an unrelated non-NG
Variant column changes the NG materialization behavior. Please split flat
path-stat aggregation from NG type-metadata aggregation and collect the latter
whenever NG roots need compaction planning.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]