> 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/edgecontext-class.md).

# EdgeContext Class

```
abstract class EdgeContext[VD, ED, A] extends AnyRef
```

### Instance constructor:

new EdgeContext()

### Abstract active members:

```
abstract def attr: ED 
The attribute associated with the edge.

abstract def dstAttr: VD 
The vertex attribute of the edge's destination vertex.

abstract def dstId: VertexId 
The vertex id of the edge's destination vertex.

abstract def sendToDst(msg: A): Unit 
Sends a message to the destination vertex.

abstract def sendToSrc(msg: A): Unit 
Sends a message to the source vertex.

abstract def srcAttr: VD 
The vertex attribute of the edge's source vertex.

abstract def srcId: VertexId 
The vertex id of the edge's source vertex.
```

#### Example:

```
import org.apache.spark.graphx 
import org.apache.spark.graphx.impl._ 
import org.apache.spark.graphx.lib._ 
import org.apache.spark.graphx.util._


// $example on$
    // Create a graph with "age" as the vertex property.
    // Here we use a random graph for simplicity.
    val graph: Graph[Double, Int] =
      GraphGenerators.logNormalGraph(sc, numVertices = 100).mapVertices( (id, _) => id.toDouble )

def sendMsg(triplet: EdgeContext[Double, Int, (Int, Double)]): Unit ={
//      (triplet:EdgeContext[Double, Int, (Int, Double)]) => { // Map Function
        if (triplet.srcAttr > triplet.dstAttr) {
          // Send message to destination vertex containing counter and age
          triplet.sendToDst((1, triplet.srcAttr))
        }
//      }
}
def mergeMsg(a:(Int, Double), b:(Int, Double)): (Int, Double) = (a._1+b._1,a._2+b._2)
val olderFollowers: VertexRDD[(Int, Double)]  = graph.aggregateMessages[(Int, Double)](sendMsg, mergeMsg)

olderFollowers.take(5).foreach(println)

/*
Output:
(34,(36,2433.0))
(52,(20,1615.0))
(96,(2,195.0))
(4,(49,2511.0))
(16,(43,2754.0))

*/

```

Reference:

<https://github.com/apache/spark/blob/v2.4.5/graphx/src/main/scala/org/apache/spark/graphx/EdgeContext.scala>


---

# 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, and the optional `goal` query parameter:

```
GET https://george-jen.gitbook.io/data-science-and-apache-spark/edgecontext-class.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
