Skip to content

Commit

Permalink
remove type check from eval
Browse files Browse the repository at this point in the history
  • Loading branch information
yjshen committed Jul 2, 2015
1 parent 7a71255 commit fd3cd8e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ case class CreateNamedStruct(children: Seq[Expression]) extends Expression {
private lazy val names = nameExprs.map(_.asInstanceOf[Literal].value.toString)

override lazy val dataType: StructType = {
require(resolved, resolveFailureMessage)
assert(resolved, resolveFailureMessage)
val fields = names.zip(valExprs).map { case (name, valExpr) =>
StructField(name, valExpr.dataType, valExpr.nullable, Metadata.empty)
}
Expand Down Expand Up @@ -123,7 +123,6 @@ case class CreateNamedStruct(children: Seq[Expression]) extends Expression {
}

override def eval(input: InternalRow): Any = {
require(resolved, resolveFailureMessage)
InternalRow(valExprs.map(_.eval(input)): _*)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,11 @@ class ExpressionTypeCheckingSuite extends SparkFunSuite {
assertError(Explode('intField),
"input to function explode should be array or map type")
}

test("check types for CreateNamedStruct") {
assertError(
CreateNamedStruct(Seq("a", "b", 2.0)), "even number of arguments")
assertError(
CreateNamedStruct(Seq(1, "a", "b", 2.0)), "Non String Literal fields")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,6 @@ class ComplexTypeSuite extends SparkFunSuite with ExpressionEvalHelper {
assert(getStructField(nullStruct, "a").nullable === true)
}

test("CreateNamedStruct with odd number of parameters") {
val thrown = intercept[TestFailedException] {
checkEvaluation(
CreateNamedStruct(Seq("a", "b", 2.0)), InternalRow("x", 2.0), InternalRow.empty)
}
assert(thrown.getCause.getMessage.contains("even number of arguments"))
}

test("CreateNamedStruct with non String Literal name") {
val thrown = intercept[TestFailedException] {
checkEvaluation(
CreateNamedStruct(Seq(1, "a", "b", 2.0)), InternalRow("x", 2.0), InternalRow.empty)
}
assert(thrown.getCause.getMessage.contains("Non String Literal fields"))
}

test("complex type") {
val row = create_row(
"^Ba*n", // 0
Expand Down

0 comments on commit fd3cd8e

Please sign in to comment.