-
Notifications
You must be signed in to change notification settings - Fork 21
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 #120 from osopardo1/append-index-status-builder
Fixed #119
- Loading branch information
Showing
2 changed files
with
66 additions
and
1 deletion.
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
65 changes: 65 additions & 0 deletions
65
src/test/scala/io/qbeast/spark/delta/IndexStatusBuilderTest.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,65 @@ | ||
package io.qbeast.spark.delta | ||
|
||
import io.qbeast.core.model.{CubeId, CubeStatus, Weight} | ||
import io.qbeast.spark.QbeastIntegrationTestSpec | ||
import org.apache.spark.sql.delta.DeltaLog | ||
|
||
class IndexStatusBuilderTest extends QbeastIntegrationTestSpec { | ||
|
||
"IndexBuilder" should "build cube information from DeltaLog" in withSparkAndTmpDir( | ||
(spark, tmpDir) => { | ||
import spark.implicits._ | ||
val data = 0.to(100000).toDF("id") | ||
|
||
// Append data x times | ||
data.write | ||
.format("qbeast") | ||
.option("columnsToIndex", "id") | ||
.option("cubeSize", "10000") | ||
.save(tmpDir) | ||
|
||
val deltaLog = DeltaLog.forTable(spark, tmpDir) | ||
val indexStatus = | ||
DeltaQbeastSnapshot(deltaLog.snapshot).loadLatestIndexStatus | ||
|
||
indexStatus.revision.revisionID shouldBe 1 | ||
indexStatus.cubesStatuses.foreach(_._2.files.size shouldBe 1) | ||
indexStatus.replicatedSet shouldBe Set.empty | ||
indexStatus.announcedSet shouldBe Set.empty | ||
}) | ||
|
||
it should "work well on appending the same revision" in withSparkAndTmpDir((spark, tmpDir) => { | ||
|
||
import spark.implicits._ | ||
val data = 0.to(100000).toDF("id") | ||
|
||
// Append data x times | ||
data.write | ||
.format("qbeast") | ||
.option("columnsToIndex", "id") | ||
.option("cubeSize", "10000") | ||
.save(tmpDir) | ||
val deltaLog = DeltaLog.forTable(spark, tmpDir) | ||
val firstIndexStatus = DeltaQbeastSnapshot(deltaLog.snapshot).loadLatestIndexStatus | ||
data.write | ||
.format("qbeast") | ||
.mode("append") | ||
.option("columnsToIndex", "id") | ||
.option("cubeSize", "10000") | ||
.save(tmpDir) | ||
val secondIndexStatus = DeltaQbeastSnapshot(deltaLog.update()).loadLatestIndexStatus | ||
|
||
secondIndexStatus.revision.revisionID shouldBe 1 | ||
secondIndexStatus.announcedSet shouldBe Set.empty | ||
secondIndexStatus.replicatedSet shouldBe Set.empty | ||
secondIndexStatus.cubesStatuses.foreach(_._2.files.size shouldBe <=(2)) | ||
secondIndexStatus.cubesStatuses.foreach { case (cube: CubeId, cubeStatus: CubeStatus) => | ||
if (cubeStatus.maxWeight < Weight.MaxValue) { | ||
firstIndexStatus.cubesStatuses.get(cube) shouldBe defined | ||
cubeStatus.maxWeight shouldBe cubeStatus.files.map(_.maxWeight).min | ||
cubeStatus.maxWeight shouldBe <=(firstIndexStatus.cubesStatuses(cube).maxWeight) | ||
} | ||
} | ||
}) | ||
|
||
} |