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

[Spark] Remove unused method and do a little refactor in Checkpoints.scala #3874

Merged
merged 2 commits into from
Nov 14, 2024
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
18 changes: 14 additions & 4 deletions spark/src/main/scala/org/apache/spark/sql/delta/Checkpoints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.util.UUID

import scala.collection.mutable
import scala.math.Ordering.Implicits._
import scala.util.Try
import scala.util.control.NonFatal

// scalastyle:off import.ordering.noEmptyLine
Expand Down Expand Up @@ -376,13 +377,22 @@ trait Checkpoints extends DeltaLogging {
loadMetadataFromFile(0)
}

/**
* Reads the checkpoint metadata from the `_last_checkpoint` file. This method doesn't handle any
* exceptions that can be thrown, for example IOExceptions thrown when reading the data such as
* FileNotFoundExceptions which is expected for a new Delta table or JSON deserialization errors.
*/
protected def unsafeLoadMetadataFromFile(): LastCheckpointInfo = {
val lastCheckpointInfoJson = store.read(LAST_CHECKPOINT, newDeltaHadoopConf())
val validate = LastCheckpointInfo.checksumEnabled(spark)
LastCheckpointInfo.deserializeFromJson(lastCheckpointInfoJson.head, validate)
}

/** Loads the checkpoint metadata from the _last_checkpoint file. */
private def loadMetadataFromFile(tries: Int): Option[LastCheckpointInfo] =
protected def loadMetadataFromFile(tries: Int): Option[LastCheckpointInfo] =
recordDeltaOperation(self, "delta.deltaLog.loadMetadataFromFile") {
try {
val lastCheckpointInfoJson = store.read(LAST_CHECKPOINT, newDeltaHadoopConf())
val validate = LastCheckpointInfo.checksumEnabled(spark)
Some(LastCheckpointInfo.deserializeFromJson(lastCheckpointInfoJson.head, validate))
Some(unsafeLoadMetadataFromFile())
} catch {
case _: FileNotFoundException =>
None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,32 +306,6 @@ object DeltaDataSource extends DatabricksLogging {
Serialization.read[Seq[String]](str)
}

/**
* Extract the Delta path if `dataset` is created to load a Delta table. Otherwise returns `None`.
* Table UI in universe will call this.
*/
def extractDeltaPath(dataset: Dataset[_]): Option[String] = {
if (dataset.isStreaming) {
dataset.queryExecution.logical match {
case logical: org.apache.spark.sql.execution.streaming.StreamingRelation =>
if (logical.dataSource.providingClass == classOf[DeltaDataSource]) {
CaseInsensitiveMap(logical.dataSource.options).get("path")
} else {
None
}
case _ => None
}
} else {
dataset.queryExecution.analyzed match {
case DeltaTable(tahoeFileIndex) =>
Some(tahoeFileIndex.path.toString)
case SubqueryAlias(_, DeltaTable(tahoeFileIndex)) =>
Some(tahoeFileIndex.path.toString)
case _ => None
}
}
}

/**
* For Delta, we allow certain magic to be performed through the paths that are provided by users.
* Normally, a user specified path should point to the root of a Delta table. However, some users
Expand Down
Loading