[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
Los mantenedores suelen responder en 1 día
@adarshomrey ya está trabajando en esto.
Desde el 1/11/2026.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
Línea de trabajo
Localiza la clase ExpressionTranslator donde se construyen los objetos ColumnRefExpr del comparador de array_sort. Añade column2.setName(arrayItemReference.getName()); como se muestra en el diff. Verifica ejecutando los ejemplos SQL: la función de alias debe devolver un array ordenado y el lambda anidado debe ser rechazado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Java
- Estrellas
- 16.2k
- Forks
- 4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 671
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/doris
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
apache/doris#70000 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
apache/doris#69863 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Bug] Upper-case hex in cloud initial rowset id is mis-parsed by BE from_hex (lossy, non-unique RowsetId)Posiblemente ocupada @siddiqueirshad la tomó hace 5 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
apache/doris#69371 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Doc] 官方文档中 S3 路径风格访问参数错误 (s3.use_path_style)Posiblemente ocupada @wy471x la tomó hace 10 días. Abierto
Dificultad 2/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 Medio día Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
Todos los issues de apache/doris
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 3 días
-
A proxy that fails to start logs a RejectedExecutionException stack trace from its shutdown hookAbiertofollow-up
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Sanne/incus-spawn#1953 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Shweit/EtherealPortals#30 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 70/100
checkstyle/checkstyle#22398 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Typo in jakartaee-bom 12.0.0-SNAPSHOT with cdiPosiblemente ocupada @ElectLive la tomó hoy. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
jakartaee/jakartaee-api#205 · 1 comentario ·