Skip to content

Commit

Permalink
session table function
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bli committed Nov 13, 2023
1 parent dee1584 commit 11f0266
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.snowflake.snowpark.functions._
import com.snowflake.snowpark.{Row, _}

import scala.collection.Seq
import scala.collection.immutable.Map

class TableFunctionSuite extends TestData {
import session.implicits._
Expand Down Expand Up @@ -221,4 +222,19 @@ class TableFunctionSuite extends TestData {
assert(df1.join(tableFunctions.flatten(input = parse_json(df1("col")),
path = "", outer = true, recursive = true, mode = "object")).count() == 2)
}

test("Argument in table function: flatten - session") {
val df = Seq(
(1, Array(1, 2, 3), Map("a" -> "b", "c" -> "d")),
(2, Array(11, 22, 33), Map("a1" -> "b1", "c1" -> "d1"))).toDF("idx", "arr", "map")
checkAnswer(session.tableFunction(tableFunctions.flatten(df("arr"))).select("value"),
Seq(Row("1"), Row("2"), Row("3"), Row("11"), Row("22"), Row("33")))
// error if it is not a table function
val error1 = intercept[SnowparkClientException] {
session.tableFunction(lit("dummy"))
}
assert(
error1.message.contains("Invalid input argument, " +
"Session.tableFunction only supports table function arguments"))
}
}

0 comments on commit 11f0266

Please sign in to comment.