Skip to content

Commit

Permalink
fix style and address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cloud-fan committed Jun 30, 2015
1 parent fc694e8 commit e3f8427
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ case class GetArrayStructFields(
}
}

//todo: add code gen for this.
// todo: add code gen for this.
}

abstract class ExtractValueWithOrdinal extends BinaryExpression with ExtractValue {
Expand All @@ -162,8 +162,8 @@ abstract class ExtractValueWithOrdinal extends BinaryExpression with ExtractValu
def ordinal: Expression
def child: Expression

def left = child
def right = ordinal
override def left: Expression = child
override def right: Expression = ordinal

/** `Null` is returned for invalid ordinals. */
override def nullable: Boolean = true
Expand Down Expand Up @@ -207,7 +207,8 @@ case class GetArrayItem(child: Expression, ordinal: Expression)
}

override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
defineCodeGen(ctx, ev, (eval1, eval2) => s"(${ctx.javaType(dataType)})$eval1.apply((int)$eval2)")
defineCodeGen(ctx, ev,
(eval1, eval2) => s"(${ctx.javaType(dataType)})$eval1.apply((int)$eval2)")
}
}

Expand All @@ -225,6 +226,7 @@ case class GetMapValue(child: Expression, ordinal: Expression)
}

override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
defineCodeGen(ctx, ev, (eval1, eval2) => s"(${ctx.javaType(dataType)})$eval1.getOrElse($eval2, null)")
defineCodeGen(ctx, ev,
(eval1, eval2) => s"(${ctx.javaType(dataType)})$eval1.getOrElse($eval2, null)")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class ComplexTypeSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(GetArrayItem(nullArray, Literal(1)), null)
checkEvaluation(GetArrayItem(array, nullInt), null)
checkEvaluation(GetArrayItem(nullArray, nullInt), null)

val nestedArray = Literal.create(Seq(Seq(1)), ArrayType(ArrayType(IntegerType)))
checkEvaluation(GetArrayItem(nestedArray, Literal(0)), Seq(1))
}

test("GetMapValue") {
Expand All @@ -62,6 +65,9 @@ class ComplexTypeSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(GetMapValue(map, nullString), null)
checkEvaluation(GetMapValue(nullMap, nullString), null)
checkEvaluation(GetMapValue(map, nullString), null)

val nestedMap = Literal.create(Map("a" -> Map("b" -> "c")), MapType(StringType, typeM))
checkEvaluation(GetMapValue(nestedMap, Literal("a")), Map("b" -> "c"))
}

test("GetStructField") {
Expand All @@ -80,6 +86,10 @@ class ComplexTypeSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(getStructField(struct, "a"), 1)
checkEvaluation(getStructField(nullStruct, "a"), null)

val nestedStruct = Literal.create(create_row(create_row(1)),
StructType(StructField("a", typeS) :: Nil))
checkEvaluation(getStructField(nestedStruct, "a"), create_row(1))

val typeS_fieldNotNullable = StructType(StructField("a", IntegerType, false) :: Nil)
val struct_fieldNotNullable = Literal.create(create_row(1), typeS_fieldNotNullable)
val nullStruct_fieldNotNullable = Literal.create(null, typeS_fieldNotNullable)
Expand Down

0 comments on commit e3f8427

Please sign in to comment.