How to achieve a multi-dimensional description of attributes in a triple?

We now have a triple: uid name “jack”. The requirement is: we want to add metadata to describe this triple, for example: this triple comes from different databases, but in our application we only want to use jack as the attribute of uid. How to describe the source of attribute jack? If you use facts, you can only describe one source, such as uid name “jack” (source = “database1”), we need to describe multiple sources in this case, such as uid name “jack” (source = “database1”, source_2 = “database2”), but in actual operation, we cannot define the number of sources because we cannot know the number of sources. Is there any way to achieve a multi-dimensional description of attributes in dgraph?

You could make custom trees.

{
   "set":[
      {
         "databases_tree":[
            {
               "name":"database1",
               "uid":"_:database1"
            },
            {
               "name":"database2",
               "uid":"_:database2"
            }
         ]
      },
      {
         "name":"jack",
         "source":[
            {
               "uid":"_:database1"
            },
            {
               "uid":"_:database2"
            }
         ]
      }
   ]
}

This example above would be for the origin of the entity.

The sample below would be to determine the relationship of each attribute. I’m using 0 or 1 to define “true or false”. You can define what suits you better.

{
   "set":[
      {
         "databases_tree":[
            {
               "name":"database1",
               "uid":"_:database1"
            },
            {
               "name":"database2",
               "uid":"_:database2"
            }
         ]
      },
      {
         "name":"Jack",
         "age":"31",
         "city":"San Francisco",
         "source":[
            {
               "uid":"_:database1",
              "source|name": "1",
              "source|age": "0",
              "source|city": "1"
            },
            {
               "uid":"_:database2",
              "source|name": "0",
              "source|age": "1",
              "source|city": "1"
            }
         ]
      }
   ]
}

Query

{
  q(func: eq(name, "Jack")){
    name
    age
    city
    source @facets {
      name
    }
  }
}

You can also filter like so (“I wanna know what attributes come from database1”)

{
  q(func: eq(name, "Jack")){
    name
    age
    city
    source @filter(eq(name, "database1")) @facets {
      name
    }
  }
}

Result

From the first query

{
  "data": {
    "q": [
      {
        "name": "Jack",
        "age": "31",
        "city": "San Francisco",
        "source": [
          {
            "name": "database1",
            "source|age": "0",
            "source|city": "1",
            "source|name": "1"
          },
          {
            "name": "database2",
            "source|age": "1",
            "source|city": "1",
            "source|name": "0"
          }
        ]
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 79419,
      "processing_ns": 20825753,
      "encoding_ns": 31606,
      "assign_timestamp_ns": 473431,
      "total_ns": 21513902
    },
    "txn": {
      "start_ts": 10021
    },
    "metrics": {
      "num_uids": {
        "age": 1,
        "city": 1,
        "name": 3,
        "source": 1
      }
    }
  }
}

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