-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate doc ID in build index job for idempotency (#1803)
* Add doc id to DF by Spark built-in sha1 function Signed-off-by: Chen Dai <daichen@amazon.com> * Add UT Signed-off-by: Chen Dai <daichen@amazon.com> * Fix broken IT Signed-off-by: Chen Dai <daichen@amazon.com> * Change id column name to avoid conflict with user data Signed-off-by: Chen Dai <daichen@amazon.com> --------- Signed-off-by: Chen Dai <daichen@amazon.com>
- Loading branch information
Showing
6 changed files
with
76 additions
and
9 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
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
42 changes: 42 additions & 0 deletions
42
...ion/src/test/scala/org/opensearch/flint/spark/skipping/FlintSparkSkippingIndexSuite.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,42 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.spark.skipping | ||
|
||
import org.mockito.Mockito.when | ||
import org.opensearch.flint.spark.FlintSparkIndex.ID_COLUMN | ||
import org.opensearch.flint.spark.skipping.FlintSparkSkippingIndex.FILE_PATH_COLUMN | ||
import org.scalatest.matchers.must.Matchers.contain | ||
import org.scalatest.matchers.should.Matchers.convertToAnyShouldWrapper | ||
import org.scalatestplus.mockito.MockitoSugar.mock | ||
|
||
import org.apache.spark.FlintSuite | ||
import org.apache.spark.sql.catalyst.expressions.aggregate.CollectSet | ||
import org.apache.spark.sql.functions.col | ||
|
||
class FlintSparkSkippingIndexSuite extends FlintSuite { | ||
|
||
test("get skipping index name") { | ||
val index = new FlintSparkSkippingIndex("test", Seq(mock[FlintSparkSkippingStrategy])) | ||
index.name() shouldBe "flint_test_skipping_index" | ||
} | ||
|
||
test("can build index building job with unique ID column") { | ||
val indexCol = mock[FlintSparkSkippingStrategy] | ||
when(indexCol.outputSchema()).thenReturn(Map("name" -> "string")) | ||
when(indexCol.getAggregators).thenReturn(Seq(CollectSet(col("name").expr))) | ||
val index = new FlintSparkSkippingIndex("test", Seq(indexCol)) | ||
|
||
val df = spark.createDataFrame(Seq(("hello", 20))).toDF("name", "age") | ||
val indexDf = index.build(df) | ||
indexDf.schema.fieldNames should contain only ("name", FILE_PATH_COLUMN, ID_COLUMN) | ||
} | ||
|
||
test("should fail if no indexed column given") { | ||
assertThrows[IllegalArgumentException] { | ||
new FlintSparkSkippingIndex("test", Seq.empty) | ||
} | ||
} | ||
} |
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