Spark Graphx Describes Organization Chart Easy and Fast

GRAPHX

GraphX is a new component in Spark for graphs and graph-parallel computation. At a high level, GraphX extends the Spark RDD by introducing a new Graph abstraction: a directed multigraph with properties attached to each vertex and edge.

To support graph computation, GraphX exposes a set of fundamental operators (e.g., subgraph, joinVertices, and aggregateMessages) as well as an optimized variant of the Pregel API from Google.

In addition, GraphX includes a growing collection of graph algorithms and builders to simplify graph analytics tasks.

Example:

Let’s define a simple org chart:

Let’s add one more person, sherry, Jacks’ wife

Here we have data:

The box, indicates the name and title in the org chart:

Sherry, wife of owner

Jack, owner

George, clerk

Mary, sales

The line, indicates the relationship in the org chart:

Jack, owner is boss of George, clerk

Jack, owner is boss of Mary, sales

Sherry, wife of owner is boss of Jack, owner

George, clerk is coworker of Mary, sales

First, I try it on an SQL database. Any database would do. Just use existing HIVE:

First, create 2 tables:

Vertex: stores the Vertex id (long integer), name, title information.

Vertex stores the box or node

Edge: Stores source vertex id, destination vertex id and relationship.

Edge stores the line, or relationship

Create the 2 tables in hive, under database cstu, that was created before

Then add data into Vertex and Edge tables

The box, indicating person and title of person:

Sherry, wife of owner

Jack, owner

George, clerk

Mary, sales

The line, indicates the relationship in the org chart:

Jack, owner is boss of George, clerk

Jack, owner is boss of Mary, sales

Sherry, wife of owner is boss of Jack, owner

George, clerk is coworker of Mary, sales

Then I construct the SQL query as below:

select * from vertex;

select * from edge;

Here is the Graph query to describe the org chart.

Run it in hive

Here is the result of query, compare with the org chart, it that right?

Now switch to Spark GraphX library with Scala:

Run the above Scala code, output below:

If this is a complex charts, Spark Graphx is the perfect platform to compute the inter-relationships because of its distributed, in memory computing nature.

Last updated

Was this helpful?