Skip to content

Commit f3a476f

Browse files
committed
implement target type selection for range queries on dictionary data types
Fixes apache#13151
1 parent 132b232 commit f3a476f

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

datafusion/optimizer/src/analyzer/type_coercion.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,21 @@ fn coerce_frame_bound(
688688
}
689689
}
690690

691+
fn extract_window_frame_target_type(col_type: &DataType) -> Result<DataType> {
692+
if col_type.is_numeric()
693+
|| is_utf8_or_large_utf8(&col_type)
694+
|| matches!(col_type, DataType::Null)
695+
{
696+
Ok(col_type.clone())
697+
} else if is_datetime(&col_type) {
698+
Ok(DataType::Interval(IntervalUnit::MonthDayNano))
699+
} else if let DataType::Dictionary(_, value_type) = col_type {
700+
extract_window_frame_target_type(value_type)
701+
} else {
702+
return internal_err!("Cannot run range queries on datatype: {col_type:?}");
703+
}
704+
}
705+
691706
// Coerces the given `window_frame` to use appropriate natural types.
692707
// For example, ROWS and GROUPS frames use `UInt64` during calculations.
693708
fn coerce_window_frame(
@@ -703,18 +718,7 @@ fn coerce_window_frame(
703718
.map(|s| s.expr.get_type(schema))
704719
.transpose()?;
705720
if let Some(col_type) = current_types {
706-
if col_type.is_numeric()
707-
|| is_utf8_or_large_utf8(&col_type)
708-
|| matches!(col_type, DataType::Null)
709-
{
710-
col_type
711-
} else if is_datetime(&col_type) {
712-
DataType::Interval(IntervalUnit::MonthDayNano)
713-
} else {
714-
return internal_err!(
715-
"Cannot run range queries on datatype: {col_type:?}"
716-
);
717-
}
721+
extract_window_frame_target_type(&col_type)?
718722
} else {
719723
return internal_err!("ORDER BY column cannot be empty");
720724
}

0 commit comments

Comments
 (0)