Skip to content

Commit 3946063

Browse files
authored
[fix](fe) Fix struct field slot type in NestedColumnPruning for OFFSET-only access (#62446)
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
1 parent 7ec32b4 commit 3946063

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NestedColumnPruning.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,7 @@ public Optional<DataType> pruneDataType() {
666666
return Optional.of(type);
667667
} else if (isStringOffsetOnly) {
668668
// Only the offset array is accessed (e.g. length(str_col)).
669-
// The slot type stays unchanged (varchar); the access path tells BE to skip char data.
670-
return Optional.empty();
669+
return Optional.of(type);
671670
} else if (!accessPartialChild) {
672671
return Optional.empty();
673672
}

regression-test/suites/nereids_rules_p0/column_pruning/string_length_column_pruning.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ suite("string_length_column_pruning") {
6969
contains "OFFSET"
7070
notContains "type=bigint"
7171
}
72-
//sql "select length(struct_element(struct_col, 'f3')) from slcp_str_tbl"
72+
sql "select length(struct_element(struct_col, 'f3')) from slcp_str_tbl"
7373
// length() in both SELECT and WHERE: predicate must remain length(str_col) > 1,
7474
// never be rewritten to CAST(str_col AS int) > 1. Slot type must stay varchar.
7575
explain {

0 commit comments

Comments
 (0)