forked from typelevel/frameless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flatten operator for Optional columns. (typelevel#307)
- Loading branch information
Showing
3 changed files
with
92 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package frameless | ||
|
||
import org.scalacheck.Prop | ||
import org.scalacheck.Prop.forAll | ||
import org.scalacheck.Prop._ | ||
|
||
|
||
class FlattenTests extends TypedDatasetSuite { | ||
test("simple flatten test") { | ||
val ds: TypedDataset[(Int,Option[Int])] = TypedDataset.create(Seq((1,Option(1)))) | ||
ds.flattenOption('_2): TypedDataset[(Int,Int)] | ||
} | ||
|
||
test("different Optional types") { | ||
def prop[A: TypedEncoder](xs: List[X1[Option[A]]]): Prop = { | ||
val tds: TypedDataset[X1[Option[A]]] = TypedDataset.create(xs) | ||
|
||
val framelessResults: Seq[Tuple1[A]] = tds.flattenOption('a).collect().run().toVector | ||
val scalaResults = xs.flatMap(_.a).map(Tuple1(_)).toVector | ||
|
||
framelessResults ?= scalaResults | ||
} | ||
|
||
check(forAll(prop[Long] _)) | ||
check(forAll(prop[Int] _)) | ||
check(forAll(prop[Char] _)) | ||
check(forAll(prop[String] _)) | ||
} | ||
} |
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