From 0df17179f46244a5f07208b0922b77599e4fd006 Mon Sep 17 00:00:00 2001 From: happenlee Date: Mon, 13 Apr 2026 14:36:44 +0800 Subject: [PATCH] [fix](fe) Fix struct field slot type in NestedColumnPruning for OFFSET-only access Issue Number: close #xxx Problem Summary: When using struct_element() to access a string field inside a struct (e.g., length(struct_element(struct_col, 'f3'))), the NestedColumnPruning rule incorrectly returned Optional.empty() for the slot type, causing the slot type to become nullable and lose its original type information. The fix changes the return value from Optional.empty() to Optional.of(type) when the column is accessed in OFFSET-only mode (e.g., length()), ensuring the slot type remains the original type (e.g., varchar). Release note: None Test: Added test case in string_length_column_pruning.groovy --- .../doris/nereids/rules/rewrite/NestedColumnPruning.java | 3 +-- .../column_pruning/string_length_column_pruning.groovy | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NestedColumnPruning.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NestedColumnPruning.java index e096d8c2f85d7f..3c368f0f4b3cce 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NestedColumnPruning.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NestedColumnPruning.java @@ -666,8 +666,7 @@ public Optional pruneDataType() { return Optional.of(type); } else if (isStringOffsetOnly) { // Only the offset array is accessed (e.g. length(str_col)). - // The slot type stays unchanged (varchar); the access path tells BE to skip char data. - return Optional.empty(); + return Optional.of(type); } else if (!accessPartialChild) { return Optional.empty(); } diff --git a/regression-test/suites/nereids_rules_p0/column_pruning/string_length_column_pruning.groovy b/regression-test/suites/nereids_rules_p0/column_pruning/string_length_column_pruning.groovy index ba089f735a133d..1159055c431418 100644 --- a/regression-test/suites/nereids_rules_p0/column_pruning/string_length_column_pruning.groovy +++ b/regression-test/suites/nereids_rules_p0/column_pruning/string_length_column_pruning.groovy @@ -69,7 +69,7 @@ suite("string_length_column_pruning") { contains "OFFSET" notContains "type=bigint" } - //sql "select length(struct_element(struct_col, 'f3')) from slcp_str_tbl" + sql "select length(struct_element(struct_col, 'f3')) from slcp_str_tbl" // length() in both SELECT and WHERE: predicate must remain length(str_col) > 1, // never be rewritten to CAST(str_col AS int) > 1. Slot type must stay varchar. explain {