LEAD/LAG with offset 0 and IGNORE NULLS returns the default for a NULL row, unlike the form without IGNORE NULLS

Abierto
#27,284 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@0xamlab ya está trabajando en esto.

Desde el 10/11/2026.

  • #27313 de @0xamlab — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
rust, sql

Línea de trabajo

Read datafusion/functions-window/src/lead_lag.rs, focusing on WindowShiftEvaluator::evaluate and the offset-zero path in evaluate_all_with_ignore_null. Start by checking the existing window function tests for LEAD and LAG with IGNORE NULLS; add coverage for offset 0 on a NULL current row. Done means both functions preserve NULL instead of returning the default, with the tests passing.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Describe the bug

lead(v, 0, d) and lag(v, 0, d) return the current row's own value. Without IGNORE NULLS a NULL row stays NULL. With IGNORE NULLS the default d replaces it.

To Reproduce
SELECT id,
       lead(v, 0, -7) OVER (ORDER BY id) AS lead_plain,
       lead(v, 0, -7) IGNORE NULLS OVER (ORDER BY id) AS lead_ignore_nulls,
       lag(v, 0, -7) OVER (ORDER BY id) AS lag_plain,
       lag(v, 0, -7) IGNORE NULLS OVER (ORDER BY id) AS lag_ignore_nulls
FROM (VALUES (1, 10), (2, NULL), (3, 30)) AS t(id, v)
ORDER BY id;

On 55.2.0 (datafusion-python 55.0.0):

| id | lead_plain | lead_ignore_nulls | lag_plain | lag_ignore_nulls |
| 1  | 10         | 10                | 10        | 10               |
| 2  | NULL       | -7                | NULL      | -7               |
| 3  | 30         | 30                | 30        | 30               |
Expected behavior

Row 2 should be NULL in all four columns. Offset 0 refers to the current row itself, so there is no row to skip and nothing out of range that would call for the default. Apache Spark 4.0 returns the row's own value (NULL) for lead(v, 0, -7) IGNORE NULLS, the same as without IGNORE NULLS.

Additional context

In datafusion/functions-window/src/lead_lag.rs the two code paths disagree on this input as written:

  • evaluate_all_with_ignore_null starts with if offset == 0 { return Ok(Arc::clone(array)) }, so a NULL stays NULL.
  • WindowShiftEvaluator::evaluate ends with "Set the default value if ... ignore nulls mode and current value is null", which turns a NULL current row into the default when the offset is 0.

Offsets of 1 or more are not affected by this; the offset 0 case is only reached by an explicit 0.

Separately, #25471 (fixed on main by #25472) covers LEAD with an offset of 2 or more returning wrong rows across NULL gaps. The published 55.2.0 crate still has the old code for that.

Lenguaje dominante
Rust
Estrellas
9.6k
Forks
2.6k
Merge medio
3 d 4 h
PR fusionados (30 d)
345

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/datafusion

Todos los issues de apache/datafusion

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.