Apache Spark GraphX and Graph Processing 1 — Questions and Answers
Question 1: What is Apache Spark GraphX primarily used for?
- Graph-parallel computation and graph analytics (Correct answer)
- Real-time stream processing of graph data
- Machine learning on tabular datasets
- SQL queries on graph databases
Correct answer: Graph-parallel computation and graph analytics
GraphX is Spark's API for graph-parallel computation, enabling graph creation, transformation, and execution of graph algorithms at scale.
Question 2: In GraphX, what are the two fundamental components of a Property Graph?
- Edges and Paths
- Vertices and Edges (Correct answer)
- Nodes and Relationships
- Rows and Columns
Correct answer: Vertices and Edges
A Property Graph in GraphX consists of vertices (nodes) and edges (connections), each carrying associated user-defined properties.
Question 3: Which data type is used as a vertex identifier (VertexId) in GraphX?
- String
- UUID
- Long (64-bit integer) (Correct answer)
- Integer (32-bit)
Correct answer: Long (64-bit integer)
GraphX defines VertexId as a type alias for Long, providing a large namespace of unique IDs suitable for billions of vertices.
Question 4: What distributed collection type does GraphX use internally to store vertex attributes?
- DataFrame
- VertexRDD (Correct answer)
- HashSet
- DenseVector
Correct answer: VertexRDD
GraphX uses VertexRDD[VD], which extends RDD[(VertexId, VD)], to store and index vertex attributes as key-value pairs.
Question 5: What method in GraphX creates a graph from an RDD of edges, assigning a default attribute to all vertices?
- Graph.fromVertices()
- Graph.fromEdges() (Correct answer)
- Graph.apply()
- Graph.edgeListFile()
Correct answer: Graph.fromEdges()
Graph.fromEdges() constructs a graph from an RDD[Edge[ED]] and automatically creates vertex entries with a supplied default attribute.
Question 6: What does the `triplets` property of a GraphX Graph return?
- Three separate RDDs for source, edge, and destination
- An RDD of EdgeTriplet objects containing source vertex, edge, and destination vertex attributes (Correct answer)
- A tuple of (VertexRDD, EdgeRDD, PartitionRDD)
- An array of three graphs representing different structural views
Correct answer: An RDD of EdgeTriplet objects containing source vertex, edge, and destination vertex attributes
The `triplets` property returns an RDD[EdgeTriplet[VD, ED]], where each triplet combines the source vertex, the connecting edge, and the destination vertex with all their attributes.
Question 7: Which GraphX edge partitioning strategy assigns edges to partitions based solely on the source vertex ID?
- RandomVertexCut
- CanonicalRandomVertexCut
- EdgePartition1D (Correct answer)
- EdgePartition2D
Correct answer: EdgePartition1D
EdgePartition1D assigns edges to partitions by hashing only the source vertex ID, colocating all outgoing edges from the same vertex in one partition.
What is Apache Spark GraphX primarily used for?