-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bounded unique count aggregation
- Loading branch information
1 parent
ed7d514
commit 685e0b9
Showing
8 changed files
with
150 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
44 changes: 44 additions & 0 deletions
44
aggregator/src/test/scala/ai/chronon/aggregator/test/BoundedUniqueCountTest.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,44 @@ | ||
package ai.chronon.aggregator.test | ||
|
||
import ai.chronon.aggregator.base.BoundedUniqueCount | ||
import ai.chronon.api.StringType | ||
import junit.framework.TestCase | ||
import org.junit.Assert._ | ||
|
||
import java.util | ||
import scala.jdk.CollectionConverters._ | ||
|
||
class BoundedUniqueCountTest extends TestCase { | ||
def testHappyCase(): Unit = { | ||
val boundedDistinctCount = new BoundedUniqueCount[String](StringType, 5) | ||
var ir = boundedDistinctCount.prepare("1") | ||
ir = boundedDistinctCount.update(ir, "1") | ||
ir = boundedDistinctCount.update(ir, "2") | ||
|
||
val result = boundedDistinctCount.finalize(ir) | ||
assertEquals(2, result) | ||
} | ||
|
||
def testExceedSize(): Unit = { | ||
val boundedDistinctCount = new BoundedUniqueCount[String](StringType, 5) | ||
var ir = boundedDistinctCount.prepare("1") | ||
ir = boundedDistinctCount.update(ir, "2") | ||
ir = boundedDistinctCount.update(ir, "3") | ||
ir = boundedDistinctCount.update(ir, "4") | ||
ir = boundedDistinctCount.update(ir, "5") | ||
ir = boundedDistinctCount.update(ir, "6") | ||
ir = boundedDistinctCount.update(ir, "7") | ||
|
||
val result = boundedDistinctCount.finalize(ir) | ||
assertEquals(5, result) | ||
} | ||
|
||
def testMerge(): Unit = { | ||
val boundedDistinctCount = new BoundedUniqueCount[String](StringType, 5) | ||
val ir1 = new util.HashSet[String](Seq("1", "2", "3").asJava) | ||
val ir2 = new util.HashSet[String](Seq("4", "5", "6").asJava) | ||
|
||
val merged = boundedDistinctCount.merge(ir1, ir2) | ||
assertEquals(merged.size(), 5) | ||
} | ||
} |
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
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