[Bug] array_sort's second comparator argument takes the first argument's name: a nested lambda reads the wrong argument, and alias functions sort nothing
Les mainteneurs répondent en général sous 1 jour
@adarshomrey y travaille déjà.
Depuis le 1/11/2026.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 82/100
Piste de recherche
Localisez la classe ExpressionTranslator où les objets ColumnRefExpr du comparateur de array_sort sont construits. Ajoutez column2.setName(arrayItemReference.getName()); comme indiqué dans le diff. Vérifiez en exécutant les exemples SQL : la fonction d'alias doit renvoyer un tableau trié et le lambda imbriqué doit être rejeté.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Search before asking
- I had searched in the issues and found no similar issues.
Version
master and branch-4.1 (the translator code is the same on both). Reproduced on a 4.1 build that includes the nested-lambda capture changes (#68062, #68471).
What's wrong?
ExpressionTranslator builds the ColumnRef of array_sort's second comparator argument as a copy of the first one, and keeps the first argument's name:
ColumnRefExpr column2 = new ColumnRefExpr(column);
column2.setColumnId(1);
That causes two wrong results.
1. A nested lambda in the comparator reads the wrong argument. The BE identifies comparator arguments by name when it rejects a nested lambda that captures one, and both arguments are named after the first. So a nested lambda that re-declares the first argument's name and reads the second passes that check. At run time it reads its own argument instead, the comparator returns a constant, and the array comes back unsorted with no error:
select array_sort((x, y) -> if(array_contains(array_map(x -> x < y, array(x)), true), -1, 1), [3, 1, 2]);
-- returns [3, 1, 2]
2. Alias functions with an array_sort comparator sort nothing, even with a flat comparator. CREATE ALIAS FUNCTION stores the translated expression and rebuilds the function from it, so both comparator arguments come back under the first name, as (x, y) -> ... (x < x) ...:
CREATE ALIAS FUNCTION db.asc_sort(ARRAY<INT>) WITH PARAMETER(arr)
AS array_sort((x, y) -> IF(x < y, -1, IF(x = y, 0, 1)), arr);
select db.asc_sort([3, 1, 2]);
-- returns [3, 1, 2]
The same comparator in a plain query returns [1, 2, 3].
What you expected to happen
- The first query is rejected, like any nested lambda that captures a comparator argument (
array_sort comparator does not support nested lambda capturing comparator argument 'y'). - The alias returns
[1, 2, 3].
How to reproduce
Run the statements above.
Anything else?
Fix: give the second ColumnRef its own name. The comparator frame is position-based (column ids 0 and 1), so flat comparators in queries are unaffected:
arrayItemReference = lambda.getLambdaArgument(1);
ColumnRefExpr column2 = new ColumnRefExpr(column);
+ column2.setName(arrayItemReference.getName());
column2.setColumnId(1);
With that change, query 1 is rejected with the error above, and a flat comparator still sorts [3, 1, 2] to [1, 2, 3]. Aliases created before the fix keep the stored broken body until they are dropped and recreated.
Related: #68977
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
- Langage dominant
- Java
- Étoiles
- 16.2k
- Forks
- 4k
- Merge moyen
- 1 j 16 h
- PR mergées (30 j)
- 679
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de apache/doris
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
apache/doris#69863 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
[Bug] Upper-case hex in cloud initial rowset id is mis-parsed by BE from_hex (lossy, non-unique RowsetId)Peut-être pris @siddiqueirshad l’a pris il y a 4 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
apache/doris#69371 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
[Doc] 官方文档中 S3 路径风格访问参数错误 (s3.use_path_style)Peut-être pris @wy471x l’a pris il y a 9 jours. Ouverte
Difficulté 2/5 Moins d'une heure Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 Une demi-journée Accessibilité débutants 70/100
Les mainteneurs répondent en général sous 1 jour
-
4.1.4.1 Release NoteOuverterelease notes
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de apache/doris
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
intellij-elixir/intellij-elixir#4585 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
MetricsHub/metricshub-community#1474 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
adorsys/keycloak-config-cli#1742 ·
Les mainteneurs répondent en général sous 1 jour
-
Booking links: POST /api/booking-links with a null element in "availabilityRules" throws NullPointerException and answers 500 instead of 400Peut-être pris @chibenwa l’a pris aujourd’hui. Ouverteai-driven-fuzzing bug claude Minor
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
linagora/twake-calendar-side-service#1322 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
PathnameExpander incorrectly interprets regex metacharacters in wildcard patternsPeut-être pris @jiteshkhatri11 l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
javapathfinder/jpf-core#662 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour