`lpad` and `rpad` with a literal length above `i32::MAX` error on a NULL string or fill

Ouverte Adaptée aux débutants
#27,482 1 commentaire 0 réactions 1 personne assignée Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@TechWizard9999 y travaille déjà.

Depuis le 17/11/2026.

  • #27496 par @TechWizard9999 — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
77/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
rust
Domaine
backend, databases

Piste de recherche

Commence dans datafusion/functions/src/unicode/pad.rs et compare le chemin rapide pour les longueurs scalaires avec le traitement de NULL du chemin des tableaux. Vérifie les cas existants dans string_literal.slt et la correction connexe de split_part mentionnée dans l’issue. Le travail est terminé lorsque lpad et rpad renvoient NULL pour les longueurs littérales trop grandes dans les lignes où la chaîne ou le remplissage est NULL, tout en continuant à produire une erreur pour les lignes où les arguments concernés ne sont pas NULL.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Describe the bug

lpad(s, n) on a row where s is NULL and n is above i32::MAX errors when n is a literal, and returns NULL when n comes from a column. A NULL fill behaves the same, and so does rpad. The fast path for a scalar length rejects a length above i32::MAX before it looks at any row. The array path skips rows where any argument is NULL before it checks the length, so it errors only on a row whose string and fill are both non-NULL.

To Reproduce

-- Literal length: the fast path
SELECT lpad(s, 2147483648) AS r FROM (VALUES (NULL::text)) AS t(s);
-- Execution error: lpad requested length 2147483648 too large, maximum allowed length is 2147483647

-- The same row with the length from a column: the array path
SELECT lpad(s, n) AS r FROM (VALUES (NULL::text, 2147483648)) AS t(s, n);
-- NULL

-- A NULL fill with a literal length
SELECT lpad(s, 2147483648, f) AS r FROM (VALUES ('a', NULL::text)) AS t(s, f);
-- Execution error: lpad requested length 2147483648 too large, maximum allowed length is 2147483647

-- The same row with the length from a column
SELECT lpad(s, n, f) AS r FROM (VALUES ('a', 2147483648, NULL::text)) AS t(s, n, f);
-- NULL

The same four queries with rpad give the same results.

Expected behavior

All four return NULL, as the array path does. string_literal.slt already expects NULL for a NULL string or fill with a literal length in range, and #27352 made split_part's fast path return NULL in the same situation (#27276).

Could the fast path skip a length above i32::MAX, as it already skips one above MAX_SCALAR_TARGET_LEN, instead of returning the error? The array path would then return the error for the first row whose string and fill are non-NULL, and NULL for the other rows.

Additional context

Property-based tests found this on main at e2dc8b048b: one row of a call with an array of lengths returned NULL, and the same row called with every argument as a scalar returned the error. The reproduction runs on main at e2dc8b048b. The check in the fast path came with #20657 and moved to pad.rs in #26367.

Langage dominant
Rust
Étoiles
9.6k
Forks
2.6k
Merge moyen
3 j 5 h
PR mergées (30 j)
352

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de apache/datafusion

Toutes les issues de apache/datafusion

Issues similaires

Plus d'issues Rust

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.