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

[Hudi] setCommitFileUpdates bug fix #3309

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 @@ -86,9 +86,10 @@ class HudiConversionTransaction(
private var metaClient = providedMetaClient
private val instantTime = convertInstantToCommit(
Instant.ofEpochMilli(postCommitSnapshot.timestamp))
private var writeStatuses: util.List[WriteStatus] = Collections.emptyList[WriteStatus]
private var writeStatuses: util.List[WriteStatus] =
new util.ArrayList[WriteStatus]()
private var partitionToReplacedFileIds: util.Map[String, util.List[String]] =
Collections.emptyMap[String, util.List[String]]
new util.HashMap[String, util.List[String]]()

private val version = postCommitSnapshot.version
/** Tracks if this transaction has already committed. You can only commit once. */
Expand All @@ -101,7 +102,7 @@ class HudiConversionTransaction(
def setCommitFileUpdates(actions: scala.collection.Seq[Action]): Unit = {
// for all removed files, group by partition path and then map to
// the file group ID (name in this case)
partitionToReplacedFileIds = actions
val newPartitionToReplacedFileIds = actions
.map(_.wrap)
.filter(action => action.remove != null)
.map(_.remove)
Expand All @@ -111,15 +112,17 @@ class HudiConversionTransaction(
(partitionPath, path.getName)})
.groupBy(_._1).map(v => (v._1, v._2.map(_._2).asJava))
.asJava
partitionToReplacedFileIds.putAll(newPartitionToReplacedFileIds)
// Convert the AddFiles to write statuses for the commit
writeStatuses = actions
val newWriteStatuses = actions
.map(_.wrap)
.filter(action => action.add != null)
.map(_.add)
.map(add => {
convertAddFile(add, tablePath, instantTime)
})
.asJava
writeStatuses.addAll(newWriteStatuses)
}

def commit(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.apache.spark.sql.avro.SchemaConverters
import org.apache.spark.sql.delta.DeltaOperations.Truncate
import org.apache.spark.sql.delta.{DeltaConfigs, DeltaLog, DeltaUnsupportedOperationException, OptimisticTransaction}
import org.apache.spark.sql.delta.actions.{Action, AddFile, Metadata, RemoveFile}
import org.apache.spark.sql.delta.sources.DeltaSQLConf
import org.apache.spark.sql.types.StructType
import org.apache.spark.util.{ManualClock, Utils}
import org.scalatest.concurrent.Eventually
Expand Down Expand Up @@ -212,6 +213,25 @@ class ConvertToHudiSuite extends QueryTest with Eventually {
verifyFilesAndSchemaMatch()
}

test("all batches of actions are converted") {
withSQLConf(
DeltaSQLConf.HUDI_MAX_COMMITS_TO_CONVERT.key -> "3"
) {
_sparkSession.sql(
s"""CREATE TABLE `$testTableName` (col1 INT)
| USING DELTA
|LOCATION '$testTablePath'""".stripMargin)
for (i <- 1 to 10) {
_sparkSession.sql(s"INSERT INTO `$testTableName` VALUES ($i)")
}
_sparkSession.sql(
s"""ALTER TABLE `$testTableName` SET TBLPROPERTIES (
| 'delta.universalFormat.enabledFormats' = 'hudi'
|)""".stripMargin)
verifyFilesAndSchemaMatch()
}
}

def buildHudiMetaClient(): HoodieTableMetaClient = {
val hadoopConf: Configuration = _sparkSession.sparkContext.hadoopConfiguration
HoodieTableMetaClient.builder
Expand Down
Loading