Data modelling: customer, product and subscription tables

Hi,

I have three tables, customer, product and subscription.

In dgraph, customer and prodcut tables are nodes with scalar values (e.g., name, sex, addr., etc); subscription will be links/edges/predicate between customers and products. A customer can have multiple subscriptions for the same product, i.e., there can be multiple links/predicate between a given customer and product. The attribute/facets of the link/predicate are different. For instance, subscription start and end dates are possible attributes/facets. These attributes/facets are sort of the key referring the link.

I have some questions to model this:

  • Is this the correct way to model these kind of tables ?
  • How to create multiple links between two nodes ? I could not add multiple predicates for a given customer and product. Does dgraph support multiple predicates ?
  • Can facets on predicate be list of string or int ?
    **Answer from Sai (slack) No…current support is only one value. But you can use the index and append to the facet and add multiple facets (like color1=red, color2=orange etc) **

If list[date] or list[str] is allowed on edge uid predicate, then subscription history can be modeled using single link but attribute list instead of multiple links. Of course in this case, the order of list has to be maintained.

Regarding to appending multiple facets (Sai suggestion), how is query performed and how efficient is the query ? Let’s assume that predicate is subscription date, we have date1=2016-01-01, date2=2015-01-01, … daten=2018-01-01. How can I aggregate how many times the customer has subscribed the product between 2016-2018?

Or should I model other way?
All kinds of suggestions are welcome.

How you model your data would depend a lot on the kind of queries that you want to do. Facets are good for retrieval but not suggested if you want to filter or sort using them. I will still try to answer these questions.

Since this is the case, and multiple facets are not supported on an edge, you should have an intermediate subscription node.

<customer_uid> <subscription> _:s1 .
_:s1 <product> <product_uid> . 

Whether you add start and end date as facets or as edges would depend on what you plan to do with them.

Dgraph does support multiple predicates between two nodes. In the example below, friend and son are predicates between the same set of nodes.

<person_uid> <friend> <person_2_uid> .
<person_uid> <son> <person_2_uid> .

As Sai suggested, facets cannot be of list type.

Sorry, can you elaborate more about what you are trying to do here?

Facets are not suited for doing aggregations, filtering or sorting. You should have these values attached to a node to do these operations efficiently.

Happy to answer more questions.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.