Restricting a union by dj.Top produces invalid SQL
維護者通常 6 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 半天
- 新手友好度
- 75/100
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
(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.
- 主要語言
- Python
- 星號
- 198
- 分支
- 103
- 平均合併
- 6 天 1 小時
- 30 天內合併 PR
- 10
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
datajoint/datajoint-python 的其他 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
datajoint/datajoint-python#1703 ·
維護者通常 6 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
datajoint/datajoint-python#1702 ·
維護者通常 6 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
datajoint/datajoint-python#1701 ·
維護者通常 6 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 74/100
datajoint/datajoint-python#1691 ·
維護者通常 6 天內回覆
-
dependencies needs-discussion
難度 2/5 1-3 小時 新手友好度 68/100
datajoint/datajoint-python#1687 ·
維護者通常 6 天內回覆
查看 datajoint/datajoint-python 的全部 Issue
相似的 Issue
-
needs-triage
難度 1/5 1-3 小時 新手友好度 85/100
gke-labs/kube-agents#6620 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
open-webui/open-webui#34719 · 2 則留言 ·
維護者通常 1 天內回覆
-
cognition
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
One non-object JSON record makes the session catalog exit可能已有人在做 @he-yufeng 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 78/100
collabnix/awesome-mcp-lists#433 ·
維護者通常 4 天內回覆