Skip to content

Commit

Permalink
typelevel#803 - base good case
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-twiner committed Mar 18, 2024
1 parent b161067 commit 419fdb7
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions dataset/src/test/scala/frameless/functions/UdfTests.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package frameless
package functions

import org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute
import org.scalacheck.Prop
import org.scalacheck.Prop._

Expand Down Expand Up @@ -62,8 +63,8 @@ class UdfTests extends TypedDatasetSuite {
(dataset21 ?= d) && (dataset22 ?= d)
}

check(forAll(prop[Int, Int, Int] _))
check(forAll(prop[String, Int, Int] _))
//check(forAll(prop[Int, Int, Int] _))
//check(forAll(prop[String, Int, Int] _))
check(forAll(prop[X3[Int, String, Boolean], Int, Int] _))
check(forAll(prop[X3U[Int, String, Boolean], Int, Int] _))
}
Expand Down Expand Up @@ -182,4 +183,28 @@ class UdfTests extends TypedDatasetSuite {

check(forAll(prop[Int, Int, Int, Int, Int] _))
}

test("struct of arrays explode and star should resolve with udf") {

val dataset = TypedDataset.create(Seq(
X2(1, Seq(X2(1, "a"),X2(2, "b"),X2(5, "c"),X2(6, "d"))),
X2(2, Seq(X2(7, "a"),X2(8, "b"),X2(9, "c"),X2(10, "d"))),
X2(3, Seq(X2(11, "a"),X2(12, "b"),X2(13, "c"),X2(14, "d")))
))
import org.apache.spark.sql.functions.{expr, explode => sexplode}
import org.apache.spark.sql.Column

val starter = UnresolvedAttribute("struct")

val inc = FramelessUdf[X2[Int, String], X2[Int, String]](
(x: X2[Int, String]) => x.copy(x.a + 1),
encoders = List(TypedEncoder[X2[Int, String]]),
Seq(TypedEncoder[X2[Int, String]].fromCatalyst(starter)), // b doesn't resolve
TypedEncoder[X2[Int, String]])

// dataset.dataset.select(expr("*"), sexplode(new Column(inc)).as("struct")).select(expr("struct.*")).show
dataset.dataset.select(expr("*"), sexplode(new Column("b")).as("struct")).
select(new Column(inc).as("struct")).
select(expr("struct.*")).show
}
}

0 comments on commit 419fdb7

Please sign in to comment.