Skip to content

Commit 6f68316

Browse files
maropugatorsmile
authored andcommitted
[SPARK-22771][SQL] Add a missing return statement in Concat.checkInputDataTypes
## What changes were proposed in this pull request? This pr is a follow-up to fix a bug left in #19977. ## How was this patch tested? Added tests in `StringExpressionsSuite`. Author: Takeshi Yamamuro <[email protected]> Closes #20149 from maropu/SPARK-22771-FOLLOWUP.
1 parent 5aadbc9 commit 6f68316

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ case class Concat(children: Seq[Expression]) extends Expression {
5858
} else {
5959
val childTypes = children.map(_.dataType)
6060
if (childTypes.exists(tpe => !Seq(StringType, BinaryType).contains(tpe))) {
61-
TypeCheckResult.TypeCheckFailure(
61+
return TypeCheckResult.TypeCheckFailure(
6262
s"input to function $prettyName should have StringType or BinaryType, but it's " +
6363
childTypes.map(_.simpleString).mkString("[", ", ", "]"))
6464
}

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/StringExpressionsSuite.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ class StringExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
5151
checkEvaluation(Concat(strs.map(Literal.create(_, StringType))), strs.mkString, EmptyRow)
5252
}
5353

54+
test("SPARK-22771 Check Concat.checkInputDataTypes results") {
55+
assert(Concat(Seq.empty[Expression]).checkInputDataTypes().isSuccess)
56+
assert(Concat(Literal.create("a") :: Literal.create("b") :: Nil)
57+
.checkInputDataTypes().isSuccess)
58+
assert(Concat(Literal.create("a".getBytes) :: Literal.create("b".getBytes) :: Nil)
59+
.checkInputDataTypes().isSuccess)
60+
assert(Concat(Literal.create(1) :: Literal.create(2) :: Nil)
61+
.checkInputDataTypes().isFailure)
62+
assert(Concat(Literal.create("a") :: Literal.create("b".getBytes) :: Nil)
63+
.checkInputDataTypes().isFailure)
64+
}
65+
5466
test("concat_ws") {
5567
def testConcatWs(expected: String, sep: String, inputs: Any*): Unit = {
5668
val inputExprs = inputs.map {

0 commit comments

Comments
 (0)