Restricting a union by dj.Top produces invalid SQL
Mantenedores costumam responder em até 6 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- Meio dia
- Facilidade para iniciantes
- 75/100
Direção de pesquisa
Start in Union.make_sql in expression.py around line 1437, where the derived-table alias is built as f"_u{n}{self.sorting_clauses()}", so ORDER BY and LIMIT land inside the quoted identifier. Run the reproducer from the issue on MySQL or PostgreSQL to see the syntax error. Move the sorting and limit clauses after the alias, and also make the secondary-attribute branch (around lines 1444-1446) honor _top. Done when (A + B) & dj.Top(3, "t_id DESC") returns [7, 8, 9] on both backends.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
(A + B) & dj.Top(...) fails with an SQL syntax error on both backends.
Reproduced on master @ 3c912c46 against MySQL 8.0 and PostgreSQL 16. Connection via DJ_HOST/DJ_USER/DJ_PASS/DJ_BACKEND. Found while benchmarking subquery pruning (#1665).
Reproducible example
import datajoint as dj
schema = dj.Schema("repro_union_top")
@schema
class T(dj.Manual):
definition = """
t_id : int32
"""
@schema
class A(dj.Manual):
definition = """
-> T
"""
@schema
class B(dj.Manual):
definition = """
-> T
"""
T.insert([(i,) for i in range(10)], skip_duplicates=True)
A.insert([(i,) for i in range(0, 6)], skip_duplicates=True)
B.insert([(i,) for i in range(4, 10)], skip_duplicates=True)
q = (A + B) & dj.Top(3, "t_id DESC")
print(sorted(r["t_id"] for r in q.to_dicts())) # expected: [7, 8, 9]
Actual
MySQL:
datajoint.errors.QuerySyntaxError: You have an error in your SQL syntax; ... near 't_id` DESC LIMIT 3`' at line 1
PostgreSQL:
datajoint.errors.QuerySyntaxError: syntax error at or near "t_id"
LINE 1: ...d" FROM "repro_union_top"."b")) as "_u0 ORDER BY "t_id" DESC...
Expected
[7, 8, 9].
Cause
Union.make_sql (expression.py:1437) builds the derived-table alias as f"_u{n}{self.sorting_clauses()}". ORDER BY ... LIMIT therefore ends up inside the quoted alias identifier. The ORDER BY/LIMIT should go after the alias instead.
The union form with secondary attributes (:1444-1446) ignores _top altogether.
- Linguagem predominante
- Python
- Estrelas
- 198
- Forks
- 103
- Merge médio
- 6d 1h
- PRs com merge (30d)
- 10
Preparar o ambiente
- Inclui um Dockerfile ou arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de datajoint/datajoint-python
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
datajoint/datajoint-python#1703 ·
Mantenedores costumam responder em até 6 dias
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
datajoint/datajoint-python#1702 ·
Mantenedores costumam responder em até 6 dias
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
datajoint/datajoint-python#1701 ·
Mantenedores costumam responder em até 6 dias
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
datajoint/datajoint-python#1691 ·
Mantenedores costumam responder em até 6 dias
-
dependencies needs-discussion
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
datajoint/datajoint-python#1687 ·
Mantenedores costumam responder em até 6 dias
Todas as issues de datajoint/datajoint-python
Issues semelhantes
-
needs-triage
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 85/100
gke-labs/kube-agents#6620 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
open-webui/open-webui#34719 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
cognition
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia
-
One non-object JSON record makes the session catalog exitTalvez já em andamento @he-yufeng assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 78/100
collabnix/awesome-mcp-lists#433 ·
Mantenedores costumam responder em até 4 dias