@@ -18,8 +18,7 @@ package org.jetbrains.kotlinx.spark.api/*-
1818 * = LICENSEEND =
1919 */
2020import ch.tutteli.atrium.api.fluent.en_GB.*
21- import ch.tutteli.atrium.domain.builders.migration.asExpect
22- import ch.tutteli.atrium.verbs.expect
21+ import ch.tutteli.atrium.api.verbs.expect
2322import io.kotest.core.spec.style.ShouldSpec
2423import io.kotest.matchers.shouldBe
2524import org.apache.spark.sql.streaming.GroupState
@@ -36,7 +35,6 @@ import java.io.Serializable
3635import java.sql.Date
3736import java.sql.Timestamp
3837import java.time.LocalDate
39- import kotlin.reflect.KProperty1
4038import scala.collection.Iterator as ScalaIterator
4139import scala.collection.Map as ScalaMap
4240import scala.collection.mutable.Map as ScalaMutableMap
@@ -48,33 +46,37 @@ class ApiTest : ShouldSpec({
4846 val ll1 = LonLat (1.0, 2.0)
4947 val ll2 = LonLat (3.0, 4.0)
5048 val lonlats = dsOf(ll1, ll2).collectAsList()
51- expect(lonlats).asExpect(). contains.inAnyOrder.only.values(ll1.copy(), ll2.copy())
49+ expect(lonlats).contains.inAnyOrder.only.values(ll1.copy(), ll2.copy())
5250 }
5351 should("contain all generic primitives with complex schema") {
5452 val primitives = c(1, 1.0, 1.toFloat(), 1.toByte(), LocalDate .now(), true)
5553 val primitives2 = c(2, 2.0, 2.toFloat(), 2.toByte(), LocalDate .now().plusDays(1), false)
5654 val tuples = dsOf(primitives, primitives2).collectAsList()
57- expect(tuples).asExpect(). contains.inAnyOrder.only.values(primitives, primitives2)
55+ expect(tuples).contains.inAnyOrder.only.values(primitives, primitives2)
5856 }
5957 should("contain all generic primitives with complex nullable schema") {
6058 val primitives = c(1, 1.0, 1.toFloat(), 1.toByte(), LocalDate .now(), true)
6159 val nulls = c(null, null, null, null, null, null)
6260 val tuples = dsOf(primitives, nulls).collectAsList()
63- expect(tuples).asExpect(). contains.inAnyOrder.only.values(primitives, nulls)
61+ expect(tuples).contains.inAnyOrder.only.values(primitives, nulls)
6462 }
6563 should("handle cached operations") {
6664 val result = dsOf(1, 2, 3, 4, 5)
67- .map { it to (it + 2) }
68- .withCached {
69- expect(collectAsList()).asExpect().contains.inAnyOrder.only.values(1 to 3, 2 to 4, 3 to 5, 4 to 6, 5 to 7)
70-
71- val next = filter { it.first % 2 == 0 }
72- expect(next.collectAsList()).asExpect().contains.inAnyOrder.only.values(2 to 4, 4 to 6)
73- next
74- }
75- .map { c(it.first, it.second, (it.first + it.second) * 2) }
76- .collectAsList()
77- expect(result).asExpect().contains.inOrder.only.values(c(2, 4, 12), c(4, 6, 20))
65+ .map { it to (it + 2) }
66+ .withCached {
67+ expect(collectAsList()).contains.inAnyOrder.only.values(1 to 3,
68+ 2 to 4,
69+ 3 to 5,
70+ 4 to 6,
71+ 5 to 7)
72+
73+ val next = filter { it.first % 2 == 0 }
74+ expect(next.collectAsList()).contains.inAnyOrder.only.values(2 to 4, 4 to 6)
75+ next
76+ }
77+ .map { c(it.first, it.second, (it.first + it.second) * 2) }
78+ .collectAsList()
79+ expect(result).contains.inOrder.only.values(c(2, 4, 12), c(4, 6, 20))
7880 }
7981 should("handle join operations") {
8082 data class Left (val id: Int , val name: String )
@@ -84,34 +86,34 @@ class ApiTest : ShouldSpec({
8486 val first = dsOf(Left (1, "a"), Left (2, "b"))
8587 val second = dsOf(Right (1, 100), Right (3, 300))
8688 val result = first
87- .leftJoin(second, first.col("id").eq(second.col("id")))
88- .map { c(it.first.id, it.first.name, it.second?.value) }
89- .collectAsList()
90- expect(result).asExpect(). contains.inOrder.only.values(c(1, "a", 100), c(2, "b", null))
89+ .leftJoin(second, first.col("id").eq(second.col("id")))
90+ .map { c(it.first.id, it.first.name, it.second?.value) }
91+ .collectAsList()
92+ expect(result).contains.inOrder.only.values(c(1, "a", 100), c(2, "b", null))
9193 }
9294 should("handle map operations") {
9395 expect(
94- dsOf(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6))
95- .flatMap { it.iterator() }
96- .map { it + 4 }
97- .filter { it < 10 }
98- .collectAsList()
96+ dsOf(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6))
97+ .flatMap { it.iterator() }
98+ .map { it + 4 }
99+ .filter { it < 10 }
100+ .collectAsList()
99101 )
100- .asExpect()
101- .contains
102- .inAnyOrder
103- .only
104- .values(5, 6, 7, 8, 7, 8, 9)
102+ .contains
103+ .inAnyOrder
104+ .only
105+ .values(5, 6, 7, 8, 7, 8, 9)
105106 }
106107 should("hadle strings converted to lists") {
107108 data class Movie (val id: Long , val genres: String )
108109 data class MovieExpanded (val id: Long , val genres: List <String >)
109110
110111 val comedies = listOf(Movie (1, "Comedy |Romance "), Movie (2, "Horror |Action ")).toDS()
111- .map { MovieExpanded (it.id, it.genres.split("|").toList()) }
112- .filter { it.genres.contains("Comedy ") }
113- .collectAsList()
114- expect(comedies).asExpect().contains.inAnyOrder.only.values(MovieExpanded (1, listOf("Comedy ", "Romance ")))
112+ .map { MovieExpanded (it.id, it.genres.split("|").toList()) }
113+ .filter { it.genres.contains("Comedy ") }
114+ .collectAsList()
115+ expect(comedies).contains.inAnyOrder.only.values(MovieExpanded (1,
116+ listOf("Comedy ", "Romance ")))
115117 }
116118 should("handle strings converted to arrays") {
117119 data class Movie (val id: Long , val genres: String )
@@ -131,27 +133,28 @@ class ApiTest : ShouldSpec({
131133 }
132134
133135 val comedies = listOf(Movie (1, "Comedy |Romance "), Movie (2, "Horror |Action ")).toDS()
134- .map { MovieExpanded (it.id, it.genres.split("|").toTypedArray()) }
135- .filter { it.genres.contains("Comedy ") }
136- .collectAsList()
137- expect(comedies).asExpect().contains.inAnyOrder.only.values(MovieExpanded (1, arrayOf("Comedy ", "Romance ")))
136+ .map { MovieExpanded (it.id, it.genres.split("|").toTypedArray()) }
137+ .filter { it.genres.contains("Comedy ") }
138+ .collectAsList()
139+ expect(comedies).contains.inAnyOrder.only.values(MovieExpanded (1,
140+ arrayOf("Comedy ", "Romance ")))
138141 }
139142 should("!handle arrays of generics") {
140143
141144 val result = listOf(Test (1, arrayOf(5.1 to 6, 6.1 to 7)))
142- .toDS()
143- .map { it.id to it.data.first { liEl -> liEl.first < 6 } }
144- .map { it.second }
145- .collectAsList()
146- expect(result).asExpect(). contains.inOrder.only.values(5.1 to 6)
145+ .toDS()
146+ .map { it.id to it.data.first { liEl -> liEl.first < 6 } }
147+ .map { it.second }
148+ .collectAsList()
149+ expect(result).contains.inOrder.only.values(5.1 to 6)
147150 }
148151 should("handle primitive arrays") {
149152 val result = listOf(arrayOf(1, 2, 3, 4))
150- .toDS()
151- .map { it.map { ai -> ai + 1 } }
152- .collectAsList()
153- .flatten()
154- expect(result).asExpect(). contains.inOrder.only.values(2, 3, 4, 5)
153+ .toDS()
154+ .map { it.map { ai -> ai + 1 } }
155+ .collectAsList()
156+ .flatten()
157+ expect(result).contains.inOrder.only.values(2, 3, 4, 5)
155158
156159 }
157160 @OptIn(ExperimentalStdlibApi ::class )
@@ -174,7 +177,7 @@ class ApiTest : ShouldSpec({
174177 }
175178 .collectAsList()
176179
177- expect(result).asExpect(). contains.inOrder.only.values(3.0, 5.0, 7.0, 9.0, 11.0)
180+ expect(result).contains.inOrder.only.values(3.0, 5.0, 7.0, 9.0, 11.0)
178181 }
179182 should("Handle JavaConversions in Kotlin ") {
180183 // Test the iterator conversion
@@ -444,7 +447,7 @@ class ApiTest : ShouldSpec({
444447 )
445448 dataset.forEachPartition {
446449 it.forEach {
447- it.b shouldBe 1
450+ it.b shouldBe 1
448451 }
449452 }
450453 }
@@ -454,7 +457,7 @@ class ApiTest : ShouldSpec({
454457 SomeClass (intArrayOf(4, 3, 2), 1),
455458 )
456459 .groupByKey { it.b }
457- .reduceGroups (func = { a, b -> SomeClass (a.a + b.a, a.b) })
460+ .reduceGroupsK (func = { a, b -> SomeClass (a.a + b.a, a.b) })
458461 .takeValues()
459462
460463 dataset.count() shouldBe 1
0 commit comments