Compiled Cypher on Postgres: apply =~'s two pattern rewrites in drivine4j's order
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start at drivine/cypher/sql/postgres_cypher_compiler.py:589, in matches, and compare the two regexp_replace calls with the order shown in the issue. Swap their order so anchoring happens first. Check the compiled SQL for the example pattern and confirm the spec statements produce the same text as the other Drivine libraries.
Written by the indexing model from the issue text.
Description
A tidy-up. The results are the same; only the SQL text differs from drivine4j's.
I compiled the 998 statements of the Cypher spec at v0.6.18 with drivine4j (main, 3c5c4e5a), Drivine for TypeScript (master, e5b5d2b) and this library (main, a684245). On Postgres, =~ is the one place where this library alone writes different text from the other two.
What happens: matches (drivine/cypher/sql/postgres_cypher_compiler.py:589) first adds the w flag, when the flags hold both s and m, and then anchors the pattern:
regexp_replace(regexp_replace(<pattern>, '^\(\?([a-z]*(s[a-z]*m|m[a-z]*s)[a-z]*)\)', '(?\1w)'), '^(\(\?([a-z]+)\))?(.*)$', '(?p\2)\\A(\3)\\Z')
drivine4j (PostgresCypherCompiler.kt:416) and Drivine for TypeScript (PostgresCypherCompiler.ts:503) anchor first and then add the w:
regexp_replace(regexp_replace(<pattern>, '^(\(\?([a-z]+)\))?(.*)$', '(?p\2)\\A(\3)\\Z'), '^\(\?([a-z]*(s[a-z]*m|m[a-z]*s)[a-z]*)\)', '(?\1w)')
Both orders turn (?sm)a.b into (?psmw)\A(a.b)\Z. A pattern without both flags gets no w either way. So the results are the same, and the spec passes here. This shows up in 11 spec statements, for example RETURN 'a\nb' =~ '(?ims)A$.^B'.
Why bother: with the same text, a compile of the spec compares byte for byte across the libraries, so a real difference stands out. These 11 are about a quarter of the 41 Postgres statements where the two ports' SQL differs.
A fix: swap the two regexp_replace calls in matches, so the pattern is anchored first, as drivine4j does.
A tidy-up, so it goes in Next release + 2.
- Dominant language
- Python
- Stars
- 1
- Forks
- 0
- Avg merge
- 1h 32m
- Merged PRs (30d)
- 149
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from liberation-data/drivine-python
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
liberation-data/drivine-python#363 ·
Maintainers usually reply within 1 day
-
Docs: drivine4j doesn't read the flat DATABASE_* variables, as 02-connecting.md and design.md sayOpendocumentation
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
liberation-data/drivine-python#361 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
liberation-data/drivine-python#209 ·
Maintainers usually reply within 1 day
-
CI: three Oracle-only tests in test_cypher_compiled.py never run, as -k oracle doesn't select themOpen
Difficulty 1/5 Under an hour Newbie friendliness 88/100
liberation-data/drivine-python#178 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 40/100
liberation-data/drivine-python#366 ·
Maintainers usually reply within 1 day
All issues in liberation-data/drivine-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Nixtla/mlforecast#823 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
microsoft/ML-For-Beginners#1061 ·
-
bot-found documentation priority: P3
Difficulty 2/5 Under an hour Newbie friendliness 82/100
madenvel/KalinkaPlayer#503 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
EleutherAI/lm-evaluation-harness#4508 ·
Maintainers usually reply within 1 day