databricks Associate Developer for Apache Spark · Practice questions

Section 5: Structured Streaming Practice Questions

Review 10 sample questions with their correct answers and explanations. Sign up free to continue with the full topic quiz.

Sign up free for the full quiz

Question 1

In the Kafka source, which column contains the message payload?

  1. payload, as a string
  2. value, as binary — Correct
  3. message, as a struct
  4. data, as JSON

Correct answer

value, as binary

Explanation

Kafka source rows include key, value, topic, partition, offset and timestamp; key and value are binary.

Question 2

Which three elements together allow Structured Streaming to achieve end-to-end exactly-once guarantees?

  1. Replayable sources, checkpoints and idempotent sinks — Correct
  2. Broadcast variables, accumulators and caching
  3. A single executor, a single core and the console sink
  4. Speculative execution, AQE and Photon

Correct answer

Replayable sources, checkpoints and idempotent sinks

Explanation

Exactly-once requires sources that can replay data, offsets and state saved in the checkpoint, and sinks that handle replays safely.

Question 3

Which code defines sliding windows of 10 minutes that start every 5 minutes?

  1. window('event_time', '10 minutes').slide('5 minutes')
  2. window('event_time', '10 minutes', '5 minutes') — Correct
  3. session_window('event_time', '5 minutes')
  4. window('event_time', '5 minutes', '10 minutes')

Correct answer

window('event_time', '10 minutes', '5 minutes')

Explanation

The second argument is the window duration and the third is the slide duration.

Question 4

Which statement about a stateful operator in Structured Streaming is correct?

  1. It stores state only in driver memory
  2. It recomputes all historical data in every micro-batch
  3. It can only be used in batch queries
  4. It keeps checkpointed state across micro-batches — Correct

Correct answer

It keeps checkpointed state across micro-batches

Explanation

Stateful operators such as streaming aggregations, deduplication and arbitrary state functions keep state in a state store on executors, checkpointed for fault tolerance.

Question 5

Which code defines a watermark of 15 minutes on the column event_time?

  1. df.option('watermark', '15 minutes')
  2. df.withColumn('watermark', '15 minutes')
  3. df.withWatermark('event_time', '15 minutes') — Correct
  4. df.watermark(col('event_time'), delay='15 minutes')

Correct answer

df.withWatermark('event_time', '15 minutes')

Explanation

withWatermark(eventTimeColumn, delayThreshold) defines how late data may arrive before state is dropped.

Question 6

Which code stops a running streaming query referenced by q?

  1. q.terminate(True)
  2. q.awaitTermination(0)
  3. q.stop() — Correct
  4. spark.stop(q)

Correct answer

q.stop()

Explanation

StreamingQuery.stop() stops the query; awaitTermination waits for it.

Question 7

Which code reads a Kafka topic as a stream?

  1. spark.readStream.format('topic').load('orders')
  2. spark.readStream.format('kafka').option('kafka.bootstrap.servers', servers).option('subscribe', 'orders').load() — Correct
  3. spark.readStream.format('kafka').option('kafka.servers', servers).option('topic', 'orders').option('format', 'json').load()
  4. spark.readStream.kafka(servers, 'orders').start()

Correct answer

spark.readStream.format('kafka').option('kafka.bootstrap.servers', servers).option('subscribe', 'orders').load()

Explanation

The Kafka source requires bootstrap servers and a subscription option; the value column holds the message payload as binary.

Question 8

Which code creates a streaming DataFrame from JSON files arriving in a folder, with an explicit schema?

  1. spark.readStream.schema(schema).json('/data/incoming') — Correct
  2. spark.read.stream.json('/data/incoming')
  3. spark.streamRead('json', '/data/incoming')
  4. spark.readStream.json('/data/incoming').schema(schema).start()

Correct answer

spark.readStream.schema(schema).json('/data/incoming')

Explanation

readStream returns a DataStreamReader. File sources require a schema unless schema inference for streaming is enabled.

Question 9

Which sink is meant only for debugging, printing each micro-batch to stdout?

  1. foreachBatch
  2. delta
  3. kafka
  4. console — Correct

Correct answer

console

Explanation

The console sink prints results and is not fault tolerant; use it for testing only.

Question 10

Which PySpark API applies arbitrary stateful processing per group in a streaming query using pandas?

  1. foreachPartition
  2. groupBy().pivot()
  3. mapPartitionsWithState
  4. applyInPandasWithState — Correct

Correct answer

applyInPandasWithState

Explanation

applyInPandasWithState (and newer transformWithStateInPandas) supports custom stateful logic per key in streaming queries.

Ready for the full quiz?

Create a free QuizAnalyst account to practice the complete question set and save your progress.

Sign up free for the full quiz