Support [bool] list predicates and JSON arrays of booleans

Aperta
#9,897 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 10 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend, database

Direzione di ricerca

Start with the list-type check in schema/parse.go, which rejects [bool] alongside [password], and the []interface{} item switch in mapToNquads in chunker/json_parser.go, which must be checked in both ParseJSON and FastParseJSON. Done means p: [bool] . parses, a JSON array of booleans is accepted, and [password] is still refused. The author's test names (TestParseScalarListEveryStoreType, TestNquadsFromJsonBoolList) show what to cover, but the false-as-delete-all behaviour needs a maintainer decision first.

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

Descrizione

What happens. Two places refuse a list of booleans:

  1. The schema parser refuses p: [bool] . with Unsupported type for list: [bool].
    (schema/parse.go, the schema.List check names PasswordID and BoolID).
  2. The JSON mutation parser refuses a JSON array of booleans, whatever the schema:
    {"set": {"uid": "_:a", "p": [true, false]}} gives got unsupported type for list: p
    (chunker/json_parser.go, mapToNquads: the []interface{} branch accepts string,
    float64, json.Number and int64 items, not bool), in both ParseJSON and
    FastParseJSON.

Dgraph's GraphQL layer refuses [Boolean] with the comment "[Boolean] is not allowed as
dgraph schema doesn't support [bool] yet" (graphql/schema/rules.go:724), which reads as
a missing feature rather than a design decision.

Why it matters. A multi-valued boolean is ordinary in RDF and OWL data: OWL 2 lets a
data property that is not functional relate a subject to both true and false. A
schema generated from such a model has no way to store it in Dgraph except as a string or
int list, which loses the boolean type for comparison and output.

Proposed change (what our fork runs). Remove BoolID from the list check in
schema/parse.go (keep PasswordID), and add bool to the two item type cases of the
[]interface{} branch in chunker/json_parser.go. Nothing else was needed in our
testing: a list value's posting UID is the fingerprint of the value after conversion to the
schema type (posting/list.go fingerprintEdge), so "true", "1", "T" and true are
one stored value; count(), has(), eq() in a filter and with the bool index at the
root, deletes of one value, the admin JSON export (one record per value, schema line
<p>:[bool] @count), and dgraph live and dgraph bulk loading that export all behaved
as for other scalar lists. The admin RDF export was not tried. Sorting by a [bool] is refused like sorting by any
list.

Behaviour to be aware of. In a JSON delete, false is read as "every value"
(handleBasicType, as 0 and null), so {"delete": {"uid": X, "p": false}} on a
[bool] holding both values removes both. Deleting one value works with the string
"false" or RDF. We kept the convention and documented it; upstream may want to decide
whether false inside an array ("p": [false]) should be star.

Tests we added (can be offered with the change): schema/parse_test.go
TestParseScalarListEveryStoreType (string, int, float, bool, datetime lists parse;
[password] still refused); chunker/json_bool_list_test.go
(TestNquadsFromJsonBoolList, TestNquadsFromJsonBoolDeleteFalseIsStar).

Compatibility. No stored data changes. A store holding a [bool] predicate opened by
a binary without the change still reads it (the stored schema is not re-parsed), but that
binary refuses the schema text, so an Alter or export/restore round trip through it fails.

Lingua principale
Go
Stelle
21.8k
Fork
1.6k
Merge medio
11g 7h
PR unite (30g)
5

Preparare l'ambiente

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 dgraph-io/dgraph

Tutte le issue di dgraph-io/dgraph

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.