Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented explode() operation. Optimized single column typed access…
…. Permitted unspecialized columns in schema.
- Loading branch information
Jacob Fischer
committed
Oct 1, 2020
1 parent
27bf941
commit 57f037c
Showing
8 changed files
with
109 additions
and
12 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
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
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
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
31 changes: 31 additions & 0 deletions
31
src/test/scala/com/audienceproject/crossbow/core/ExplodeTest.scala
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,31 @@ | ||
package com.audienceproject.crossbow.core | ||
|
||
import com.audienceproject.crossbow.DataFrame | ||
import com.audienceproject.crossbow.Implicits._ | ||
import org.scalatest.funsuite.AnyFunSuite | ||
|
||
class ExplodeTest extends AnyFunSuite { | ||
|
||
test("Explode int seq column") { | ||
val df = DataFrame.fromSeq(Seq(("a", Seq(1, 2)), ("b", Seq(1, 2, 3)), ("c", Seq(5, 10)))) | ||
val result = df.explode($"_1") | ||
val expected = Seq(("a", 1), ("a", 2), ("b", 1), ("b", 2), ("b", 3), ("c", 5), ("c", 10)) | ||
assert(result("_0", "_2").as[(String, Int)].toSeq == expected) | ||
} | ||
|
||
test("Explode on evaluated expression") { | ||
val df = DataFrame.fromSeq(Seq(("a", 2), ("b", 3), ("c", 4))) | ||
val range = lambda[(Int, Int), Seq[Int]] { case (from, to) => from until to } | ||
val result = df.explode(range((index(), $"_1"))) | ||
val expected = Seq(("a", 0), ("a", 1), ("b", 1), ("b", 2), ("c", 2), ("c", 3)) | ||
assert(result("_0", "_2").as[(String, Int)].toSeq == expected) | ||
} | ||
|
||
test("Explode on object column") { | ||
val df = DataFrame.fromSeq(Seq(("a", Seq(Left(1), Right(2))), ("b", Seq(Left(2), Right(3))))) | ||
val result = df.explode($"_1" as "either") | ||
val expected = Seq(("a", Left(1)), ("a", Right(2)), ("b", Left(2)), ("b", Right(3))) | ||
assert(result("_0", "either").as[(String, Any)].toSeq == expected) | ||
} | ||
|
||
} |