-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chen Dai <[email protected]>
- Loading branch information
Showing
6 changed files
with
195 additions
and
3 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
30 changes: 30 additions & 0 deletions
30
...la/org/opensearch/flint/spark/skipping/bloomfilter/BloomFilterSkippingStrategySuite.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,30 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.spark.skipping.bloomfilter | ||
|
||
import org.opensearch.flint.spark.skipping.{FlintSparkSkippingStrategy, FlintSparkSkippingStrategySuite} | ||
import org.opensearch.flint.spark.skipping.bloomfilter.BloomFilter.Algorithm.CLASSIC | ||
import org.opensearch.flint.spark.skipping.bloomfilter.BloomFilter.BLOOM_FILTER_ALGORITHM_KEY | ||
import org.opensearch.flint.spark.skipping.bloomfilter.ClassicBloomFilter.{CLASSIC_BLOOM_FILTER_FPP_KEY, CLASSIC_BLOOM_FILTER_NUM_ITEMS_KEY, DEFAULT_CLASSIC_BLOOM_FILTER_FPP, DEFAULT_CLASSIC_BLOOM_FILTER_NUM_ITEMS} | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
import org.apache.spark.FlintSuite | ||
|
||
class BloomFilterSkippingStrategySuite | ||
extends FlintSuite | ||
with FlintSparkSkippingStrategySuite | ||
with Matchers { | ||
|
||
/** Subclass initializes strategy class to test */ | ||
override val strategy: FlintSparkSkippingStrategy = | ||
BloomFilterSkippingStrategy(columnName = "name", columnType = "string") | ||
|
||
test("parameters") { | ||
strategy.parameters should contain allOf (BLOOM_FILTER_ALGORITHM_KEY -> CLASSIC.toString, | ||
CLASSIC_BLOOM_FILTER_NUM_ITEMS_KEY -> DEFAULT_CLASSIC_BLOOM_FILTER_NUM_ITEMS.toString, | ||
CLASSIC_BLOOM_FILTER_FPP_KEY -> DEFAULT_CLASSIC_BLOOM_FILTER_FPP.toString) | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
.../test/scala/org/opensearch/flint/spark/skipping/bloomfilter/ClassicBloomFilterSuite.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,55 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.spark.skipping.bloomfilter | ||
|
||
import java.io.{ByteArrayInputStream, ByteArrayOutputStream} | ||
|
||
import org.opensearch.flint.spark.skipping.bloomfilter.BloomFilter.{BLOOM_FILTER_ALGORITHM_KEY, BloomFilterFactory} | ||
import org.opensearch.flint.spark.skipping.bloomfilter.BloomFilter.Algorithm.CLASSIC | ||
import org.opensearch.flint.spark.skipping.bloomfilter.ClassicBloomFilter.{CLASSIC_BLOOM_FILTER_FPP_KEY, CLASSIC_BLOOM_FILTER_NUM_ITEMS_KEY, DEFAULT_CLASSIC_BLOOM_FILTER_FPP, DEFAULT_CLASSIC_BLOOM_FILTER_NUM_ITEMS} | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
import org.apache.spark.FlintSuite | ||
|
||
class ClassicBloomFilterSuite extends FlintSuite with Matchers { | ||
|
||
test("parameters should return all parameters including defaults") { | ||
val factory = new BloomFilterFactory(Map(BLOOM_FILTER_ALGORITHM_KEY -> CLASSIC.toString)) | ||
|
||
factory.parameters should contain allOf (BLOOM_FILTER_ALGORITHM_KEY -> CLASSIC.toString, | ||
CLASSIC_BLOOM_FILTER_NUM_ITEMS_KEY -> DEFAULT_CLASSIC_BLOOM_FILTER_NUM_ITEMS.toString, | ||
CLASSIC_BLOOM_FILTER_FPP_KEY -> DEFAULT_CLASSIC_BLOOM_FILTER_FPP.toString) | ||
} | ||
|
||
test("parameters should return all specified parameters") { | ||
val expectedNumItems = 50000 | ||
val fpp = 0.001 | ||
val factory = new BloomFilterFactory( | ||
Map( | ||
BLOOM_FILTER_ALGORITHM_KEY -> CLASSIC.toString, | ||
CLASSIC_BLOOM_FILTER_NUM_ITEMS_KEY -> expectedNumItems.toString, | ||
CLASSIC_BLOOM_FILTER_FPP_KEY -> fpp.toString)) | ||
|
||
factory.parameters should contain allOf (BLOOM_FILTER_ALGORITHM_KEY -> CLASSIC.toString, | ||
CLASSIC_BLOOM_FILTER_NUM_ITEMS_KEY -> expectedNumItems.toString, | ||
CLASSIC_BLOOM_FILTER_FPP_KEY -> fpp.toString) | ||
} | ||
|
||
test("serialize and deserialize") { | ||
val factory = new BloomFilterFactory(Map(BLOOM_FILTER_ALGORITHM_KEY -> CLASSIC.toString)) | ||
val bloomFilter = factory.create() | ||
bloomFilter.put(1L) | ||
bloomFilter.put(2L) | ||
bloomFilter.put(3L) | ||
|
||
// Serialize and then deserialize should remain the same | ||
val out = new ByteArrayOutputStream() | ||
bloomFilter.writeTo(out) | ||
val in = new ByteArrayInputStream(out.toByteArray) | ||
val newBloomFilter = factory.deserialize(in) | ||
bloomFilter shouldBe newBloomFilter | ||
} | ||
} |
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