@@ -37,7 +37,7 @@ The following example demonstrates how to create a GraphFrame from vertex and ed
3737{% highlight scala %}
3838import org.graphframes.GraphFrame
3939// Vertex DataFrame
40- val v = sqlContext .createDataFrame(List(
40+ val v = spark .createDataFrame(List(
4141 ("a", "Alice", 34),
4242 ("b", "Bob", 36),
4343 ("c", "Charlie", 30),
@@ -47,7 +47,7 @@ val v = sqlContext.createDataFrame(List(
4747 ("g", "Gabby", 60)
4848)).toDF("id", "name", "age")
4949// Edge DataFrame
50- val e = sqlContext .createDataFrame(List(
50+ val e = spark .createDataFrame(List(
5151 ("a", "b", "friend"),
5252 ("b", "c", "follow"),
5353 ("c", "b", "follow"),
@@ -71,7 +71,7 @@ val g: GraphFrame = examples.Graphs.friends
7171<div data-lang =" python " markdown =" 1 " >
7272{% highlight python %}
7373# Vertex DataFrame
74- v = sqlContext .createDataFrame([
74+ v = spark .createDataFrame([
7575 ("a", "Alice", 34),
7676 ("b", "Bob", 36),
7777 ("c", "Charlie", 30),
@@ -81,7 +81,7 @@ v = sqlContext.createDataFrame([
8181 ("g", "Gabby", 60)
8282] , [ "id", "name", "age"] )
8383# Edge DataFrame
84- e = sqlContext .createDataFrame([
84+ e = spark .createDataFrame([
8585 ("a", "b", "friend"),
8686 ("b", "c", "follow"),
8787 ("c", "b", "follow"),
@@ -98,7 +98,7 @@ g = GraphFrame(v, e)
9898The GraphFrame constructed above is available in the GraphFrames package:
9999{% highlight python %}
100100from graphframes.examples import Graphs
101- g = Graphs(sqlContext) .friends()
101+ g = Graphs.friends()
102102{% endhighlight %}
103103</div >
104104
@@ -166,7 +166,7 @@ val numFollows = g.edges.filter("relationship = 'follow'").count()
166166<div data-lang =" python " markdown =" 1 " >
167167{% highlight python %}
168168from graphframes.examples import Graphs
169- g = Graphs(sqlContext) .friends() # Get example graph
169+ g = Graphs.friends() # Get example graph
170170
171171# Display the vertex and edge DataFrames
172172g.vertices.show()
@@ -294,7 +294,7 @@ For API details, refer to the [API docs](api/python/graphframes.html#graphframes
294294
295295{% highlight python %}
296296from graphframes.examples import Graphs
297- g = Graphs(sqlContext) .friends() # Get example graph
297+ g = Graphs.friends() # Get example graph
298298
299299# Search for pairs of vertices with edges in both directions between them.
300300motifs = g.find("(a)-[ e] ->(b); (b)-[ e2] ->(a)")
@@ -360,7 +360,7 @@ chainWith2Friends2.show()
360360from pyspark.sql.functions import col, lit, when
361361from pyspark.sql.types import IntegerType
362362from graphframes.examples import Graphs
363- g = Graphs(sqlContext) .friends() # Get example graph
363+ g = Graphs.friends() # Get example graph
364364
365365chain4 = g.find("(a)-[ ab] ->(b); (b)-[ bc] ->(c); (c)-[ cd] ->(d)")
366366
@@ -414,7 +414,7 @@ val g1 = g.filterVertices("age > 30").filterEdges("relationship = 'friend'").dro
414414<div data-lang =" python " markdown =" 1 " >
415415{% highlight python %}
416416from graphframes.examples import Graphs
417- g = Graphs(sqlContext) .friends() # Get example graph
417+ g = Graphs.friends() # Get example graph
418418
419419# Select subgraph of users older than 30, and relationships of type "friend".
420420# Drop isolated vertices (users) which are not contained in any edges (relationships).
@@ -455,7 +455,7 @@ val g2 = GraphFrame(g.vertices, e2)
455455<div data-lang =" python " markdown =" 1 " >
456456{% highlight python %}
457457from graphframes.examples import Graphs
458- g = Graphs(sqlContext) .friends() # Get example graph
458+ g = Graphs.friends() # Get example graph
459459
460460# Select subgraph based on edges "e" of type "follow"
461461# pointing from a younger user "a" to an older user "b".
@@ -522,7 +522,7 @@ For API details, refer to the [API docs](api/python/graphframes.html#graphframes
522522
523523{% highlight python %}
524524from graphframes.examples import Graphs
525- g = Graphs(sqlContext) .friends() # Get example graph
525+ g = Graphs.friends() # Get example graph
526526
527527# Search from "Esther" for users of age < 32.
528528paths = g.bfs("name = 'Esther'", "age < 32")
@@ -568,7 +568,7 @@ For API details, refer to the [API docs](api/python/graphframes.html#graphframes
568568
569569{% highlight python %}
570570from graphframes.examples import Graphs
571- g = Graphs(sqlContext) .friends() # Get example graph
571+ g = Graphs.friends() # Get example graph
572572
573573result = g.connectedComponents()
574574result.select("id", "component").orderBy("component").show()
@@ -605,7 +605,7 @@ For API details, refer to the [API docs](api/python/graphframes.html#graphframes
605605
606606{% highlight python %}
607607from graphframes.examples import Graphs
608- g = Graphs(sqlContext) .friends() # Get example graph
608+ g = Graphs.friends() # Get example graph
609609
610610result = g.stronglyConnectedComponents(maxIter=10)
611611result.select("id", "component").orderBy("component").show()
@@ -649,7 +649,7 @@ For API details, refer to the [API docs](api/python/graphframes.html#graphframes
649649
650650{% highlight python %}
651651from graphframes.examples import Graphs
652- g = Graphs(sqlContext) .friends() # Get example graph
652+ g = Graphs.friends() # Get example graph
653653
654654result = g.labelPropagation(maxIter=5)
655655result.select("id", "label").show()
@@ -707,7 +707,7 @@ For API details, refer to the [API docs](api/python/graphframes.html#graphframes
707707
708708{% highlight python %}
709709from graphframes.examples import Graphs
710- g = Graphs(sqlContext) .friends() # Get example graph
710+ g = Graphs.friends() # Get example graph
711711
712712# Run PageRank until convergence to tolerance "tol".
713713results = g.pageRank(resetProbability=0.15, tol=0.01)
@@ -759,7 +759,7 @@ For API details, refer to the [API docs](api/python/graphframes.html#graphframes
759759
760760{% highlight python %}
761761from graphframes.examples import Graphs
762- g = Graphs(sqlContext) .friends() # Get example graph
762+ g = Graphs.friends() # Get example graph
763763
764764results = g.shortestPaths(landmarks=[ "a", "d"] )
765765results.select("id", "distances").show()
@@ -793,7 +793,7 @@ For API details, refer to the [API docs](api/python/graphframes.html#graphframes
793793
794794{% highlight python %}
795795from graphframes.examples import Graphs
796- g = Graphs(sqlContext) .friends() # Get example graph
796+ g = Graphs.friends() # Get example graph
797797
798798results = g.triangleCount()
799799results.select("id", "count").show()
@@ -823,8 +823,8 @@ g.vertices.write.parquet("hdfs://myLocation/vertices")
823823g.edges.write.parquet("hdfs://myLocation/edges")
824824
825825// Load the vertices and edges back.
826- val sameV = sqlContext .read.parquet("hdfs://myLocation/vertices")
827- val sameE = sqlContext .read.parquet("hdfs://myLocation/edges")
826+ val sameV = spark .read.parquet("hdfs://myLocation/vertices")
827+ val sameE = spark .read.parquet("hdfs://myLocation/edges")
828828
829829// Create an identical GraphFrame.
830830val sameG = GraphFrame(sameV, sameE)
@@ -834,15 +834,15 @@ val sameG = GraphFrame(sameV, sameE)
834834<div data-lang =" python " markdown =" 1 " >
835835{% highlight python %}
836836from graphframes.examples import Graphs
837- g = Graphs(sqlContext) .friends() # Get example graph
837+ g = Graphs.friends() # Get example graph
838838
839839# Save vertices and edges as Parquet to some location.
840840g.vertices.write.parquet("hdfs://myLocation/vertices")
841841g.edges.write.parquet("hdfs://myLocation/edges")
842842
843843# Load the vertices and edges back.
844- sameV = sqlContext .read.parquet("hdfs://myLocation/vertices")
845- sameE = sqlContext .read.parquet("hdfs://myLocation/edges")
844+ sameV = spark .read.parquet("hdfs://myLocation/vertices")
845+ sameE = spark .read.parquet("hdfs://myLocation/edges")
846846
847847# Create an identical GraphFrame.
848848sameG = GraphFrame(sameV, sameE)
@@ -903,7 +903,7 @@ For API details, refer to the
903903from pyspark.sql.functions import sum as sqlsum
904904from graphframes.lib import AggregateMessages as AM
905905from graphframes.examples import Graphs
906- g = Graphs(sqlContext) .friends() # Get example graph
906+ g = Graphs.friends() # Get example graph
907907
908908# For each user, sum the ages of the adjacent users.
909909msgToSrc = AM.dst[ "age"]
0 commit comments