Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stream output when the same file occurs with different DVs in the same batch #1897

Merged
Merged
Show file tree
Hide file tree
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 @@ -20,9 +20,7 @@ package org.apache.spark.sql.delta.sources
import java.io.FileNotFoundException
import java.sql.Timestamp

import scala.collection.mutable
import scala.util.{Failure, Success, Try}
import scala.util.control.NonFatal
import scala.util.matching.Regex

import org.apache.spark.sql.delta._
Expand Down Expand Up @@ -316,16 +314,40 @@ trait DeltaSourceBase extends Source
* @param indexedFiles actions iterator from which to generate the DataFrame.
*/
protected def createDataFrame(indexedFiles: Iterator[IndexedFile]): DataFrame = {
val addFilesList = indexedFiles
.map(_.getFileAction)
.filter(_.isInstanceOf[AddFile])
.asInstanceOf[Iterator[AddFile]].toArray

deltaLog.createDataFrame(
readSchemaSnapshotDescriptor,
addFilesList,
isStreaming = true
)
val addFiles = indexedFiles
.filter(_.getFileAction.isInstanceOf[AddFile])
.toSeq
val hasDeletionVectors =
addFiles.exists(_.getFileAction.asInstanceOf[AddFile].deletionVector != null)
if (hasDeletionVectors) {
// Read AddFiles from different versions in different scans.
// This avoids an issue where we might read the same file with different deletion vectors in
// the same scan, which we cannot support as long we broadcast a map of DVs for lookup.
// This code can be removed once we can pass the DVs into the scan directly together with the
// AddFile/PartitionedFile entry.
addFiles
.groupBy(_.version)
.values
.map { addFilesList =>
deltaLog.createDataFrame(
readSchemaSnapshotDescriptor,
addFilesList.map(_.getFileAction.asInstanceOf[AddFile]),
isStreaming = true)
}
.reduceOption(_ union _)
.getOrElse {
// If we filtered out all the values before the groupBy, just return an empty DataFrame.
deltaLog.createDataFrame(
readSchemaSnapshotDescriptor,
Seq.empty[AddFile],
isStreaming = true)
}
} else {
deltaLog.createDataFrame(
readSchemaSnapshotDescriptor,
addFiles.map(_.getFileAction.asInstanceOf[AddFile]),
isStreaming = true)
}
}

/**
Expand Down
Loading
Loading