forked from delta-io/delta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to support customization of delta file names - 0.6 branch (de…
…lta-io#5) * pick workflows onto branch-0.6 * Parse file metadata as a separate task * change version to distinguish this branch
- Loading branch information
Ryan Murray
committed
Sep 27, 2020
1 parent
7cdc891
commit d6c9e24
Showing
11 changed files
with
272 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Main CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- branch-0.6 | ||
|
||
jobs: | ||
java: | ||
name: Scala/sbt | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
- uses: olafurpg/setup-scala@v5 | ||
- name: Cache local sbt repository | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.ivy2/cache | ||
~/.sbt | ||
key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }} | ||
- name: Build with sbt | ||
run: sbt test publishM2 | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
- name: Push with maven | ||
run: | | ||
export VERSION=`cat version.sbt|awk '{print $5}'|sed 's/"//g'` | ||
# maven doesn't like pushing from local repository so we copy before pushing | ||
cp /home/runner/.m2/repository/io/delta/delta-core_2.12/$VERSION/delta-core_2.12-$VERSION.* . | ||
mvn -B deploy:deploy-file -DpomFile=delta-core_2.12-$VERSION.pom -DrepositoryId=github -Dfile=delta-core_2.12-$VERSION.jar -Durl=https://maven.pkg.github.com/projectnessie/delta | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Pull Request CI Test | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
java: | ||
name: Scala/sbt | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
- uses: olafurpg/setup-scala@v5 | ||
- name: Cache local sbt repository | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.ivy2/cache | ||
~/.sbt | ||
key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }} | ||
- name: Build with sbt | ||
run: sbt compile test | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/main/scala/org/apache/spark/sql/delta/LogFileMetaParser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (2020) The Delta Lake Project Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.delta | ||
|
||
import org.apache.hadoop.conf.Configuration | ||
import org.apache.hadoop.fs.{FileStatus, Path} | ||
import org.apache.spark.{SparkConf, SparkContext} | ||
import org.apache.spark.internal.Logging | ||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.delta.storage.LogStore | ||
import org.apache.spark.sql.delta.util.FileNames.{checkpointVersion, deltaVersion, isCheckpointFile, isChecksumFile, isDeltaFile, numCheckpointParts} | ||
import org.apache.spark.util.Utils | ||
|
||
import scala.util.Try | ||
|
||
sealed case class DeltaFileType(value: String) | ||
|
||
object DeltaFileType { | ||
object DELTA extends DeltaFileType("DELTA") | ||
object CHECKPOINT extends DeltaFileType("CHECKPOINT") | ||
object CHECKSUM extends DeltaFileType("CHECKSUM") | ||
object UNKNOWN extends DeltaFileType("UNKNOWN") | ||
|
||
val values = Seq(DELTA, CHECKPOINT, CHECKSUM, UNKNOWN) | ||
|
||
def getFileType(path: Path): DeltaFileType = { | ||
path match { | ||
case f if isCheckpointFile(f) => DeltaFileType.CHECKPOINT | ||
case f if isDeltaFile(f) => DeltaFileType.DELTA | ||
case f if isChecksumFile(f) => DeltaFileType.CHECKSUM | ||
case _ => DeltaFileType.UNKNOWN | ||
} | ||
} | ||
} | ||
|
||
case class LogFileMeta(fileStatus: FileStatus, | ||
version: Long, | ||
fileType: DeltaFileType, | ||
numParts: Option[Int]) { | ||
|
||
def asCheckpointInstance(): CheckpointInstance = { | ||
CheckpointInstance(version, numParts) | ||
} | ||
} | ||
|
||
object LogFileMeta { | ||
def isCheckpointFile(logFileMeta: LogFileMeta): Boolean = { | ||
logFileMeta.fileType == DeltaFileType.CHECKPOINT | ||
} | ||
|
||
def isDeltaFile(logFileMeta: LogFileMeta): Boolean = { | ||
logFileMeta.fileType == DeltaFileType.DELTA | ||
} | ||
} | ||
|
||
|
||
class LogFileMetaParser(logStore: LogStore) { | ||
|
||
def listFilesFrom(logPath: Path): Iterator[LogFileMeta] = { | ||
|
||
logStore.listFrom(logPath).map(fs => { | ||
LogFileMeta(fs, | ||
Try(deltaVersion(fs.getPath)).getOrElse(Try(checkpointVersion(fs.getPath)).getOrElse(-1L)), | ||
DeltaFileType.getFileType(fs.getPath), | ||
numCheckpointParts(fs.getPath)) | ||
}) | ||
} | ||
|
||
} | ||
|
||
object LogFileMetaParser extends LogFileMetaProvider | ||
with Logging { | ||
|
||
def apply(sc: SparkContext, logStore: LogStore): LogFileMetaParser = { | ||
apply(sc.getConf, sc.hadoopConfiguration, logStore) | ||
} | ||
|
||
def apply(sparkConf: SparkConf, | ||
hadoopConf: Configuration, | ||
logStore: LogStore): LogFileMetaParser = { | ||
createLogFileMetaParser(sparkConf, hadoopConf, logStore) | ||
} | ||
} | ||
|
||
trait LogFileMetaProvider { | ||
|
||
def createLogFileMetaParser(spark: SparkSession, logStore: LogStore): LogFileMetaParser = { | ||
val sc = spark.sparkContext | ||
createLogFileMetaParser(sc.getConf, sc.hadoopConfiguration, logStore) | ||
} | ||
|
||
def createLogFileMetaParser(sparkConf: SparkConf, | ||
hadoopConf: Configuration, | ||
logStore: LogStore): LogFileMetaParser = { | ||
val logStoreClassName = sparkConf.get("spark.delta.logFileHandler.class", | ||
classOf[LogFileMetaParser].getName) | ||
val logStoreClass = Utils.classForName(logStoreClassName) | ||
logStoreClass.getConstructor(classOf[LogStore]) | ||
.newInstance(logStore).asInstanceOf[LogFileMetaParser] | ||
} | ||
} |
Oops, something went wrong.