Skip to content

Commit

Permalink
[SPARK-22771][SQL] Add a missing return statement in Concat.checkInpu…
Browse files Browse the repository at this point in the history
…tDataTypes

## 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 <yamamuro@apache.org>

Closes #20149 from maropu/SPARK-22771-FOLLOWUP.
  • Loading branch information
maropu authored and gatorsmile committed Jan 4, 2018
1 parent 5aadbc9 commit 6f68316
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ case class Concat(children: Seq[Expression]) extends Expression {
} else {
val childTypes = children.map(_.dataType)
if (childTypes.exists(tpe => !Seq(StringType, BinaryType).contains(tpe))) {
TypeCheckResult.TypeCheckFailure(
return TypeCheckResult.TypeCheckFailure(
s"input to function $prettyName should have StringType or BinaryType, but it's " +
childTypes.map(_.simpleString).mkString("[", ", ", "]"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ class StringExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(Concat(strs.map(Literal.create(_, StringType))), strs.mkString, EmptyRow)
}

test("SPARK-22771 Check Concat.checkInputDataTypes results") {
assert(Concat(Seq.empty[Expression]).checkInputDataTypes().isSuccess)
assert(Concat(Literal.create("a") :: Literal.create("b") :: Nil)
.checkInputDataTypes().isSuccess)
assert(Concat(Literal.create("a".getBytes) :: Literal.create("b".getBytes) :: Nil)
.checkInputDataTypes().isSuccess)
assert(Concat(Literal.create(1) :: Literal.create(2) :: Nil)
.checkInputDataTypes().isFailure)
assert(Concat(Literal.create("a") :: Literal.create("b".getBytes) :: Nil)
.checkInputDataTypes().isFailure)
}

test("concat_ws") {
def testConcatWs(expected: String, sep: String, inputs: Any*): Unit = {
val inputExprs = inputs.map {
Expand Down

0 comments on commit 6f68316

Please sign in to comment.