superphy / prairiedog

next-gen pangenome graphs for predictive genomics
Other
0 stars 0 forks source link

Support graph queries in dgraph #115

Closed kevinkle closed 4 years ago

kevinkle commented 4 years ago
{
  set {
    _:a <km> "ATCG" .
    _:b <km> "ATCC" .
    _:a <fd> _:b (type="a", value=1) .
  }
}
{
  class(func: has(km)) {
    km
  }
}

returns

{
  "extensions": {
    "server_latency": {
      "parsing_ns": 20616,
      "processing_ns": 56538535,
      "encoding_ns": 1186852
    },
    "txn": {
      "start_ts": 35
    }
  },
  "data": {
    "class": [
      {
        "km": "ATCG",
        "uid": "0x3"
      },
      {
        "km": "ATCC",
        "uid": "0x4"
      }
    ]
  }
}

so we need to prefetch uids

kevinkle commented 4 years ago

Add re-running the mutation gives us new nodes in the db, so ya.

{
  "extensions": {
    "server_latency": {
      "parsing_ns": 18856,
      "processing_ns": 2261523,
      "encoding_ns": 1030873
    },
    "txn": {
      "start_ts": 40
    }
  },
  "data": {
    "class": [
      {
        "km": "ATCG",
        "uid": "0x3"
      },
      {
        "km": "ATCC",
        "uid": "0x4"
      },
      {
        "km": "ATCG",
        "uid": "0x5"
      },
      {
        "km": "ATCC",
        "uid": "0x6"
      }
    ]
  }
}
kevinkle commented 4 years ago

I wonder how this works with bulk load

kevinkle commented 4 years ago

Looks like we might be fine with blank nodes split into multiple rdf files per Sharded UID Map section in https://blog.dgraph.io/post/bulkloader/

kevinkle commented 4 years ago
{
  q(func: eq(km, "ATCG")){
    fd @facets(eq(type, "a") AND eq(value, 1)){
      uid
    }
  }
}
kevinkle commented 4 years ago
{
  q(func: eq(km, "ATCG")){
    fd @facets(eq(type, "a") AND eq(value, 1))
      @filter(eq(km, "ATCC"))
      {
      uid
    }
  }
}
kevinkle commented 4 years ago
{
  set{
    _:a <km> "AAAA" .
    _:b <km> "BBBB" .
    _:c <km> "CCCC" .
    _:a <fd> _:b (type="a", value=1) .
    _:b <fd> _:c (type="a", value=2) .
  }
}
{
  set{
    _:a <km> "AAAA" .
    _:b <km> "BBBB" .
    _:c <km> "CCCC" .
    _:a <fd> _:b (type="a", value=1) .
    _:b <fd> _:c (type="a", value=2) .
  }
}
{
  path as shortest(from: 0x4e22, to:0x4e21){
    fd
  }
  path(func: uid(path)) {
   km
 }
}
kevinkle commented 4 years ago
{
  set{
    _:a <km> "XXXX" .
    <0x4e22> <fd> _:a (type="b", value=1) .
    _:a <fd> <0x4e21> (type="b", value=2) .
  }
}
{
  path as shortest(from: 0x4e22, to:0x4e21){
    fd @facets(eq(type, "a"))
  }
  path(func: uid(path)) {
   km
 }
}

returns

{
  "extensions": {
    "server_latency": {
      "parsing_ns": 22227,
      "processing_ns": 2627869,
      "encoding_ns": 1228573
    },
    "txn": {
      "start_ts": 20063
    }
  },
  "data": {
    "path": [
      {
        "km": "AAAA"
      },
      {
        "km": "BBBB"
      },
      {
        "km": "CCCC"
      }
    ],
    "_path_": [
      {
        "fd": [
          {
            "fd": [
              {
                "uid": "0x4e21"
              }
            ],
            "uid": "0x4e23"
          }
        ],
        "uid": "0x4e22"
      }
    ]
  }
}
kevinkle commented 4 years ago
{
  path as shortest(from: 0x4e22, to:0x4e21){
    fd 
  }
  path(func: uid(path)) {
   km
    fd @facets(type, value){
      km
    }
 }
}
{
  "extensions": {
    "server_latency": {
      "parsing_ns": 23603,
      "processing_ns": 3462913,
      "encoding_ns": 1161420
    },
    "txn": {
      "start_ts": 20078
    }
  },
  "data": {
    "path": [
      {
        "km": "AAAA",
        "fd": [
          {
            "km": "BBBB",
            "fd|type": "a",
            "fd|value": 1
          },
          {
            "km": "XXXX",
            "fd|type": "b",
            "fd|value": 1
          }
        ]
      },
      {
        "km": "BBBB",
        "fd": [
          {
            "km": "CCCC",
            "fd|type": "a",
            "fd|value": 2
          }
        ]
      },
      {
        "km": "CCCC"
      }
    ],
    "_path_": [
      {
        "fd": [
          {
            "fd": [
              {
                "uid": "0x4e21"
              }
            ],
            "uid": "0x4e23"
          }
        ],
        "uid": "0x4e22"
      }
    ]
  }
}
kevinkle commented 4 years ago
{
  path as shortest(from: 0x4e22, to:0x4e21, numpaths:100){
    fd
  }
  path(func: uid(path)) {
   km
 }
}
{
  "extensions": {
    "server_latency": {
      "parsing_ns": 17427,
      "processing_ns": 2585440,
      "encoding_ns": 994625
    },
    "txn": {
      "start_ts": 20088
    }
  },
  "data": {
    "path": [
      {
        "km": "AAAA"
      },
      {
        "km": "BBBB"
      },
      {
        "km": "CCCC"
      }
    ],
    "_path_": [
      {
        "fd": [
          {
            "fd": [
              {
                "uid": "0x4e21"
              }
            ],
            "uid": "0x4e23"
          }
        ],
        "uid": "0x4e22"
      },
      {
        "fd": [
          {
            "fd": [
              {
                "uid": "0x4e21"
              }
            ],
            "uid": "0x4e24"
          }
        ],
        "uid": "0x4e22"
      }
    ]
  }
}
kevinkle commented 4 years ago
{
  q(func: eq(km, "AAAA")){
    fd @facets(eq(type, "a")) @facets(value)
  }
}
kevinkle commented 4 years ago
{
  q(func: has(km))@filter(uid_in(fd, 0x4e21)){
    uid
    km
    fd  @facets(type, value) {
      expand(_all_)
    } 
  }
}

returns

{
  "extensions": {
    "server_latency": {
      "parsing_ns": 22424,
      "processing_ns": 2967667,
      "encoding_ns": 1094799
    },
    "txn": {
      "start_ts": 20169
    }
  },
  "data": {
    "q": [
      {
        "uid": "0x4e23",
        "km": "BBBB",
        "fd": [
          {
            "km": "CCCC",
            "~fd": [
              {
                "~fd|type": "a",
                "~fd|value": 2
              },
              {
                "~fd|type": "b",
                "~fd|value": 2
              }
            ],
            "fd|type": "a",
            "fd|value": 2
          }
        ]
      },
      {
        "uid": "0x4e24",
        "km": "XXXX",
        "fd": [
          {
            "km": "CCCC",
            "~fd": [
              {
                "~fd|type": "a",
                "~fd|value": 2
              },
              {
                "~fd|type": "b",
                "~fd|value": 2
              }
            ],
            "fd|type": "b",
            "fd|value": 2
          }
        ]
      }
    ]
  }
}
kevinkle commented 4 years ago

Looks good as of https://github.com/superphy/prairiedog/pull/124/commits/1a151cd568d931c691caea18d9be999d5fed24a4