@@ -22,9 +22,9 @@ package org.jetbrains.kotlinx.spark.api
22
22
import ch.tutteli.atrium.api.fluent.en_GB.*
23
23
import ch.tutteli.atrium.api.verbs.expect
24
24
import io.kotest.core.spec.style.ShouldSpec
25
- import io.kotest.matchers.collections.shouldContain
26
25
import io.kotest.matchers.collections.shouldContainExactly
27
26
import io.kotest.matchers.shouldBe
27
+ import io.kotest.matchers.string.shouldContain
28
28
import org.apache.spark.sql.Dataset
29
29
import org.apache.spark.sql.types.Decimal
30
30
import org.apache.spark.unsafe.types.CalendarInterval
@@ -210,7 +210,7 @@ class EncodingTest : ShouldSpec({
210
210
context("schema") {
211
211
withSpark(props = mapOf("spark.sql.codegen.comments" to true)) {
212
212
213
- context("Give proper names to columns of data classe ") {
213
+ context("Give proper names to columns of data classes ") {
214
214
val old = KotlinTypeInference .DO_NAME_HACK
215
215
KotlinTypeInference .DO_NAME_HACK = true
216
216
@@ -240,6 +240,142 @@ class EncodingTest : ShouldSpec({
240
240
dataset.collectAsList() shouldBe pairs
241
241
}
242
242
243
+ should("Be able to serialize pairs of pairs of pairs") {
244
+ val pairs = listOf(
245
+ 1 to (1 to (1 to "1")),
246
+ 2 to (2 to (2 to "2")),
247
+ 3 to (3 to (3 to "3")),
248
+ )
249
+ val dataset = pairs.toDS()
250
+ dataset.show()
251
+ dataset.printSchema()
252
+ dataset.columns().shouldContainExactly("first", "second")
253
+ dataset.select("second.*").columns().shouldContainExactly("first", "second")
254
+ dataset.select("second.second.*").columns().shouldContainExactly("first", "second")
255
+ dataset.collectAsList() shouldBe pairs
256
+ }
257
+
258
+ should("Be able to serialize lists of pairs") {
259
+ val pairs = listOf(
260
+ listOf(1 to "1", 2 to "2"),
261
+ listOf(3 to "3", 4 to "4"),
262
+ )
263
+ val dataset = pairs.toDS()
264
+ dataset.show()
265
+ dataset.printSchema()
266
+ dataset.schema().toString().let {
267
+ it shouldContain " first"
268
+ it shouldContain " second"
269
+ }
270
+ dataset.collectAsList() shouldBe pairs
271
+ }
272
+
273
+ should("Be able to serialize lists of lists of pairs") {
274
+ val pairs = listOf(
275
+ listOf(
276
+ listOf(1 to "1", 2 to "2"),
277
+ listOf(3 to "3", 4 to "4")
278
+ )
279
+ )
280
+ val dataset = pairs.toDS()
281
+ dataset.show()
282
+ dataset.printSchema()
283
+ dataset.schema().toString().let {
284
+ it shouldContain " first"
285
+ it shouldContain " second"
286
+ }
287
+ dataset.collectAsList() shouldBe pairs
288
+ }
289
+
290
+ should("Be able to serialize lists of lists of lists of pairs") {
291
+ val pairs = listOf(
292
+ listOf(
293
+ listOf(
294
+ listOf(1 to "1", 2 to "2"),
295
+ listOf(3 to "3", 4 to "4"),
296
+ )
297
+ )
298
+ )
299
+ val dataset = pairs.toDS()
300
+ dataset.show()
301
+ dataset.printSchema()
302
+ dataset.schema().toString().let {
303
+ it shouldContain " first"
304
+ it shouldContain " second"
305
+ }
306
+ dataset.collectAsList() shouldBe pairs
307
+ }
308
+
309
+ should("Be able to serialize lists of lists of lists of pairs of pairs") {
310
+ val pairs = listOf(
311
+ listOf(
312
+ listOf(
313
+ listOf(1 to ("1" to 3.0), 2 to ("2" to 3.0)),
314
+ listOf(3 to ("3" to 3.0), 4 to ("4" to 3.0)),
315
+ )
316
+ )
317
+ )
318
+ val dataset = pairs.toDS()
319
+ dataset.show()
320
+ dataset.printSchema()
321
+ dataset.schema().toString().let {
322
+ it shouldContain " first"
323
+ it shouldContain " second"
324
+ }
325
+ dataset.collectAsList() shouldBe pairs
326
+ }
327
+
328
+ should("Be able to serialize arrays of pairs") {
329
+ val pairs = arrayOf(
330
+ arrayOf(1 to "1", 2 to "2"),
331
+ arrayOf(3 to "3", 4 to "4"),
332
+ )
333
+ val dataset = pairs.toDS()
334
+ dataset.show()
335
+ dataset.printSchema()
336
+ dataset.schema().toString().let {
337
+ it shouldContain " first"
338
+ it shouldContain " second"
339
+ }
340
+ dataset.collectAsList() shouldBe pairs
341
+ }
342
+
343
+ should("Be able to serialize arrays of arrays of pairs") {
344
+ val pairs = arrayOf(
345
+ arrayOf(
346
+ arrayOf(1 to "1", 2 to "2"),
347
+ arrayOf(3 to "3", 4 to "4")
348
+ )
349
+ )
350
+ val dataset = pairs.toDS()
351
+ dataset.show()
352
+ dataset.printSchema()
353
+ dataset.schema().toString().let {
354
+ it shouldContain " first"
355
+ it shouldContain " second"
356
+ }
357
+ dataset.collectAsList() shouldBe pairs
358
+ }
359
+
360
+ should("Be able to serialize arrays of arrays of arrays of pairs") {
361
+ val pairs = arrayOf(
362
+ arrayOf(
363
+ arrayOf(
364
+ arrayOf(1 to "1", 2 to "2"),
365
+ arrayOf(3 to "3", 4 to "4"),
366
+ )
367
+ )
368
+ )
369
+ val dataset = pairs.toDS()
370
+ dataset.show()
371
+ dataset.printSchema()
372
+ dataset.schema().toString().let {
373
+ it shouldContain " first"
374
+ it shouldContain " second"
375
+ }
376
+ dataset.collectAsList() shouldBe pairs
377
+ }
378
+
243
379
KotlinTypeInference .DO_NAME_HACK = old
244
380
}
245
381
@@ -351,6 +487,7 @@ class EncodingTest : ShouldSpec({
351
487
listOf(SomeClass (intArrayOf(1, 2, 3), 4)),
352
488
listOf(SomeClass (intArrayOf(3, 2, 1), 0)),
353
489
)
490
+ dataset.printSchema()
354
491
355
492
val (first, second) = dataset.collectAsList()
356
493
0 commit comments