Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-wang committed Jan 29, 2016
1 parent 5b2d942 commit 2244999
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ case class GetArrayItem(child: Expression, ordinal: Expression)
protected override def nullSafeEval(value: Any, ordinal: Any): Any = {
val baseValue = value.asInstanceOf[ArrayData]
val index = ordinal.asInstanceOf[Number].intValue()
if (index >= baseValue.numElements() || index < 0) {
if (index >= baseValue.numElements() || index < 0 || baseValue.isNullAt(index)) {
null
} else {
baseValue.get(index, dataType)
Expand Down Expand Up @@ -267,6 +267,7 @@ case class GetMapValue(child: Expression, key: Expression)
val map = value.asInstanceOf[MapData]
val length = map.numElements()
val keys = map.keyArray()
val values = map.valueArray()

var i = 0
var found = false
Expand All @@ -278,10 +279,10 @@ case class GetMapValue(child: Expression, key: Expression)
}
}

if (!found || map.valueArray().isNullAt(i)) {
if (!found || values.isNullAt(i)) {
null
} else {
map.valueArray().get(i, dataType)
values.get(i, dataType)
}
}

Expand All @@ -291,10 +292,12 @@ case class GetMapValue(child: Expression, key: Expression)
val keys = ctx.freshName("keys")
val found = ctx.freshName("found")
val key = ctx.freshName("key")
val values = ctx.freshName("values")
nullSafeCodeGen(ctx, ev, (eval1, eval2) => {
s"""
final int $length = $eval1.numElements();
final ArrayData $keys = $eval1.keyArray();
final ArrayData $values = $eval1.valueArray();

int $index = 0;
boolean $found = false;
Expand All @@ -307,8 +310,8 @@ case class GetMapValue(child: Expression, key: Expression)
}
}

if ($found && !$eval1.valueArray().isNullAt($index)) {
${ev.value} = ${ctx.getValue(eval1 + ".valueArray()", dataType, index)};
if ($found && !$values.isNullAt($index)) {
${ev.value} = ${ctx.getValue(values, dataType, index)};
} else {
${ev.isNull} = true;
}
Expand Down

0 comments on commit 2244999

Please sign in to comment.