dgraph-io / dgraph

The high-performance database for modern applications
https://dgraph.io
Other
20.44k stars 1.5k forks source link

[FEATURE]: Support Map types #9146

Open RJKeevil opened 2 months ago

RJKeevil commented 2 months ago

Use case

We have a number of use cases where having a map type predicate would simplify our usage of dgraph. A good example is real-world address node, which may have multiple known address strings that refer to that address (e.g. ["32 Heren Gracht, Amsterdam, 1015BA","32, Herengracht, Amsterdam, 1015BA, NL"]). We run the addresses through a parser to extract known features such as number, postcode, country etc. Storing these as separate properties is problematic as it loses the lineage/grouping (which house number goes with which postcode etc in the raw data). A map (or preferably, a set of maps) would allow such nested/grouped structures.

I know this could instead be modelled as child nodes, but that a) makes our logic much more complex, and b) doesnt model the data in a way suitable for client usage patterns. So for now we marshall maps backwards and forwards from strings to achieve this.

Links to Discuss, RFC or previous Issues and PRs

No response

Links to examples and research

https://docs.arcadedb.com/#DataTypes https://neo4j.com/docs/cypher-manual/current/values-and-types/maps/

Current state

As mentioned, can marshal to or from strings, or use child nodes, but both are suboptimal via perfomance overhead and query complexity

Solution proposal

Main complexity would be this will need a mechanism to query fields within maps. Perhaps libraries like https://github.com/elgs/jsonql can be of inspiration for what functionality may be of use here. For MVP just having a map object that i interact with client side would be already a big help.

Additional Information

No response

harshil-goel commented 2 months ago

Can you try storing the map as a list of bytes using default directive? Or just by using jq urself to store it as a string?

RJKeevil commented 2 months ago

Yes, that is essentially what I do. It works ok, but having true map support would be a good feature I think, especially if i could subquery them.