-
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.
- Loading branch information
1 parent
1421e51
commit 2d3fefa
Showing
4 changed files
with
42 additions
and
38 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
15 changes: 15 additions & 0 deletions
15
modules/core/src/test/scala/uk/co/odinconsultants/CrudSpec.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,15 @@ | ||
package uk.co.odinconsultants | ||
import org.scalatest.GivenWhenThen | ||
import uk.co.odinconsultants.documentation_utils.{SpecPretifier, TableNameFixture} | ||
|
||
class CrudSpec extends SpecPretifier with GivenWhenThen with TableNameFixture { | ||
|
||
"A Delta table" should { | ||
"be created and populated" in new SimpleSparkFixture { | ||
val sinkSQL = createTableSQLUsingDelta(tableName) | ||
Given(s"a table created with SQL${formatSQL(sinkSQL)}") | ||
spark.sqlContext.sql(sinkSQL) | ||
} | ||
} | ||
|
||
} |
24 changes: 21 additions & 3 deletions
24
modules/core/src/test/scala/uk/co/odinconsultants/SimpleSparkFixture.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 |
---|---|---|
@@ -1,14 +1,32 @@ | ||
package uk.co.odinconsultants | ||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.{DataFrame, SparkSession} | ||
import uk.co.odinconsultants.SparkUtils.tmpDir | ||
import uk.co.odinconsultants.documentation_utils.SimpleFixture | ||
import uk.co.odinconsultants.documentation_utils.SQLUtils.createTableSQL | ||
import uk.co.odinconsultants.documentation_utils.{Datum, SimpleFixture, SpecFormats} | ||
|
||
trait SimpleSparkFixture extends SimpleFixture { | ||
trait SimpleSparkFixture extends SimpleFixture with SpecFormats { | ||
|
||
val spark: SparkSession = SparkUtils.sparkSession | ||
|
||
def dataDir(tableName: String): String = s"$tmpDir/$tableName/data" | ||
|
||
def appendData(tableName: String): Unit = spark.createDataFrame(data).writeTo(tableName).append() | ||
|
||
def aCDFTable(tableName: String, spark: SparkSession): String = { | ||
val createCDF: String = | ||
s"${createTableSQLUsingDelta(tableName)} TBLPROPERTIES (delta.enableChangeDataFeed = true)" | ||
spark.sqlContext.sql(createCDF) | ||
s"a table created with the SQL: ${formatSQL(createCDF)}" | ||
} | ||
|
||
def describeHistory( | ||
tableName: String, | ||
spark: SparkSession, | ||
): DataFrame = | ||
spark.sqlContext.sql(s"DESCRIBE HISTORY $tableName") | ||
|
||
def createTableSQLUsingDelta(tableName: String): String = | ||
s"""${createTableSQL(tableName, classOf[Datum])} | ||
|USING DELTA""".stripMargin | ||
|
||
} |