kosiew commented on code in PR #27313:
URL: https://github.com/apache/datafusion/pull/27313#discussion_r4767569957


##########
datafusion/functions-window/src/lead_lag.rs:
##########
@@ -597,6 +597,9 @@ impl PartitionEvaluator for WindowShiftEvaluator {
         range: &Range<usize>,
     ) -> Result<ScalarValue> {
         let array = &values[0];
+        if self.shift_offset == 0 {

Review Comment:
   Optional: document that `get_range` returns `idx..idx + 1` for offset zero, 
so `range.start` selects the current row and preserves NULL without applying 
the default.



##########
datafusion/sqllogictest/test_files/window_lead_lag_zero_offset.slt:
##########
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: Apache-2.0
+# SPDX-FileCopyrightText: See the NOTICE file distributed with this work for 
additional information regarding copyright ownership
+# SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under 
one or more contributor license agreements
+
+# Zero-offset LEAD/LAG returns the current value, including NULL, with or 
without IGNORE NULLS
+query IIIIII
+SELECT id, v,
+       LEAD(v, 0, -7) IGNORE NULLS OVER (ORDER BY id),
+       LAG(v, 0, -7) IGNORE NULLS OVER (ORDER BY id),
+       LEAD(v, 0, -7) OVER (ORDER BY id),
+       LAG(v, 0, -7) OVER (ORDER BY id)
+FROM (VALUES (1, 10), (2, NULL), (3, 30)) AS t(id, v)
+ORDER BY id;
+----
+1 10 10 10 10 10
+2 NULL NULL NULL NULL NULL
+3 30 30 30 30 30
+
+# Zero-offset LEAD/LAG IGNORE NULLS ignores defaults in either sort direction
+query IIIIIIIIII
+SELECT id, v,
+       LEAD(v, 0, -7) IGNORE NULLS OVER (ORDER BY id),

Review Comment:
   Optional: remove the two ascending expressions with explicit defaults 
already covered by the first query. Retain the ascending omitted-default pair 
and both descending pairs, remove the corresponding expected cells, and change 
the query header to eight `I`s.



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