Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
cloud-fan committed May 8, 2015
1 parent c9d85f5 commit b5961a9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ package object dsl {
def isNotNull: Predicate = IsNotNull(expr)

def getItem(ordinal: Expression): UnresolvedGetField = UnresolvedGetField(expr, ordinal)
def getField(fieldName: String): UnresolvedGetField = UnresolvedGetField(expr, Literal(fieldName))
def getField(fieldName: String): UnresolvedGetField =
UnresolvedGetField(expr, Literal(fieldName))

def cast(to: DataType): Expression = Cast(expr, to)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ object GetField {
MapOrdinalGetField(child, fieldExpr)
case (otherType, _) =>
throw new AnalysisException(
s"GetField is not valid on child of type $otherType with fieldExpr of type ${fieldExpr.dataType}")
"GetField is not valid on child of type " +
s"$otherType with fieldExpr of type ${fieldExpr.dataType}")
}
}

Expand Down Expand Up @@ -138,8 +139,11 @@ case class SimpleStructGetField(child: Expression, field: StructField, ordinal:
/**
* Returns the array of value of fields in the Array of Struct `child`.
*/
case class ArrayStructGetField(child: Expression, field: StructField, ordinal: Int, containsNull: Boolean)
extends StructGetField {
case class ArrayStructGetField(
child: Expression,
field: StructField,
ordinal: Int,
containsNull: Boolean) extends StructGetField {

override def dataType: DataType = ArrayType(field.dataType, containsNull)
override def nullable: Boolean = child.nullable
Expand All @@ -160,7 +164,7 @@ case class ArrayStructGetField(child: Expression, field: StructField, ordinal: I
case class ArrayOrdinalGetField(child: Expression, ordinal: Expression)
extends OrdinalGetField {

override def dataType = child.dataType.asInstanceOf[ArrayType].elementType
override def dataType: DataType = child.dataType.asInstanceOf[ArrayType].elementType

override lazy val resolved = childrenResolved &&
child.dataType.isInstanceOf[ArrayType] && ordinal.dataType.isInstanceOf[IntegralType]
Expand All @@ -184,12 +188,12 @@ case class ArrayOrdinalGetField(child: Expression, ordinal: Expression)
case class MapOrdinalGetField(child: Expression, ordinal: Expression)
extends OrdinalGetField {

override def dataType = child.dataType.asInstanceOf[MapType].valueType
override def dataType: DataType = child.dataType.asInstanceOf[MapType].valueType

override lazy val resolved = childrenResolved && child.dataType.isInstanceOf[MapType]

protected def evalNotNull(value: Any, ordinal: Any) = {
val baseValue = value.asInstanceOf[Map[Any, _]]
baseValue.get(ordinal).orNull
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -895,15 +895,17 @@ class ExpressionEvaluationSuite extends ExpressionEvaluationBaseSuite {
Literal("aa")), "bb", row)
checkEvaluation(MapOrdinalGetField(Literal.create(null, typeMap), Literal("aa")), null, row)
checkEvaluation(
MapOrdinalGetField(Literal.create(null, typeMap), Literal.create(null, StringType)), null, row)
MapOrdinalGetField(Literal.create(null, typeMap),
Literal.create(null, StringType)), null, row)
checkEvaluation(MapOrdinalGetField(BoundReference(3, typeMap, true),
Literal.create(null, StringType)), null, row)

checkEvaluation(ArrayOrdinalGetField(BoundReference(4, typeArray, true),
Literal(1)), "bb", row)
checkEvaluation(ArrayOrdinalGetField(Literal.create(null, typeArray), Literal(1)), null, row)
checkEvaluation(
ArrayOrdinalGetField(Literal.create(null, typeArray), Literal.create(null, IntegerType)), null, row)
ArrayOrdinalGetField(Literal.create(null, typeArray),
Literal.create(null, IntegerType)), null, row)
checkEvaluation(ArrayOrdinalGetField(BoundReference(4, typeArray, true),
Literal.create(null, IntegerType)), null, row)

Expand Down

0 comments on commit b5961a9

Please sign in to comment.