Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Compiled Cypher: a CALL subquery sees every outer variable, so an inner MATCH reusing an outer name joins to it instead of binding a new one

未关闭
#294 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
65/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
databases

调研方向

Start with drivine/cypher/ast/clause.py:83 and drivine/cypher/cypher_reader.py:226, then trace _called_part and _call_writing in drivine/cypher/sql/sql_cypher_compiler.py. Port the listed cross-engine tests and the five statements in CompilerRefusalTest; done means CALL subqueries see only their imports while procedure calls retain access to the whole row.

由索引模型根据 Issue 内容生成。

描述

bug

Port of liberation-data/drivine4j#410.

What happens here now. A compiled CALL { … } sees every variable of the row it is in, whatever it imports, so an inner MATCH that reuses an outer name joins to the outer variable instead of binding a new one:

MATCH (p:Person) CALL { MATCH (p:Movie) RETURN count(p) AS n } RETURN p.name, n
// Neo4j: 3 for each person    Postgres, Oracle, SQLite: 0
MATCH (a:Person {name: 'Keanu'}) CALL { MATCH ()-[a:KNOWS]->() RETURN count(a) AS n } RETURN a.name, n
// Neo4j: Keanu, 2    here: refused as "a relationship variable bound before its pattern"
MATCH (a:N) CALL () { CREATE (a:N {made: true}) RETURN 1 AS x } RETURN x
// Neo4j: makes a new node for each row    here: refused as bound already (without labels: joins the row's a and makes nothing)

Where:

  • drivine/cypher/ast/clause.py:83: Call keeps no import list, and drivine/cypher/cypher_reader.py:226 drops the brackets of CALL (a, b) { … }, CALL () { … } and CALL (*) { … }.
  • drivine/cypher/sql/sql_cypher_compiler.py:1496 (_called_part): the inner query is _Select(select.scope), every variable of the row (line 1503), _imports_apart gets the whole scope (line 1504), and each clause is read with select.scope as its outer scope (line 1511), so a variable stays seen even after a WITH within the call that doesn't pass it on.
  • drivine/cypher/sql/sql_cypher_compiler.py:2373 (_call_writing): self._rows() binds every variable of the row, and _imported() (line 5957) drops a leading importing WITH without narrowing to what it names.

What the fix in drivine4j does (liberation-data/drivine4j#410):

  • keeps the brackets in the AST (imports, importsAll, from drivine4j#451);
  • works out what a CALL imports: its brackets' names, each with (*), none with (); with no brackets, the variables its leading WITH passes on as they are, each with WITH *, and none where it has no leading WITH;
  • calledPart (_called_part here) builds the call's query over the imported variables alone, gives importsApart only those, and reads its clauses with no outer scope, so an import a WITH in the call doesn't pass on is gone after it;
  • callWriting (_call_writing here) narrows the row's kinds to the imports before reading each row, and skips the leading WITH only where it passes on each import;
  • a procedure's CALL db.labels() YIELD label WHERE … still sees the whole row, as its WHERE may read any variable around it (a procedure flag on the call).

Every spec statement and TCK query compiled to the same SQL before and after on each store there.

Tests to port: drivine4j's CypherQueryCrossEngineTest "a CALL sees only the variables it imports, and a name it does not import is a new variable in it", CypherWriteCrossEngineTest "a CALL that writes sees only the variables it imports, so a CREATE of a name it does not import makes a new node", and the five #410 statements added to the accepted list in CompilerRefusalTest (two moved there from the refused list). Rows are Neo4j 2026.10's.

主要语言
Python
星标
1
派生
0
平均合并
1 小时 29 分钟
30 天内合并 PR
136

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

liberation-data/drivine-python 的其他 Issue

查看 liberation-data/drivine-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。