or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

graph-analytics.mdgraph-construction.mdgraph-operations.mdindex.mditerative-algorithms.md

graph-operations.mddocs/

0

# Graph Operations

1

2

Complete API for graph data access, transformations, and manipulations.

3

4

## Data Access Methods

5

6

### Basic Data Retrieval

7

8

```scala { .api }

9

def getVertices: DataSet[Vertex[K, VV]]

10

```

11

12

Returns the vertex DataSet containing all graph vertices.

13

14

```scala { .api }

15

def getEdges: DataSet[Edge[K, EV]]

16

```

17

18

Returns the edge DataSet containing all graph edges.

19

20

```scala { .api }

21

def getVerticesAsTuple2(): DataSet[(K, VV)]

22

```

23

24

Returns vertices as tuple DataSet `(vertexId, vertexValue)`.

25

26

```scala { .api }

27

def getEdgesAsTuple3(): DataSet[(K, K, EV)]

28

```

29

30

Returns edges as tuple DataSet `(sourceId, targetId, edgeValue)`.

31

32

```scala { .api }

33

def getTriplets(): DataSet[Triplet[K, VV, EV]]

34

```

35

36

Returns triplets containing `(srcVertexId, trgVertexId, srcVertexValue, trgVertexValue, edgeValue)`.

37

38

### Graph Statistics

39

40

```scala { .api }

41

def numberOfVertices(): Long

42

```

43

44

Returns the total number of vertices in the graph.

45

46

```scala { .api }

47

def numberOfEdges(): Long

48

```

49

50

Returns the total number of edges in the graph.

51

52

```scala { .api }

53

def getVertexIds(): DataSet[K]

54

```

55

56

Returns a DataSet containing all vertex IDs.

57

58

```scala { .api }

59

def getEdgeIds(): DataSet[(K, K)]

60

```

61

62

Returns a DataSet containing all edge IDs as `(sourceId, targetId)` tuples.

63

64

## Transformation Operations

65

66

### Vertex Transformations

67

68

```scala { .api }

69

def mapVertices[NV: TypeInformation : ClassTag](mapper: MapFunction[Vertex[K, VV], NV]): Graph[K, NV, EV]

70

```

71

72

Applies a map function to transform vertex values.

73

74

**Parameters:**

75

- `mapper` - MapFunction that transforms `Vertex[K, VV]` to new value type `NV`

76

77

```scala { .api }

78

def mapVertices[NV: TypeInformation : ClassTag](fun: Vertex[K, VV] => NV): Graph[K, NV, EV]

79

```

80

81

Applies a Scala function to transform vertex values.

82

83

**Parameters:**

84

- `fun` - Scala function that transforms vertex to new value type

85

86

### Edge Transformations

87

88

```scala { .api }

89

def mapEdges[NV: TypeInformation : ClassTag](mapper: MapFunction[Edge[K, EV], NV]): Graph[K, VV, NV]

90

```

91

92

Applies a map function to transform edge values.

93

94

**Parameters:**

95

- `mapper` - MapFunction that transforms `Edge[K, EV]` to new value type `NV`

96

97

```scala { .api }

98

def mapEdges[NV: TypeInformation : ClassTag](fun: Edge[K, EV] => NV): Graph[K, VV, NV]

99

```

100

101

Applies a Scala function to transform edge values.

102

103

**Parameters:**

104

- `fun` - Scala function that transforms edge to new value type

105

106

### Translation Operations

107

108

```scala { .api }

109

def translateGraphIds[NEW: TypeInformation : ClassTag](translator: TranslateFunction[K, NEW]): Graph[NEW, VV, EV]

110

```

111

112

Translates vertex and edge IDs using the given TranslateFunction.

113

114

**Parameters:**

115

- `translator` - TranslateFunction implementing conversion from `K` to `NEW`

116

117

```scala { .api }

118

def translateGraphIds[NEW: TypeInformation : ClassTag](fun: (K, NEW) => NEW): Graph[NEW, VV, EV]

119

```

120

121

Translates vertex and edge IDs using a Scala function.

122

123

**Parameters:**

124

- `fun` - Function implementing conversion from `K` to `NEW`

125

126

```scala { .api }

127

def translateVertexValues[NEW: TypeInformation : ClassTag](translator: TranslateFunction[VV, NEW]): Graph[K, NEW, EV]

128

```

129

130

Translates vertex values using the given TranslateFunction.

131

132

**Parameters:**

133

- `translator` - TranslateFunction implementing conversion from `VV` to `NEW`

134

135

```scala { .api }

136

def translateVertexValues[NEW: TypeInformation : ClassTag](fun: (VV, NEW) => NEW): Graph[K, NEW, EV]

137

```

138

139

Translates vertex values using a Scala function.

140

141

**Parameters:**

142

- `fun` - Function implementing conversion from `VV` to `NEW`

143

144

```scala { .api }

145

def translateEdgeValues[NEW: TypeInformation : ClassTag](translator: TranslateFunction[EV, NEW]): Graph[K, VV, NEW]

146

```

147

148

Translates edge values using the given TranslateFunction.

149

150

**Parameters:**

151

- `translator` - TranslateFunction implementing conversion from `EV` to `NEW`

152

153

```scala { .api }

154

def translateEdgeValues[NEW: TypeInformation : ClassTag](fun: (EV, NEW) => NEW): Graph[K, VV, NEW]

155

```

156

157

Translates edge values using a Scala function.

158

159

**Parameters:**

160

- `fun` - Function implementing conversion from `EV` to `NEW`

161

162

## Join Operations

163

164

### Vertex Joins

165

166

```scala { .api }

167

def joinWithVertices[T: TypeInformation](inputDataSet: DataSet[(K, T)], vertexJoinFunction: VertexJoinFunction[VV, T]): Graph[K, VV, EV]

168

```

169

170

Joins the vertex DataSet with an input Tuple2 DataSet and applies a transformation function.

171

172

**Parameters:**

173

- `inputDataSet` - Tuple2 DataSet to join with `(vertexId, inputValue)`

174

- `vertexJoinFunction` - Function to transform joined values

175

176

```scala { .api }

177

def joinWithVertices[T: TypeInformation](inputDataSet: DataSet[(K, T)], fun: (VV, T) => VV): Graph[K, VV, EV]

178

```

179

180

Joins vertices with external data using a Scala function.

181

182

**Parameters:**

183

- `inputDataSet` - Tuple2 DataSet `(vertexId, inputValue)`

184

- `fun` - Function combining current vertex value with input value

185

186

### Edge Joins

187

188

```scala { .api }

189

def joinWithEdges[T: TypeInformation](inputDataSet: DataSet[(K, K, T)], edgeJoinFunction: EdgeJoinFunction[EV, T]): Graph[K, VV, EV]

190

```

191

192

Joins the edge DataSet with an input DataSet on the composite key of source and target IDs.

193

194

**Parameters:**

195

- `inputDataSet` - Tuple3 DataSet `(sourceId, targetId, inputValue)`

196

- `edgeJoinFunction` - Function to transform joined edge values

197

198

```scala { .api }

199

def joinWithEdges[T: TypeInformation](inputDataSet: DataSet[(K, K, T)], fun: (EV, T) => EV): Graph[K, VV, EV]

200

```

201

202

Joins edges with external data using a Scala function.

203

204

```scala { .api }

205

def joinWithEdgesOnSource[T: TypeInformation](inputDataSet: DataSet[(K, T)], edgeJoinFunction: EdgeJoinFunction[EV, T]): Graph[K, VV, EV]

206

```

207

208

Joins edges with external data based on source vertex ID.

209

210

**Parameters:**

211

- `inputDataSet` - Tuple2 DataSet `(sourceId, inputValue)`

212

- `edgeJoinFunction` - Function to transform edge values

213

214

```scala { .api }

215

def joinWithEdgesOnSource[T: TypeInformation](inputDataSet: DataSet[(K, T)], fun: (EV, T) => EV): Graph[K, VV, EV]

216

```

217

218

Joins edges on source ID using a Scala function.

219

220

```scala { .api }

221

def joinWithEdgesOnTarget[T: TypeInformation](inputDataSet: DataSet[(K, T)], edgeJoinFunction: EdgeJoinFunction[EV, T]): Graph[K, VV, EV]

222

```

223

224

Joins edges with external data based on target vertex ID.

225

226

```scala { .api }

227

def joinWithEdgesOnTarget[T: TypeInformation](inputDataSet: DataSet[(K, T)], fun: (EV, T) => EV): Graph[K, VV, EV]

228

```

229

230

Joins edges on target ID using a Scala function.

231

232

## Filtering Operations

233

234

### Subgraph Creation

235

236

```scala { .api }

237

def subgraph(vertexFilter: FilterFunction[Vertex[K, VV]], edgeFilter: FilterFunction[Edge[K, EV]]): Graph[K, VV, EV]

238

```

239

240

Creates a subgraph by applying filtering predicates to both vertices and edges.

241

242

**Parameters:**

243

- `vertexFilter` - Predicate function for vertices

244

- `edgeFilter` - Predicate function for edges

245

246

```scala { .api }

247

def subgraph(vertexFilterFun: Vertex[K, VV] => Boolean, edgeFilterFun: Edge[K, EV] => Boolean): Graph[K, VV, EV]

248

```

249

250

Creates a subgraph using Scala predicate functions.

251

252

### Individual Filtering

253

254

```scala { .api }

255

def filterOnVertices(vertexFilter: FilterFunction[Vertex[K, VV]]): Graph[K, VV, EV]

256

```

257

258

Filters the graph based on vertex predicates only.

259

260

```scala { .api }

261

def filterOnVertices(vertexFilterFun: Vertex[K, VV] => Boolean): Graph[K, VV, EV]

262

```

263

264

Filters vertices using a Scala predicate function.

265

266

```scala { .api }

267

def filterOnEdges(edgeFilter: FilterFunction[Edge[K, EV]]): Graph[K, VV, EV]

268

```

269

270

Filters the graph based on edge predicates only.

271

272

```scala { .api }

273

def filterOnEdges(edgeFilterFun: Edge[K, EV] => Boolean): Graph[K, VV, EV]

274

```

275

276

Filters edges using a Scala predicate function.

277

278

## Graph Mutation Operations

279

280

### Adding Elements

281

282

```scala { .api }

283

def addVertex(vertex: Vertex[K, VV]): Graph[K, VV, EV]

284

```

285

286

Adds a single vertex to the graph. If the vertex already exists, it will not be added again.

287

288

```scala { .api }

289

def addVertices(vertices: List[Vertex[K, VV]]): Graph[K, VV, EV]

290

```

291

292

Adds multiple vertices to the graph.

293

294

```scala { .api }

295

def addEdges(edges: List[Edge[K, EV]]): Graph[K, VV, EV]

296

```

297

298

Adds multiple edges to the graph. Invalid edges (with non-existing vertices) are ignored.

299

300

```scala { .api }

301

def addEdge(source: Vertex[K, VV], target: Vertex[K, VV], edgeValue: EV): Graph[K, VV, EV]

302

```

303

304

Adds a single edge. If source and target vertices don't exist, they will be added.

305

306

**Parameters:**

307

- `source` - Source vertex of the edge

308

- `target` - Target vertex of the edge

309

- `edgeValue` - Value of the edge

310

311

### Removing Elements

312

313

```scala { .api }

314

def removeVertex(vertex: Vertex[K, VV]): Graph[K, VV, EV]

315

```

316

317

Removes the specified vertex and all its edges from the graph.

318

319

```scala { .api }

320

def removeVertices(vertices: List[Vertex[K, VV]]): Graph[K, VV, EV]

321

```

322

323

Removes multiple vertices and their edges from the graph.

324

325

```scala { .api }

326

def removeEdge(edge: Edge[K, EV]): Graph[K, VV, EV]

327

```

328

329

Removes all edges that match the given edge from the graph.

330

331

```scala { .api }

332

def removeEdges(edges: List[Edge[K, EV]]): Graph[K, VV, EV]

333

```

334

335

Removes multiple edges from the graph while keeping vertices intact.

336

337

## Usage Examples

338

339

### Basic Transformations

340

341

```scala

342

// Transform vertex values to uppercase

343

val transformedGraph = graph.mapVertices(vertex => vertex.getValue.toUpperCase)

344

345

// Transform edge values by doubling them

346

val doubledEdges = graph.mapEdges(edge => edge.getValue * 2)

347

```

348

349

### Filtering Operations

350

351

```scala

352

// Create subgraph with specific vertices and edges

353

val filteredGraph = graph.subgraph(

354

vertex => vertex.getValue.startsWith("A"),

355

edge => edge.getValue > 1.0

356

)

357

358

// Filter only high-value edges

359

val highValueGraph = graph.filterOnEdges(_.getValue > 5.0)

360

```

361

362

### Join Operations

363

364

```scala

365

// Join with external vertex data

366

val externalData = env.fromCollection(List((1L, "extra"), (2L, "info")))

367

val enrichedGraph = graph.joinWithVertices(externalData,

368

(vertexValue, extraInfo) => s"$vertexValue-$extraInfo")

369

370

// Join with edge weights

371

val edgeWeights = env.fromCollection(List((1L, 2L, 2.5), (2L, 3L, 1.8)))

372

val weightedGraph = graph.joinWithEdges(edgeWeights,

373

(currentValue, weight) => currentValue * weight)

374

```