Graph 在 pyspark for Spark 3.0+ 上可用吗

问题描述

我想知道 PySpark 中是否有适用于 Spark 3.0+ 的 GraphX API? 我在官方文档中找不到任何此类内容。所有的例子都是用 Scala 开发的。我可以从哪里获得有关它的更多更新。

谢谢, 大山

解决方法

根据 http://ampcamp.berkeley.edu/big-data-mini-course/graph-analytics-with-graphx.html 提供的文档:

“GraphX API 目前仅在 Scala 中可用,但我们计划在未来提供 Java 和 Python 绑定。”

但是,您应该看看 GraphFrames (https://github.com/graphframes/graphframes),它在 DataFrames API 下包装了 GraphX 算法并提供了 Python 接口。

这是 https://graphframes.github.io/graphframes/docs/_site/quick-start.html 中的一个简单示例,稍加修改即可正常工作。

首先,在加载了graphframes pkg的情况下启动pyspark。

pyspark --packages graphframes:graphframes:0.1.0-spark1.6

python 代码:

from graphframes import *

# Create a Vertex DataFrame with unique ID column "id"
v = sqlContext.createDataFrame([
  ("a","Alice",34),("b","Bob",36),("c","Charlie",30),],["id","name","age"])

# Create an Edge DataFrame with "src" and "dst" columns
e = sqlContext.createDataFrame([
  ("a","b","friend"),"c","follow"),["src","dst","relationship"])
# Create a GraphFrame
g = GraphFrame(v,e)

# Query: Get in-degree of each vertex.
g.inDegrees.show()

# Query: Count the number of "follow" connections in the graph.
g.edges.filter("relationship = 'follow'").count()

# Run PageRank algorithm,and show results.
results = g.pageRank(resetProbability=0.01,maxIter=20)
results.vertices.select("id","pagerank").show()
,

没有

GraphX 计算仅支持使用 Scala 和 RDD API。

https://docs.databricks.com/spark/latest/graph-analysis/graph-analysis-graphx-tutorial.html

GraphX 是传统的,这是有道理的。