Skip to content

Commit

Permalink
Skip getFileStatus call during iceberg to delta clone (#3825)
Browse files Browse the repository at this point in the history
<!--
Thanks for sending a pull request!  Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
https://github.com/delta-io/delta/blob/master/CONTRIBUTING.md
2. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]
Your PR title ...'.
  3. Be sure to keep the PR description updated to reflect all changes.
  4. Please write your PR title to summarize what this PR proposes.
5. If possible, provide a concise example to reproduce the issue for a
faster review.
6. If applicable, include the corresponding issue number in the PR title
and link it in the body.
-->

#### Which Delta project/connector is this regarding?
<!--
Please add the component selected below to the beginning of the pull
request title
For example: [Spark] Title of my pull request
-->

- [x] Spark
- [ ] Standalone
- [ ] Flink
- [ ] Kernel
- [ ] Other (fill in here)

## Description

use snapshot time as the Delta AddFile modificationTime

## How was this patch tested?

UT

## Does this PR introduce _any_ user-facing changes?

<!--
If yes, please clarify the previous behavior and the change this PR
proposes - provide the console output, description and/or an example to
show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change
compared to the released Delta Lake versions or within the unreleased
branches such as master.
If no, write 'No'.
-->
No
  • Loading branch information
lzlfred authored Oct 29, 2024
1 parent 0d960ad commit 285ed6b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,16 @@ class IcebergFileManifest(
spark.sessionState.conf.getConf(DeltaSQLConf.DELTA_CONVERT_ICEBERG_UNSAFE_MOR_TABLE_ENABLE)

var numFiles = 0L
val skipGetFileStatus = spark.sessionState.conf.getConf(
DeltaSQLConf.DELTA_CLONE_ICEBERG_SKIP_GETFILESTATUS)
val snapshotTimestamp: Option[Long] = Option(table.currentSnapshot()).map(_.timestampMillis())

val res = table.newScan().planFiles().iterator().asScala.grouped(schemaBatchSize).map { batch =>
logInfo(log"Getting file statuses for a batch of " +
log"${MDC(DeltaLogKeys.BATCH_SIZE, batch.size)} of files; " +
log"finished ${MDC(DeltaLogKeys.NUM_FILES, numFiles)} files so far")
numFiles += batch.length
val filePathWithPartValues = batch.map { fileScanTask =>
val filePathWithPartValuesAndSize = batch.map { fileScanTask =>
val filePath = fileScanTask.file().path().toString
// If an Iceberg table has deletion file associated with the data file (Supported in
// Iceberg V2, either position deletes or equality deletes), we could not convert directly.
Expand All @@ -129,18 +133,23 @@ class IcebergFileManifest(
Some(convertIcebergPartitionToPartitionValues(
fileScanTask.file().partition()))
} else None
(filePath, partitionValues)
(filePath, partitionValues, fileScanTask.file.fileSizeInBytes())
}
val numParallelism = Math.min(Math.max(filePathWithPartValues.size, 1),
val numParallelism = Math.min(Math.max(filePathWithPartValuesAndSize.size, 1),
spark.sparkContext.defaultParallelism)

val rdd = spark.sparkContext.parallelize(filePathWithPartValues, numParallelism)
val rdd = spark.sparkContext.parallelize(filePathWithPartValuesAndSize, numParallelism)
.mapPartitions { iterator =>
iterator.map { case (filePath, partValues) =>
val path = new Path(filePath)
val fs = path.getFileSystem(conf.value.value)
val fileStatus = fs.getFileStatus(path)
ConvertTargetFile(SerializableFileStatus.fromStatus(fileStatus), partValues)
iterator.map { case (filePath, partValues, size) =>
val serializableFileStatus = (skipGetFileStatus, snapshotTimestamp) match {
case (true, Some(ts)) =>
SerializableFileStatus(filePath, size, isDir = false, ts)
case _ =>
val path = new Path(filePath)
val fs = path.getFileSystem(conf.value.value)
SerializableFileStatus.fromStatus(fs.getFileStatus(path))
}
ConvertTargetFile(serializableFileStatus, partValues)
}
}
spark.createDataset(rdd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ abstract class CloneConvertedSource(spark: SparkSession) extends CloneSource {
val basePath = new Path(baseDir)
val fs = basePath.getFileSystem(conf.value.value)
targetFile.map(ConvertUtils.createAddFile(
_, basePath, fs, SQLConf.get, Some(partitionSchema)))
_, basePath, fs, SQLConf.get, Some(partitionSchema), useAbsolutePath = true))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,15 @@ trait DeltaSQLConfBase {
.booleanConf
.createWithDefault(true)

val DELTA_CLONE_ICEBERG_SKIP_GETFILESTATUS = {
buildConf("clone.IcebergSkipGetFileStatus")
.internal()
.doc("If clone with Iceberg source can skip getFileStatus and " +
"use snapshot timestamp as the modificationTime for Delta AddFile")
.booleanConf
.createWithDefault(true)
}

val DELTA_OPTIMIZE_METADATA_QUERY_ENABLED =
buildConf("optimizeMetadataQuery.enabled")
.internal()
Expand Down

0 comments on commit 285ed6b

Please sign in to comment.