Skip to content

Commit

Permalink
use NamedExpr
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxr committed Mar 26, 2015
1 parent c78e31a commit 85dd559
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,17 @@ case class CreateArray(children: Seq[Expression]) extends Expression {
/**
* Returns a Row containing the evaluation of all children expressions.
*/
case class CreateStruct(children: Seq[Expression]) extends Expression {
case class CreateStruct(children: Seq[NamedExpression]) extends Expression {
override type EvaluatedType = Row

override def foldable: Boolean = children.forall(_.foldable)

override lazy val resolved: Boolean = childrenResolved

override def dataType: StructType = {
override lazy val dataType: StructType = {
assert(resolved, s"CreateStruct is called with unresolved children: $children.")
val fields = children.map {
case named: NamedExpression =>
StructField(named.name, named.dataType, named.nullable, named.metadata)
val fields = children.map { child =>
StructField(child.name, child.dataType, child.nullable, child.metadata)
}
StructType(fields)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,8 @@ class ExpressionEvaluationSuite extends FunSuite {

test("CreateStruct") {
val row = Row(1, 2, 3)
val c1 = 'a.int.at(0)
val c3 = 'a.int.at(2)
val c1 = 'a.int.at(0).as("a")
val c3 = 'c.int.at(2).as("c")
checkEvaluation(CreateStruct(Seq(c1, c3)), Row(1, 3), row)
}
}

0 comments on commit 85dd559

Please sign in to comment.