HuSen8891 commented on code in PR #12811:
URL: https://github.com/apache/datafusion/pull/12811#discussion_r1800472105
##########
datafusion/physical-plan/src/windows/mod.rs:
##########
@@ -257,31 +257,55 @@ fn create_built_in_window_expr(
}
}
BuiltInWindowFunction::Lag => {
- let arg = Arc::clone(&args[0]);
+ let mut arg = Arc::clone(&args[0]);
let shift_offset = get_scalar_value_from_args(args, 1)?
.map(get_signed_integer)
.map_or(Ok(None), |v| v.map(Some))?;
- let default_value =
- get_casted_value(get_scalar_value_from_args(args, 2)?,
out_data_type)?;
+ // If value is NULL, we use default data type as output data type,
no need to cast data type
+ let default_value = match out_data_type {
+ DataType::Null => match get_scalar_value_from_args(args, 2)? {
+ Some(value) => {
+ let null_value =
ScalarValue::try_from(value.data_type())?;
+ arg = Arc::new(Literal::new(null_value));
+ value
+ }
+ None => ScalarValue::try_from(DataType::Null)?,
+ },
+ _ => {
+ get_casted_value(get_scalar_value_from_args(args, 2)?,
out_data_type)?
+ }
+ };
Review Comment:
Thanks!Refactor the code as described above.
--
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]