Support [bool] list predicates and JSON arrays of booleans

Abierto
#9,897 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 10 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
backend, database

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
21.8k
Forks
1.6k
Merge medio
11 d 7 h
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dgraph-io/dgraph

Todos los issues de dgraph-io/dgraph

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.