Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Cypher on SQL stores: floats near the bottom of a double's range become 0.0 or null

Aperta
#118 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
postgresql, python
Ambito
backend, databases

Direzione di ricerca

Start with OracleCypherCompiler.number and float_ in drivine/cypher/sql/oracle_cypher_compiler.py, then trace the avg, round, and sqrt call sites in drivine/cypher/sql/sql_cypher_compiler.py; inspect Postgres's numeric and float_ handling for avg as well. Add integration coverage in tests/integration/test_cypher_compiled.py for the six listed statements on Postgres and Oracle, and confirm the results preserve the expected tiny double values.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Port of liberation-data/drivine4j#229.

What happens here: floats near the bottom of a double's range are lost on the SQL stores. On main (d4932f7), through the cypher_pm fixture with QuerySpecification(cypher_statement(...)):

Statement Neo4j Postgres Oracle
RETURN 1e-300 / 1e300 [0.0] [0.0] [None]
RETURN 5e-324 * 0.6 [5e-324] [5e-324] [0.0]
RETURN 1e-310 / 3 [3.333333333333e-311] [3.333333333333e-311] [0.0]
RETURN sqrt(1e-320) [9.99994433575849e-161] [1e-160] [0.0]
RETURN round(1e-320, 400) [1e-320] [1e-320] [0.0]
UNWIND [5e-324, 0.0, 0.0] AS x RETURN avg(x) [5e-324] [0.0] [0.0]

So on Oracle all six lose the value, and on Postgres avg does. Postgres's sqrt(1e-320) giving 1e-160 rather than the double's 9.99994433575849e-161 is numeric's digits, which #91 already covers.

Where:

  • Oracle, arithmetic: the same cause as #117 (drivine4j#226). OracleCypherCompiler.arithmetic (drivine/cypher/sql/oracle_cypher_compiler.py:252-259) converts each side with TO_BINARY_DOUBLE, but reads it first through number (:135-138), which is JSON_VALUE(x, '$' RETURNING NUMBER). NUMBER's least magnitude is about 1e-130 and its greatest about 1e126, so 1e-300, 1e-310 and 5e-324 become 0 and 1e300 becomes None before the double operation runs.
  • Oracle, sqrt, round and avg: the same NUMBER read, at call sites #117 doesn't name. avg (drivine/cypher/sql/sql_cypher_compiler.py:3236-3237), round (:3301-3312) and sqrt (:3313-3314) each read their argument through self.number, and only the result is turned back into a double, by float_ (drivine/cypher/sql/oracle_cypher_compiler.py:158-159). A fix to arithmetic alone leaves these; a fix to number (or a BINARY_DOUBLE read where the value is a double) covers all of them.
  • Postgres, avg: avg (drivine/cypher/sql/sql_cypher_compiler.py:3237) averages number's numeric (drivine/cypher/sql/postgres_cypher_compiler.py:79-82), and numeric's division keeps too few digits for 5e-324 / 3, so the average is 0 before float_ (:93-96) casts it. #91's fix (float_ through double precision) doesn't reach this, as the value is already 0 in numeric.

Expected: a double operation keeps double precision down to the subnormals, as Neo4j does: the Neo4j column above.

Tests to port: whatever drivine4j adds for #229. The six statements above make a direct test on Postgres and Oracle in tests/integration/test_cypher_compiled.py; SQLite isn't a store here yet.

Related: #117, #91.

Lingua principale
Python
Stelle
1
Fork
0
Merge medio
1h 19m
PR unite (30g)
122

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di liberation-data/drivine-python

Tutte le issue di liberation-data/drivine-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.