sandugood commented on code in PR #22134:
URL: https://github.com/apache/datafusion/pull/22134#discussion_r3656566317


##########
datafusion/functions-window/src/lead_lag.rs:
##########
@@ -649,17 +771,44 @@ impl PartitionEvaluator for WindowShiftEvaluator {
         values: &[ArrayRef],
         _num_rows: usize,
     ) -> Result<ArrayRef> {
-        // LEAD, LAG window functions take single column, values will have 
size 1
+        // LEAD, LAG window functions take single column, values will have 
size:
+        // '1' - when default_value is a ScalarValue (or we simply did not 
specify it)
+        // '2' - when default_value is a PhysicalExpr
         let value = &values[0];
-        if !self.ignore_nulls {
-            shift_with_default_value(value, self.shift_offset, 
&self.default_value)
-        } else {
-            evaluate_all_with_ignore_null(
-                value,
-                self.shift_offset,
-                &self.default_value,
-                self.is_lag(),
-            )
+        match &self.default_value {
+            DefaultValue::Literal(scalar) => {
+                if !self.ignore_nulls {
+                    shift_with_default_value(value, self.shift_offset, 
&scalar.clone())
+                } else {
+                    evaluate_all_with_ignore_null(
+                        value,
+                        self.shift_offset,
+                        &scalar.clone(),
+                        self.is_lag(),
+                    )
+                }
+            }
+            DefaultValue::Expression => {
+                let default_array = values.get(1).cloned().unwrap_or_else(|| {
+                    Arc::new(arrow::array::NullArray::new(value.len()))
+                });
+                let default_array = if default_array.data_type() != 
value.data_type() {
+                    arrow::compute::kernels::cast::cast(&default_array, 
value.data_type())
+                        .map_err(|e| arrow_datafusion_err!(e))?
+                } else {
+                    default_array
+                };

Review Comment:
   Moved it to the `expressions()` method of the WindowShift



-- 
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]

Reply via email to