> For the complete documentation index, see [llms.txt](https://george-jen.gitbook.io/data-science-and-apache-spark/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://george-jen.gitbook.io/data-science-and-apache-spark/graphx-1.md).

# Graphx

### Basic components of Graph computing:

Graph essentially consistes Vertex,  Edge and Triplet, each is an implementation of RDD, therefore, methods that are applied to a RDD can be applied to Vertex RDD, Edge RDD and Triplet RDD.  If you want, for example, you can convert Vetex RDD, Edge RDD and Triplet RDD to Spark SQL dataframe and use SQL to manipulate them.

### Vetex, Edge and Triplet

![](/files/-M3XUQb3BqkdDOqTV1mU)

#### Vertex is a 2 element tuple:  (vertex id, attribute)

```
graph.vertices.take(5).foreach(println)

/*
output:
(34,34.0)
(52,52.0)
(96,96.0)
(4,4.0)
(16,16.0)

*/
```

#### Edge is a case class, or structure (like a struct in C):  Edge(source vertex id, destination vertex id, Edge attribute)

```
graph.edges.take(5).foreach(println)
/*
Output:
Edge(0,2,1)
Edge(0,3,1)
Edge(0,6,1)
Edge(0,7,1)
Edge(0,13,1)
*/
```

#### Triplet is a 3 element nested tuple (tuple in tuple):  (source Vertex, destination Vertex, Edge attribute)&#x20;

```
graph.triplets.take(5).foreach(println)
/*
Output:
((0,0.0),(2,2.0),1)
((0,0.0),(3,3.0),1)
((0,0.0),(6,6.0),1)
((0,0.0),(7,7.0),1)
((0,0.0),(13,13.0),1)
*/
```

#### Graphx contains the classes and others in below packages:

[`org.apache.spark.graphx` ](/data-science-and-apache-spark/graphx.md)

[`org.apache.spark.graphx.impl` ](/data-science-and-apache-spark/untitled.md)

[`org.apache.spark.graphx.lib` ](/data-science-and-apache-spark/package-org.apache.spark.graphx.lib-1.md)

[`org.apache.spark.graphx.util`](/data-science-and-apache-spark/package-org.apache.spark.graphx.lib.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://george-jen.gitbook.io/data-science-and-apache-spark/graphx-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
