Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,23 @@ class MemorySink(val schema: StructType, outputMode: OutputMode) extends Sink wi
}.mkString("\n")
}

override def addBatch(batchId: Long, data: DataFrame): Unit = synchronized {
if (latestBatchId.isEmpty || batchId > latestBatchId.get) {
override def addBatch(batchId: Long, data: DataFrame): Unit = {
val notCommitted = synchronized {
latestBatchId.isEmpty || batchId > latestBatchId.get
}
if (notCommitted) {
logDebug(s"Committing batch $batchId to $this")
outputMode match {
case InternalOutputModes.Append | InternalOutputModes.Update =>
batches.append(AddedData(batchId, data.collect()))
val rows = AddedData(batchId, data.collect())
synchronized { batches += rows }

case InternalOutputModes.Complete =>
batches.clear()
batches += AddedData(batchId, data.collect())
val rows = AddedData(batchId, data.collect())
synchronized {
batches.clear()
batches += rows
}

case _ =>
throw new IllegalArgumentException(
Expand All @@ -206,7 +213,7 @@ class MemorySink(val schema: StructType, outputMode: OutputMode) extends Sink wi
}
}

def clear(): Unit = {
def clear(): Unit = synchronized {
batches.clear()
}

Expand Down