Skip to content

Commit f4fee40

Browse files
committed
splitting and ordering api tests into multiple files
1 parent 41c58fa commit f4fee40

File tree

4 files changed

+40
-37
lines changed

4 files changed

+40
-37
lines changed

examples/src/main/kotlin/org/jetbrains/kotlinx/spark/examples/Broadcasting.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ data class SomeClass(val a: IntArray, val b: Int) : Serializable
3131
fun main() = withSpark {
3232
val broadcastVariable = spark.broadcast(SomeClass(a = intArrayOf(5, 6), b = 3))
3333
val result = listOf(1, 2, 3, 4, 5)
34-
.toDS()
35-
.map {
36-
val receivedBroadcast = broadcastVariable.value
37-
it + receivedBroadcast.a.first()
38-
}
39-
.collectAsList()
34+
.toDS()
35+
.map {
36+
val receivedBroadcast = broadcastVariable.value
37+
it + receivedBroadcast.a.first()
38+
}
39+
.collectAsList()
4040

4141
println(result)
4242
}

examples/src/main/kotlin/org/jetbrains/kotlinx/spark/examples/CachedOperations.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import org.jetbrains.kotlinx.spark.api.*
2424
fun main() {
2525
withSpark {
2626
dsOf(1, 2, 3, 4, 5)
27-
.map { it to (it + 2) }
28-
.withCached {
29-
showDS()
27+
.map { it to (it + 2) }
28+
.withCached {
29+
showDS()
3030

31-
filter { it.first % 2 == 0 }.showDS()
32-
}
33-
.map { c(it.first, it.second, (it.first + it.second) * 2) }
34-
.show()
31+
filter { it.first % 2 == 0 }.showDS()
32+
}
33+
.map { c(it.first, it.second, (it.first + it.second) * 2) }
34+
.show()
3535
}
3636
}

examples/src/main/kotlin/org/jetbrains/kotlinx/spark/examples/MapAndListOperations.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ import org.jetbrains.kotlinx.spark.api.*
2323

2424
fun main() {
2525
withSpark(props = mapOf("spark.sql.codegen.wholeStage" to true)) {
26-
dsOf(mapOf(1 to c(1, 2, 3), 2 to c(1, 2, 3)), mapOf(3 to c(1, 2, 3), 4 to c(1, 2, 3)))
27-
.flatMap { it.toList().map { p -> listOf(p.first, p.second._1, p.second._2, p.second._3) }.iterator() }
28-
.flatten()
29-
.map { c(it) }
30-
.also { it.printSchema() }
31-
.distinct()
32-
.sort("_1")
33-
.debugCodegen()
34-
.show()
26+
dsOf(
27+
mapOf(1 to c(1, 2, 3), 2 to c(1, 2, 3)),
28+
mapOf(3 to c(1, 2, 3), 4 to c(1, 2, 3)),
29+
)
30+
.flatMap { it.toList().map { p -> listOf(p.first, p.second._1, p.second._2, p.second._3) }.iterator() }
31+
.flatten()
32+
.map { c(it) }
33+
.also { it.printSchema() }
34+
.distinct()
35+
.sort("_1")
36+
.debugCodegen()
37+
.show()
3538
}
3639
}
3740

examples/src/main/kotlin/org/jetbrains/kotlinx/spark/examples/WordCount.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ const val MEANINGFUL_WORD_LENGTH = 4
2727
fun main() {
2828
withSpark {
2929
spark
30-
.read()
31-
.textFile(this::class.java.classLoader.getResource("the-catcher-in-the-rye.txt")?.path)
32-
.map { it.split(Regex("\\s")) }
33-
.flatten()
34-
.cleanup()
35-
.groupByKey { it }
36-
.mapGroups { k, iter -> k to iter.asSequence().count() }
37-
.sort { arrayOf(it.col("second").desc()) }
38-
.limit(20)
39-
.map { it.second to it.first }
40-
.show(false)
30+
.read()
31+
.textFile(this::class.java.classLoader.getResource("the-catcher-in-the-rye.txt")?.path)
32+
.map { it.split(Regex("\\s")) }
33+
.flatten()
34+
.cleanup()
35+
.groupByKey { it }
36+
.mapGroups { k, iter -> k to iter.asSequence().count() }
37+
.sort { arrayOf(it.col("second").desc()) }
38+
.limit(20)
39+
.map { it.second to it.first }
40+
.show(false)
4141
}
4242
}
4343

4444
fun Dataset<String>.cleanup() =
45-
filter { it.isNotBlank() }
46-
.map { it.trim(',', ' ', '\n', ':', '.', ';', '?', '!', '"', '\'', '\t', ' ') }
47-
.filter { !it.endsWith("n’t") }
48-
.filter { it.length >= MEANINGFUL_WORD_LENGTH }
45+
filter { it.isNotBlank() }
46+
.map { it.trim(',', ' ', '\n', ':', '.', ';', '?', '!', '"', '\'', '\t', ' ') }
47+
.filter { !it.endsWith("n’t") }
48+
.filter { it.length >= MEANINGFUL_WORD_LENGTH }

0 commit comments

Comments
 (0)