Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mihailoale-db committed Oct 15, 2024
1 parent 14c01eb commit 3827a21
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,12 @@
"cannot find a static method <methodName> that matches the argument types in <className>."
]
},
"UNSUPPORTED_CASE_WHEN_CLAUSE" : {
"message" : [
"The CASE WHEN clause of type <clause> is not supported."
],
"sqlState" : "42601"
},
"UNSUPPORTED_INPUT_TYPE" : {
"message" : [
"The input of <functionName> can't be <dataType> type data."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2932,6 +2932,10 @@ class AstBuilder extends DataTypeAstBuilder
val branches = ctx.whenClause.asScala.map { wCtx =>
(expression(wCtx.condition), expression(wCtx.result))
}
branches.foreach(
branch => if (branch._1.isInstanceOf[LambdaFunction]) throw new ParseException(
"UNSUPPORTED_CASE_WHEN_CLAUSE", Map("clause" -> "LambdaFunction"), ctx)
)
CaseWhen(branches.toSeq, Option(ctx.elseExpression).map(expression))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1973,4 +1973,18 @@ class PlanParserSuite extends AnalysisTest {
assert(unresolvedRelation2.options == CaseInsensitiveStringMap.empty)
assert(unresolvedRelation2.isStreaming)
}

test("SPARK-49976: Disable lambda functions as case when clauses") {
val query = "select (case when a->b = true then 1 else 0 end)"
checkError(
exception = parseException(query),
condition = "UNSUPPORTED_CASE_WHEN_CLAUSE",
sqlState = Some("42601"),
parameters = Map("clause" -> "LambdaFunction"),
context = ExpectedContext(
fragment = "case when a->b = true then 1 else 0 end",
start = 8,
stop = 46)
)
}
}

0 comments on commit 3827a21

Please sign in to comment.