pagerank_res.write\ .format('bigquery')\ .mode('overwrite')\ .option('table',pagerank_table)\ .save() logging.info('Done!') # .option("query", "MATCH (n:User) WHERE n.screen_name CONTAINS '' RETURN n.screen_name,n.id_str,n.description,n.followers_count")\ """ Community Detection Triangle indicates that two of a node's neighbours are also neighbours value of 1 would mean the user is a part of a triangle """ # logging.info('Triangle count algorithm') result = g.triangleCount() triangle_count = result.sort("count", ascending=False).filter('count > 0') #triangle_count.show() # # # ## save triangle count results to BQ # triangle_count_table = 'project_data.triangle_count_results' logging.info('Writing Triangle Count data to BQ') #triangle_count.write.csv('triangle_count.csv') triangle_count.write\ .format('bigquery') \ .mode('overwrite')\ .option('table',triangle_count_table)\
# +---+---+------------+ # | a| b| friend| # | b| c| follow| # | c| b| follow| # | f| c| follow| # | e| f| follow| # | e| d| friend| # | d| a| friend| # | a| e| friend| # +---+---+------------+ # Count Triangles # To count triangles, we use the `GraphFrame.triangleCount()` # method, which counts the number of triangles passing through # each vertex in this graph. results = graph.triangleCount() results.show() # +-----+---+-------+---+ # |count| id| name|age| # +-----+---+-------+---+ # | 0| g| Gabby| 60| # | 0| f| Fanny| 36| # | 1| e| Esther| 32| # | 1| d| David| 29| # | 0| c|Charlie| 30| # | 0| b| Bob| 36| # | 1| a| Alice| 34| # +-----+---+-------+---+ # To show only vertex ID and the number of triangles # passing through each vertex, we can write: