This is an automated email from the ASF dual-hosted git repository.

HappenLee pushed a commit to branch ckb2
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 2e5cb73795b71f4bfa5cb2baf96fef8389e3eb0b
Author: happenlee <[email protected]>
AuthorDate: Mon Apr 13 14:36:44 2026 +0800

    [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
    (cherry picked from commit 0df17179f46244a5f07208b0922b77599e4fd006)
---
 .../org/apache/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 97370c261ab..7f2ca925b19 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
@@ -691,8 +691,7 @@ public class NestedColumnPruning implements CustomRewriter {
                 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 ba089f735a1..1159055c431 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 {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to