`split_part` with position 0 errors on a NULL string only when the position is a literal

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

Los mantenedores suelen responder en 1 día

@sohailshk ya está trabajando en esto.

Desde el 12/11/2026.

  • #27352 de @sohailshk — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust, sql

Línea de trabajo

Start with datafusion/functions/src/string/split_part.rs, especially the fast path and the array path identified in the issue, then review the expr.slt case around the reported test. Decide how the fast path should behave when every string is NULL, using the stated PostgreSQL strictness expectation and the prior review discussion as context. Update the regression test to reflect the chosen behavior and verify the literal and column position cases agree.

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

Descripción

bug

Describe the bug

split_part(s, delimiter, 0) on a row where s is NULL returns NULL when the position comes from a column, and errors with "field position must not be zero" when the position is a literal. The fast path for an array string with a scalar delimiter and position rejects position 0 before it looks at any row. The array path skips rows where any argument is NULL, so it errors only on a row whose three arguments are all non-NULL. The two paths disagree whenever no row has a non-NULL string, such as a batch whose strings are all NULL.

To Reproduce

-- Literal delimiter and position: the fast path
SELECT split_part(s, '.', 0) AS r FROM (VALUES (NULL::text)) AS t(s);
-- Execution error: field position must not be zero

-- The same row with the position from a column: the array path
SELECT split_part(s, '.', p) AS r FROM (VALUES (NULL::text, 0)) AS t(s, p);
-- NULL

-- Only literals
SELECT split_part(NULL::text, '.', 0) AS r;
-- NULL

Expected behavior

All three return NULL. PostgreSQL's split_part is strict: its pg_proc entry leaves proisstrict at its default of true, so a NULL argument returns NULL without calling the function.

expr.slt expects the first query's error ("Position 0 with column input errors even for empty/null inputs"), while the review of #21238 asked for the fast path to match the array path (discussion_r3030106101). Which behavior is intended? If it is NULL, the fast path could return all NULLs when the string array has no valid row before checking the position, and the expr.slt case would expect NULL.

Additional context

Property-based tests found this on main at 14b3edd9a3: calling split_part with an array string and scalar delimiter and position gave an error, and the same call with every argument as an array gave NULL. The reproduction runs on main at 14b3edd9a3. The fast path came with #21238.

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.