【问题标题】:Is Graph available on pyspark for Spark 3.0+Graph 是否在 pyspark 上适用于 Spark 3.0+
【发布时间】:2021-02-11 08:23:51
【问题描述】:

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

谢谢, 达山

【问题讨论】:

标签: apache-spark pyspark spark-graphx


【解决方案1】:

根据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 的一个简单示例,稍作修改以使其正常工作。

首先,启动 pyspark 并加载图形框架 pkg。

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"),
  ("b", "c", "follow"),
  ("c", "b", "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()

【讨论】:

  • 不错的答案,但是我会推荐更高版本的图框,例如 --packages graphframes:graphframes:0.6.0-spark2.3-s_2.11
【解决方案2】:

没有。

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

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

GraphX 是遗留的,这是有道理的。

【讨论】:

  • 很难遵循你的逻辑,其他答案是正确的原始问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-10
  • 1970-01-01
  • 2021-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-28
相关资源
最近更新 更多