Skip to content

Commit

Permalink
add error
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bli committed Nov 28, 2023
1 parent 370475e commit 6e693fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/scala/com/snowflake/snowpark/DataFrame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,8 @@ class DataFrame private[snowpark] (
joinTableFunction(
tableFunctions.flatten.call(Map("input" -> Column(expr), "mode" -> lit("object"))),
partitionByOrderBy).select(columns ++ Seq(Column("KEY"), Column("VALUE")))
case _ => null
case otherType =>
throw ErrorMessage.MISC_INVALID_EXPLODE_ARGUMENT_TYPE(otherType.typeName)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,26 @@ class TableFunctionSuite extends TestData {
parse_json(df("a"))
.cast(types.MapType(types.StringType, types.IntegerType))
.as("a"))
df1.select(tableFunctions.explode(df1("a"))).show()
checkAnswer(
df1.select(lit(1), tableFunctions.explode(df1("a")), df1("a")("a")),
Seq(Row(1, "a", "1", "1"), Row(1, "b", "2", "1")))
}

test("explode with other column") {
val df = Seq("""{"a":1, "b": 2}""").toDF("a")
val df1 = df.select(
parse_json(df("a"))
.as("a"))
val error = intercept[SnowparkClientException] {
df1.select(tableFunctions.explode(df1("a"))).show()
}
assert(
error.message.contains(
"the input argument type of Explode function should be either Map or Array types"))
assert(
error.message.contains(
"The input argument type: Variant"))
}


}

0 comments on commit 6e693fe

Please sign in to comment.