Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Seq of functions #172

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.jetbrains.kotlinx.spark.api

import scala.collection.immutable.`Seq$`.`MODULE$` as Seq
import scala.collection.immutable.Seq as Seq
import scala.collection.mutable.`Seq$`.`MODULE$` as MutableSeq
import scala.collection.mutable.Seq as MutableSeq

/**
* Returns a new empty immutable Seq.
*/
fun <T> emptySeq(): Seq<T> = Seq.empty<T>() as Seq<T>

/**
* Returns a new immutable Seq with the given elements.
*/
fun <T> seqOf(vararg elements: T): Seq<T> =
if (elements.isEmpty())
emptySeq()
else
Seq.newBuilder<T>().apply {
for (it in elements)
`$plus$eq`(it)
}.result() as Seq<T>

/**
* Returns a new mutable Seq with the given elements.
*/
fun <T> emptyMutableSeq(): MutableSeq<T> = MutableSeq.empty<T>() as MutableSeq<T>

/**
* Returns a new mutable Seq with the given elements.
*/
fun <T> mutableSeqOf(vararg elements: T): MutableSeq<T> =
if (elements.isEmpty())
emptyMutableSeq()
else
MutableSeq.newBuilder<T>().apply {
for (it in elements)
`$plus$eq`(it)
}.result() as MutableSeq<T>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ class ApiTest : ShouldSpec({
context("miscellaneous integration tests") {
withSpark(props = mapOf("spark.sql.codegen.comments" to true)) {

should("Create Seqs") {
spark.createDataset(seqOf(1, 2, 3), encoder())
.collectAsList() shouldBe listOf(1, 2, 3)


seqOf(1, 2, 3) shouldBe seqOf(1, 2, 3)
mutableSeqOf(1, 2, 3) shouldBe mutableSeqOf(1, 2, 3)

seqOf<Int>() shouldBe emptySeq<Int>()
mutableSeqOf<Int>() shouldBe emptyMutableSeq<Int>()
}

@OptIn(ExperimentalStdlibApi::class)
should("broadcast variables") {
val largeList = (1..15).map { SomeClass(a = (it..15).toList().toIntArray(), b = it) }
Expand Down