Expand(_all_) issues

I have been trying to using expand(all) to expand edges but it’s not really working as I would expect. For example why does:

{    
  q(func: eq(name, "Jethro Tull"), first: 1)    {  
  	expand(_all_)
	}
}

Expands the node properties, but not edges:

"data": {
    "q": [
      {
        "_stp_id": "Artist:/m/01v1cnf",
        "name": "Jethro Tull"
      }
    ]
  }

If I specify the edge:

{    
  q(func: eq(name, "Jethro Tull"), first: 1)    {  
  	name
    <Released> (first:1) {
  		expand(_all_)
		}
	}
}

I get:

"data": {
    "q": [
      {
        "name": "Jethro Tull",
        "Released": [
          {
            "_stp_id": "Album:/m/0_b9kq",
            "name": "The Very Best Of"
          }
        ]
      }
    ]
  },

My schema is:

type Artist {
	Released
	<~Member_of>
	_stp_id
	date
	name
	length
	place	
	type
}

type Engineer {
	Engineered
	_stp_id
	name	
	type
}

type Producer {
	Produced
	_stp_id
	name	
	type
}

type Album {
	<~Engineered>
	<~Released>
	<~On>
	_stp_id
	date
	primary_release
	contributor
	release_date
	name
	release_type	
	type
}

type Member {
	Member_of
	_stp_id
	role
	start
	name
	end	
	type
}

type Track {
	<~Engineered>
	<~Produced>
	On
	_stp_id
	date
	name
	length
	place	
	type
}

_stp_id: string @index(exact) .
_stp_label: string @index(exact) .
Engineered: [uid] @reverse @count .
Produced: [uid] @reverse @count .
Released: [uid] @reverse @count .
Member_of: [uid] @reverse @count .
On: [uid] @reverse @count .
date: string @index(exact) .
primary_release: string @index(exact) .
role: string @index(exact) .
length: float @index(float) .
start: string @index(exact) .
release_type: string @index(exact) .
type: string @index(exact) .
contributor: string @index(exact) .
release_date: string @index(exact) .
name: string @index(exact) .
end: string @index(exact) .
place: string @index(exact) .

What is the type of that nested node? does it have “dgraph.type”?

Yes. It’s Album.

"data": {
    "q": [
      {
        "name": "Jethro Tull",
        "dgraph.type": [
          "Artist"
        ],
        "Released": [
          {
            "_stp_id": "Album:/m/0_b9kq",
            "name": "The Very Best Of",
            "dgraph.type": [
              "Album"
            ]
          }
        ]
      }
    ]
  }

Run like this

{    
  q(func: eq(name, "Jethro Tull"), first: 1)    {  
  	expand(_all_) {  
  	   expand(_all_)
	  }
   }
}

Thanks that works. Missed it in the doc(https://dgraph.io/docs/query-language/#expand-predicates).

How about if I want to return the degree (how many nodes are connected to Jethro Tull). I have tried:

{    
  q(func: eq(name, "Jethro Tull"), first: 1)    {  
  	expand(_all_) {  
  	   c as count(uid)
	  }
   }
    edge_counts() {     
    	on: sum(val(c))
    }
}

But the edge_counts on is coming back as 0.

"data": {
    "q": [
      {
        "Released": [
          {
            "count": 63
          }
        ],
        "name": "Jethro Tull",
        "~Member_of": [
          {
            "count": 24
          }
        ],
        "_stp_id": "Artist:/m/01v1cnf"
      }
    ],
    "edge_counts": [
      {
        "on": 0
      }
    ]
  }

At least most of the time. If I run the query over and over sometimes it returns the count of one edge type not all.

{
  "data": {
    "q": [
      {
        "name": "Jethro Tull",
        "~Member_of": [
          {
            "count": 24
          }
        ],
        "_stp_id": "Artist:/m/01v1cnf",
        "Released": [
          {
            "count": 63
          }
        ]
      }
    ],
    "edge_counts": [
      {
        "on": 63
      }
    ]
  }
1 Like

Try this.

{    
  q(func: eq(name, "Jethro Tull"), first: 1)    {  
  	expand(_all_) {  
  	   x as count(uid)
	  }
     c as sum(val(x))
   }
    edge_counts() {     
    	on: sum(val(c))
    }
}

This also returns 0. Looking at the results c is never returned.

I modified the query a little to illustrate (same query but I changed the name of the results; else the results are the exact same as above):

{    
  q(func: eq(name, "Jethro Tull"), first: 1)    {  
  	expand(_all_) {  
  	   c1: x as count(uid)
	  }
     c2: c as sum(val(x))
   }
    edge_counts() {     
    	on: sum(val(c))
    }
}
"data": {
    "q": [
      {
        "_stp_id": "Artist:/m/01v1cnf",
        "name": "Jethro Tull",
        "Released": [
          {
            "c1": 63
          }
        ],
        "~Member_of": [
          {
            "c1": 24
          }
        ]
      }
    ],
    "edge_counts": [
      {
        "on": 0
      }
    ]
  }  

Can you check without expand?

Like this?

{    
  q(func: eq(name, "Jethro Tull"), first: 1)    {  
  	<Released> {  
  	   c1: x as count(uid)
	  }
     c2: c as sum(val(x))
   }
    edge_counts() {     
    	on: sum(val(c))
    }
}

Same. x\c1 returns 63. c\c2 does not return. End result is 0.

Must be something wrong in your side

Executing this query locally and in http://play.dgraph.io/. I got the expected results and always the same.

{
  var(func: eq(count(director.film), 7), first:10) {
    director.film {
      uid
      a as count(~director.film)
 #     <~director.film> {
#      uid
#       expand(_all_)
#    }
    }
  }

  me() {
    sum(val(a))
  }
}

Result

{
  "data": {
    "me": [
      {
        "sum(val(a))": 106
      }
    ]
  }
}

Other with several levels

{
  var(func: eq(count(director.film), 7), first:10) {
    director.film {
      <~director.film> {
        a as count(director.film)
    }
    }
  }

  me() {
    sum(val(a))
  }
}

Result


  "data": {
    "me": [
      {
        "sum(val(a))": 388
      }
    ]
  }
}

That query is not the same as what I have tried (including what you suggested above) since there is no equivalent of “c2: c as sum(val(x))” that I see. Also, the original question (that I posted today) was how to get the degree of a node using expand. Is it possible?

What do you mean by degree? I don’t know anything extra, related to expand. So it’s certainly not possible.

Degree is a common concept in graph theory (Degree (graph theory) - Wikipedia). Basically the total number of connections for a specific node (there are also incoming and outgoing variants).

There are no differences. The query does not necessarily have to be the same, to demonstrate a bug. The query below contains aggregation and works the same way.

{
  var(func: eq(count(director.film), 7), first:10) {
    director.film {
      <~director.film> {
        x as count(director.film)
    }
       c2: c as sum(val(x))
    }
  }

  me() {
    sum(val(c))
  }
}

Nope, there’s no way to tell this. Unless you try out some math functions, but you have to find a way how.

Is there some way to count the number of nodes(of any type) connected to a certain node by now?Is it possible to find all the nodes connected to a certain node without specifying type infomation?

Not sure what you mean, you can do this using count Query Language - Query language - do you mean “by now” as the current time?

Again, I didn’t get it. You can find any node without specifying the type.

BTW, please, open new topics instead of commenting on old ones. You can just reference it by link.

Not sure what you mean, you can do this using count Query Language - Query language - do you mean “by now” as the current time?

I’m sorry I didn’t express it clearly.I saw your post at Apr 2 that there is no way to get the “degree” of a specific node, i just want to know if it is supported now after four months.

Again, I didn’t get it. You can find any node without specifying the type.
BTW, please, open new topics instead of commenting on old ones. You can just reference it by link.

I thought my question was highly correlated with this old topic,so I chose to comment instead of opening a new topic.Very sorry if that commenting still goes against community rules.

It could if we see that is something practical proofed for GraphDBs. Not everything in the Graph Theory is useful in GraphDBs. Algorithm about relations are generally useful. But others are useful just in math context. Dealing with numbers and complex equations. Not a DB/business model, you can use math to plan a business model, but no a DB fundamentally speaking.

If you show me what you wanna get from it in a clear way. I could try to validate the possibility. And, if the case, have an argumentation to add a feature request. I can help you there, but first I need to understand the need. What you wanna achieve, with examples.

But nothing is guarantee tho.

np, that’s not the problem and it is not a rule. Sometimes people don’t wanna get emails from another question in your old question you know? (except when it’s a discussion thread) We like good news, not parallel discussions. So, it is totally okay to create a new topic and use this one as your reference. We gonna read it (the content of the link) to understand your context again.

Cheers.