Hi Tigers

I went through your documentation and I couldn’t find the relevant info…

I’m trying to get a better understanding of the returned value of v.outdegree().

What is the returned value of v.outdegree() if the vertex v does not have an outdegree? I would expect that value to be zero, but it appears to be null… It seems that if a vertex has no outdegree, that value is not even calculated. Could you confirm if that is the case?

Also, what is the best way to calculate indegree? And what is the best way to identify the vertices that are isolated with no edges?

Best,

H

Hi H,

The value of outdegree() suppose to be 0 is not edge originate from the vertex. Could you please show me how do you know it s a null value?

Thanks.

Hi Xinyu

I have a test dataset with directed edge only, and the data are as follows:

# FromNodeId,ToNodeId

1,2

2,1

1,3

1,1

where vertex 3 has no outbound edge and I expect to catch that with:

zerooutdegrees = SELECT s

``````               FROM start:s - (voted:e) -> :t

ACCUM IF s.outdegree() == 0 THEN

@@zero_outdegrees += 1

END;
``````

PRINT @@zero_outdegrees;

And the results show zero_outdegrees = 0. Not sure what I did wrong. Any advice is appreciated…

{

“error”: false,

“message”: “”,

“version”: {

``````"schema": 0,

"edition": "developer",

"api": "v2"
``````

},

“results”: [

``````{"@@in_edges": 4},

{"@@zero_outdegrees": 0},

{"@@numvertices": 3},

{"@@numedges": 4},

{"edge_per_vertex": 1.33333},

{"density": 1.33333},

{"@@self_edges": 1},

{"@@directed_edges": 3},

{"\"graph_summary works!\"": "graph_summary works!"}
``````

]

}

You’re performing an edge induced selection and as such Node 3 isn’t being considered as there is no outdegree edge.

Print the zerooutsegrees vertex set and you shouldn’t see Nose 3 in it.

Yes I agree with Ric,

Since 3 is a vertex without and outgoing edge, therefore 3 doesn’t match pattern start:s - (voted:e) -> :t .

Therefore 3 won’t be considered to be any s in your select statement, and the condition check won’t be executed either.

To find the vertexes without outgoing edge, please use a sekect statenebt withou edge, for example:

zerooutdegrees = SELECT s

``````               FROM start:s

ACCUM IF s.outdegree() == 0 THEN

@@zero_outdegrees += 1

END;
``````

Thanks.

Ah…

Why can’t we just do this in python!? That explains everything.

Thx!
SH

1 Like

You can send a restful request from python, also you can try to send an interpret query.

https://docs.tigergraph.com/dev/gsql-ref/querying/query-operations#interpret-query

gsql is definitely something that requires some getting used to. And the interpret mode is an under appreciated feature.

In the meantime, any suggestion on finding the # of indegree on a vertex?

As for isolated vertices. I tried the following code segment

numisolated = SELECT s

``````    FROM start:s

ACCUM IF COUNT(s.neighbors()) == 0 THEN

@@num_isolated += 1

END;
``````

PRINT @@num_isolated;

and it returns the following error msg:

Unsupported feature in query : line 76, col 18

The feature is not supported yet in batch mode query.

line 76: ACCUM IF COUNT(s.neighbors()) == 0 THEN

Thx again,

SH

Seems COUNT is not supported in DISTRIBUTED mode. Did you use DISTRIBUTED keyword when you create the query?

Nope. Also, I’m using the developer’s edition, which doesn’t support distributed mode anyway. Still, I double checked by grepping for “distributed” and it’s not used anywhere.

Thx,

SH

Hmmm, are you using interpret mode then?

Yes. I guess that is the problem?

I’ll try the regular mode and provide feedback.

SH

Hi Xinyu

The Count() function works fine if it’s not used in interpret mode.

By the way, is there an easy way to find a vertex’s indegree? I am not able to find a quick and easy way to calculate that. Any advice is appreciated.

SH

If you defined a directed + reverse edge.

You can use function outdegree(“reverse_edge_type”) to get its indegree.