Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
codeatri committed Aug 15, 2018
1 parent fb885f4 commit 58b60b2
Showing 1 changed file with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2366,34 +2366,27 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
Seq(1, 2, 3, 4)
).toDF("j")

def testInvalidLambdaFunctions(): Unit = {
val ex1 = intercept[AnalysisException] {
dfExample1.selectExpr("transform_keys(i, k -> k)")
}
assert(ex1.getMessage.contains("The number of lambda function arguments '1' does not match"))

val ex2 = intercept[AnalysisException] {
dfExample1.selectExpr("transform_keys(i, (k, v, x) -> k + 1)")
}
assert(ex2.getMessage.contains(
"The number of lambda function arguments '3' does not match"))
val ex1 = intercept[AnalysisException] {
dfExample1.selectExpr("transform_keys(i, k -> k)")
}
assert(ex1.getMessage.contains("The number of lambda function arguments '1' does not match"))

val ex3 = intercept[RuntimeException] {
dfExample1.selectExpr("transform_keys(i, (k, v) -> v)").show()
}
assert(ex3.getMessage.contains("Cannot use null as map key!"))
val ex2 = intercept[AnalysisException] {
dfExample1.selectExpr("transform_keys(i, (k, v, x) -> k + 1)")
}
assert(ex2.getMessage.contains(
"The number of lambda function arguments '3' does not match"))

val ex4 = intercept[AnalysisException] {
dfExample2.selectExpr("transform_keys(j, (k, v) -> k + 1)")
}
assert(ex4.getMessage.contains(
"data type mismatch: argument 1 requires map type"))
val ex3 = intercept[RuntimeException] {
dfExample1.selectExpr("transform_keys(i, (k, v) -> v)").show()
}
assert(ex3.getMessage.contains("Cannot use null as map key!"))

testInvalidLambdaFunctions()
dfExample1.cache()
dfExample2.cache()
testInvalidLambdaFunctions()
val ex4 = intercept[AnalysisException] {
dfExample2.selectExpr("transform_keys(j, (k, v) -> k + 1)")
}
assert(ex4.getMessage.contains(
"data type mismatch: argument 1 requires map type"))
}

private def assertValuesDoNotChangeAfterCoalesceOrUnion(v: Column): Unit = {
Expand Down

0 comments on commit 58b60b2

Please sign in to comment.