Georg Heiler
Georg Heiler

Reputation: 17704

spark graphframes stateful motif

graph frames has a nice example for stateful motifs. How can I explicitly return the counts? As you see the output only contains vertices and friends but not the counts.

How can I modify it to not (only) have access to the edges but access to the labels of the vertices as well?

when(relationship === "friend", cnt + 1).otherwise(cnt)

I.e. how could I enhance the count to count

Which will output

+-------------+------------+-------------+------------+-------------+------------+--------------+
|            a|          ab|            b|          bc|            c|          cd|             d|
+-------------+------------+-------------+------------+-------------+------------+--------------+
|[e,Esther,32]|[e,d,friend]| [d,David,29]|[d,a,friend]| [a,Alice,34]|[a,e,friend]| [e,Esther,32]|
|[e,Esther,32]|[e,d,friend]| [d,David,29]|[d,a,friend]| [a,Alice,34]|[a,b,friend]|    [b,Bob,36]|
| [d,David,29]|[d,a,friend]| [a,Alice,34]|[a,e,friend]|[e,Esther,32]|[e,d,friend]|  [d,David,29]|
| [d,David,29]|[d,a,friend]| [a,Alice,34]|[a,e,friend]|[e,Esther,32]|[e,f,follow]|  [f,Fanny,36]|
| [d,David,29]|[d,a,friend]| [a,Alice,34]|[a,b,friend]|   [b,Bob,36]|[b,c,follow]|[c,Charlie,30]|
| [a,Alice,34]|[a,e,friend]|[e,Esther,32]|[e,d,friend]| [d,David,29]|[d,a,friend]|  [a,Alice,34]|
+-------------+------------+-------------+------------+-------------+------------+--------------+

Upvotes: 2

Views: 947

Answers (1)

Paul
Paul

Reputation: 1186

Note that sumFriends returns a Column, so condition is a column. This is why you can access it in a where statement without quotes. So all you have to do is add that column to your dataframe. After running the above code, I can run

chain4.withColumn("condition",condition).select("condition").show

+---------+ 
|condition|
+---------+
 | 1|
 | 0|
 | 0|
 | 0|
 | 0|
 | 3|
 | 3|
 | 3|
 | 2|
 | 2|
 | 3|
 | 1|
+---------+

you could also use chain4.select(condition)

Hope this helps

Upvotes: 1

Related Questions