GraphX

Unifying Data-Parallel and Graph-Parallel Analytics

Graph Representation

  • Property Graphs

  • View a Graph as a Table

  • Distributed Graphs as Tables

Triplets View

  • Triplets Join the Vertices and Edges

  • Map Reduce Triplets

    1
    2
    3
    SELECT t.dstId, reduceUDF(mapUDF(t)) AS sum
    FROM triplets AS t
    GROUPBY t.dstId

  • Example: Oldest Follower
    What is the age of the oldest follower for each user?

    1
    2
    3
    4
    val oldestFollowerAge = graph.mapreduceTriplets(
    e => (e.dst.id, e.src.age), //Map
    (a,b) => max(a, b) //Reduce
    ).vertices

Subgraph Transformation

1
2
3
4
5
class Graph[VD, ED] {
def subgraph(epred: EdgeTriplet[VD, ED] => Boolean,
vpred: (VertexId, VD) => Boolean): Graph[VD, ED]
}
graph.subgraph(epred = (edge) => edge.attr != "relative")

Computation

  • mapReduceTriplets
    1
    2
    3
    4
    5
    graph.mapReduceTriplets(
    edge => Iterator(
    (edge.scrId, 1),
    (edge.dstId, 1)),
    _ + _)

System Design

  • Graph Partitioning Strategies
    Edge Cut in GraphLab 1.0 and Vertex Cut in GraphLab 2.0 in PowerGraph and GraphX

  • Graph System Optimizations

Conclusion

  • Domain specific views: Tables and Graphs
    • tables and graphs are first-class composable objects
    • specialized operators which exploit view semantics
  • Single system that efficiently spans the pipeline
    • minimize data movement and duplication
    • eliminates need to learn and manage multiple systems
  • Graphs through the lens of database systems

    • Graph-Parallel Pattern → Triplet joins in relational alg.
    • Graph Systems → Distributed join optimizations
  • Directions for Further Development

    • Static Data → Dynamic Data, Time-Evolving Big Graphs
      • Apply GraphX unified approach to time evolving data
      • Model and analyze relationships over time
    • Serving Graph Structured Data
      • Allow external systems to interact with GraphX
      • Unify distributed graph databases with relational database technology

Strength and Limitations

  • Strength

    • General-purpose graph processing library
    • Optimized for fast distributed computing
    • A rich library of algorithms: PageRank, Connected Components, etc
  • Limitations

    • No Java, Python APIs
    • Lower-level RDD-based API (vs. DataFrames)
    • Cannot use recent Spark (SQL) optimizations: Catalyst query optimizer, Tungsten memory management

GraphFrames

Motivations

Goal: Support DataFrame-based Graph processing on Spark
  • Simplify Interactive Queries
  • Support Motif-finding for Structural Pattern Search
  • Benefit from DataFrame Optimization

Graph Queries

Before GraphFrames: Separate Graph Database/ Frameworks to support Graph Algorithms and Graph Queries
GraphFrames: Support both algorithms and queries

  • System Architecture of GraphFrames

GraphFrames vs. GraphX

GraphFrames GraphX
Built on DataFrames RDDs
Languages Scala, Java, Python Scala
Use cases Queries & algorithms Algorithms
Vertex IDs Any type (in Catalyst) Long
Vertex/edge attributes Any number of DataFrame columns Any type (VD, ED)
Return types GraphFrame or DataFrame Graph[VD, ED], or RDD[Long, VD]

Graph Representation

  • Vertices DataFrame

    • 1 vertex per row
    • id: column with unique id
  • Edge DataFrame

    • 1 edge per row
    • src, dst: columns using IDs from vertices.id
id city state src dst delay tripID
“JKF” “New York” NY “JKF” “SEA” 45 1058923
“SEA” “Seattle” WA “DFW” “SFO” -7 4100224

Saving & Loading Graphs

1
2
3
4
5
vertices = sqlContext.read.parquet(...)
edges = sqlContext.read.parquet(...)
9 = GraphFrame(vertices, edges)
g.vertices.write.parquet(...)
g.edges.write.parquet(...)

Query Examples

  1. Edges and Vertices counting

    1
    2
    3
    4
    5
    6
    7
    8
    9
    from graphframes import *

    // Note that we already cached our Vertices and Edges
    tripGraph = GraphFrame(airports, departureDelays_geo)
    tripGraph.vertices

    // Airport and trip counts
    print "Airports: %d" % tripGraph.vertices.count() // Airports: 279
    print "Trips: %d" % tripGraph.edges.count() // Trips: 1361141
  2. What trips are most likely to have significant delay

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    // Get the trips with significant delay
    display(tripGraph.edges
    .groupBy("src", "dst")
    .avg("delay")
    .sort(desc("avg(delay)")))

    // States with the longest cumulative delays
    srcSeattleByState = tripGraph.edges.filter("src = 'SEA' and delay > 100")
    display(scSeattleByState)

    // Search the vertices with top 10 largest degree
    display(tripGraph.degrees
    .sort(desc("degree"))
    .limit(10))

Motif Finding

Search for structural patterns within a graph

1
2
val paths: DataFrame = g.find("(a) -[e1]-> (b); (b) -[e2]-> (c); !(c) -[]-> (a)")
paths.filter("e1.delay > 20")