Structured Streaming is a scalable and fault-tolerant stream processing engine built on the Spark SQL engine. It allows you to process live data streams using the same APIs as batch data.
Click to reveal answer
beginner
How does Structured Streaming treat streaming data internally?
Structured Streaming treats streaming data as an unbounded table that is continuously appended. Queries on this table produce incremental results as new data arrives.
Click to reveal answer
intermediate
What is a 'trigger' in Structured Streaming?
A trigger defines how often the streaming query processes new data. For example, a trigger can run the query every 1 second or process data as soon as it arrives.
Click to reveal answer
intermediate
Name two common output modes in Structured Streaming.
1. Append mode: Only new rows are added to the output. 2. Complete mode: The entire result table is output every time. There is also Update mode which outputs only rows that changed.
Click to reveal answer
intermediate
What is checkpointing in Structured Streaming and why is it important?
Checkpointing saves the state and progress of a streaming query to reliable storage. It helps recover from failures without losing data or processing progress.
Click to reveal answer
What does Structured Streaming treat streaming data as?
AAn unbounded table
BA static file
CA batch job
DA database
✗ Incorrect
Structured Streaming treats streaming data as an unbounded table that keeps growing as new data arrives.
Which output mode outputs only new rows added since the last trigger?
AOverwrite mode
BComplete mode
CUpdate mode
DAppend mode
✗ Incorrect
Append mode outputs only the new rows added since the last trigger.
What is the purpose of checkpointing in Structured Streaming?
ATo speed up queries
BTo format output
CTo save query progress for recovery
DTo delete old data
✗ Incorrect
Checkpointing saves the state and progress so the query can recover after failures.
Which API does Structured Streaming use to process data?
ASpark SQL DataFrame API
BRDD API
CMapReduce API
DHadoop API
✗ Incorrect
Structured Streaming uses the Spark SQL DataFrame API for processing streaming data.
What does a trigger control in Structured Streaming?
AHow data is stored
BHow often the query runs
CThe output format
DThe data source
✗ Incorrect
A trigger controls how often the streaming query processes new data.
Explain how Structured Streaming processes live data using the concept of an unbounded table.
Think about how new data keeps adding rows to a table that never ends.
You got /3 concepts.
Describe the role of checkpointing and triggers in ensuring reliable and timely streaming data processing.
Checkpointing helps recover from crashes; triggers decide when to run the query.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of Structured Streaming in Apache Spark?
easy
A. To visualize data using charts and graphs
B. To batch process large static datasets
C. To store data permanently in a database
D. To process live data continuously as it arrives
Solution
Step 1: Understand Structured Streaming concept
Structured Streaming is designed to handle data streams, meaning data that arrives continuously over time.
Step 2: Compare with other options
Batch processing handles static data, storing data is not the main function, and visualization is separate from streaming.
Final Answer:
To process live data continuously as it arrives -> Option D
Quick Check:
Structured Streaming = continuous live data processing [OK]
Hint: Streaming means live, continuous data processing [OK]
Common Mistakes:
Confusing streaming with batch processing
Thinking streaming stores data permanently
Assuming streaming is for visualization
2. Which of the following is the correct way to start reading a streaming DataFrame in Spark?
easy
A. spark.read.format("json").load("path")
B. spark.readStream.format("json").load("path")
C. spark.writeStream.format("json").load("path")
D. spark.write.format("json").load("path")
Solution
Step 1: Identify streaming read syntax
To read streaming data, use readStream with format and load.
Step 2: Eliminate non-streaming options
read is for batch, writeStream is for output, so only readStream with load is correct.
Final Answer:
spark.readStream.format("json").load("path") -> Option B
Quick Check:
Streaming read uses readStream [OK]
Hint: Use readStream to read streaming data [OK]
Common Mistakes:
Using read instead of readStream for streaming data
Confusing writeStream with readStream
Using writeStream with load instead of start
3. Given the code below, what will be the output schema of the streaming DataFrame?
A. Missing option to specify output mode in writeStream
B. awaitTermination does not take any arguments
C. Incorrect format 'console' should be 'Console'
D. start() must be called after awaitTermination()
Solution
Step 1: Check writeStream requirements
In Structured Streaming, writeStream requires outputMode() (e.g., "append") to be specified before format() for sinks like console.
Step 2: Verify other parts
awaitTermination(10) accepts a timeout argument, format 'console' is correct lowercase, and start() must be called before awaitTermination().
Final Answer:
Missing option to specify output mode in writeStream -> Option A
Quick Check:
writeStream requires outputMode [OK]
Hint: writeStream requires outputMode [OK]
Common Mistakes:
Missing outputMode in writeStream
Thinking awaitTermination does not take timeout
Misusing start and awaitTermination order
5. You want to count the number of words in a live stream of text lines from a socket source. Which sequence of operations correctly applies Structured Streaming to achieve this?
hard
A. Read stream from socket, split lines into words, group by word, count, write stream to console
B. Read batch from socket, split lines into words, group by word, count, write batch to file
C. Read stream from socket, count lines directly, write stream to console
D. Read stream from socket, split lines into words, filter empty words, write batch to console
Solution
Step 1: Understand streaming word count steps
Streaming word count requires reading live data, splitting lines into words, grouping by word, and counting occurrences continuously.
Step 2: Check options for correctness
Read stream from socket, split lines into words, group by word, count, write stream to console follows the correct streaming steps with writeStream to console. Read batch from socket, split lines into words, group by word, count, write batch to file uses batch, not streaming. Read stream from socket, count lines directly, write stream to console counts lines, not words. Read stream from socket, split lines into words, filter empty words, write batch to console writes batch, not stream, and misses counting.
Final Answer:
Read stream from socket, split lines into words, group by word, count, write stream to console -> Option A