-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from metabolicdata/feature/icerberg
WIP Iceberg integration
- Loading branch information
Showing
25 changed files
with
1,285 additions
and
135 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.2.0") | ||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.6") | ||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.6") | ||
addDependencyTreePlugin |
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
21 changes: 21 additions & 0 deletions
21
src/main/scala/com/metabolic/data/core/services/spark/reader/table/GenericReader.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,21 @@ | ||
package com.metabolic.data.core.services.spark.reader.table | ||
|
||
import com.metabolic.data.core.services.spark.reader.DataframeUnifiedReader | ||
import org.apache.logging.log4j.scala.Logging | ||
import org.apache.spark.sql.{DataFrame, SparkSession} | ||
|
||
class GenericReader(fqn: String) extends DataframeUnifiedReader with Logging{ | ||
|
||
override val input_identifier: String = fqn | ||
|
||
override def readBatch(spark: SparkSession): DataFrame = { | ||
//Generic for Delta Lake and Iceberg tables using fqn | ||
spark.table(input_identifier) | ||
} | ||
|
||
override def readStream(spark: SparkSession): DataFrame = { | ||
//Generic for Delta Lake and Iceberg tables using fqn | ||
spark.readStream.table(input_identifier) | ||
} | ||
|
||
} |
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
93 changes: 93 additions & 0 deletions
93
src/main/scala/com/metabolic/data/core/services/spark/writer/file/IcebergWriter.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,93 @@ | ||
package com.metabolic.data.core.services.spark.writer.file | ||
|
||
import com.metabolic.data.core.services.spark.writer.DataframeUnifiedWriter | ||
import com.metabolic.data.mapper.domain.io.WriteMode | ||
import com.metabolic.data.mapper.domain.io.WriteMode.WriteMode | ||
import org.apache.spark.sql.streaming.{StreamingQuery, Trigger} | ||
import org.apache.spark.sql.{AnalysisException, DataFrame, SparkSession} | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
class IcebergWriter( | ||
val fqn: String, | ||
val writeMode: WriteMode, | ||
val checkpointLocation: String) | ||
(implicit val spark: SparkSession) | ||
extends DataframeUnifiedWriter { | ||
|
||
override val output_identifier: String = fqn | ||
|
||
override def writeBatch(df: DataFrame): Unit = { | ||
|
||
writeMode match { | ||
case WriteMode.Append => | ||
try { | ||
df.writeTo(output_identifier).using("iceberg").create() | ||
}catch { | ||
case e: AnalysisException => | ||
logger.warn("Create table failed: " + e) | ||
df.writeTo(output_identifier).append() | ||
} | ||
|
||
case WriteMode.Overwrite => | ||
try { | ||
df.writeTo(output_identifier).using("iceberg").create() | ||
}catch { | ||
case e: AnalysisException => | ||
logger.warn("Create table failed: " + e) | ||
df.writeTo(output_identifier).using("iceberg").replace() | ||
} | ||
|
||
case WriteMode.Upsert => | ||
try { | ||
df.writeTo(output_identifier).using("iceberg").create() | ||
}catch { | ||
case e: AnalysisException => | ||
logger.warn("Create table failed: " + e) | ||
df.writeTo(output_identifier).overwritePartitions() | ||
} | ||
|
||
|
||
case WriteMode.Delete => | ||
throw new NotImplementedError("Delete is not supported in Iceberg yet") | ||
|
||
case WriteMode.Update => | ||
throw new NotImplementedError("Update is not supported in Iceberg yet") | ||
|
||
} | ||
} | ||
|
||
override def writeStream(df: DataFrame): StreamingQuery = { | ||
|
||
writeMode match { | ||
case WriteMode.Append => | ||
df | ||
.writeStream | ||
.format("iceberg") | ||
.outputMode("append") | ||
.trigger(Trigger.ProcessingTime(1, TimeUnit.MINUTES)) | ||
.option("checkpointLocation", checkpointLocation) | ||
.toTable(output_identifier) | ||
|
||
case WriteMode.Complete => | ||
df | ||
.writeStream | ||
.format("iceberg") | ||
.outputMode("complete") | ||
.trigger(Trigger.ProcessingTime(1, TimeUnit.MINUTES)) | ||
.option("checkpointLocation", checkpointLocation) | ||
.toTable(output_identifier) | ||
|
||
} | ||
} | ||
|
||
//TODO: do we need to do any specific post write operations in Iceberg? | ||
// | ||
// override def postHook(df: DataFrame, query: Seq[StreamingQuery]): Unit = { | ||
// | ||
// if (query.isEmpty) { | ||
// spark.sql(s"CALL local.system.rewrite_data_files('$output_identifier')") | ||
// } | ||
// } | ||
|
||
} |
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
Oops, something went wrong.