Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaido91 committed Apr 20, 2018
1 parent f2784f1 commit b94d067
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,23 +407,23 @@ case class Slice(x: Expression, start: Expression, length: Expression)
val arr = xVal.asInstanceOf[ArrayData]
val startIndex = if (startInt == 0) {
throw new RuntimeException(
s"Unexpected value for start in function $prettyName: SQL array indices start at 1.")
s"Unexpected value for start in function $prettyName: SQL array indices start at 1.")
} else if (startInt < 0) {
startInt + arr.numElements()
} else {
startInt - 1
}
if (lengthInt < 0) {
throw new RuntimeException(s"Unexpected value for length in function $prettyName: " +
s"length must be greater than or equal to 0.")
"length must be greater than or equal to 0.")
}
// this can happen if start is negative and its absolute value is greater than the
// startIndex can be negative if start is negative and its absolute value is greater than the
// number of elements in the array
if (startIndex < 0) {
if (startIndex < 0 || startIndex >= arr.numElements()) {
return new GenericArrayData(Array.empty[AnyRef])
}
val elementType = x.dataType.asInstanceOf[ArrayType].elementType
val data = arr.toArray[AnyRef](elementType)
val data = arr.toSeq[AnyRef](elementType)
new GenericArrayData(data.slice(startIndex, startIndex + lengthInt))
}

Expand Down Expand Up @@ -457,7 +457,7 @@ case class Slice(x: Expression, start: Expression, length: Expression)
| $resLength = $length;
|}
|Object[] $values;
|if ($startIdx < 0) {
|if ($startIdx < 0 || $startIdx >= $x.numElements()) {
| $values = new Object[0];
|} else {
| $values = new Object[$resLength];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper

checkEvaluation(Slice(a1, Literal(1), Literal(2)), Seq("a", "b"))
checkEvaluation(Slice(a2, Literal(1), Literal(2)), Seq("", null))

checkEvaluation(Slice(a0, Literal(10), Literal(1)), Seq.empty[Int])
}

test("Array Min") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ trait ExpressionEvalHelper extends GeneratorDrivenPropertyChecks {
}

protected def checkExceptionInExpression[T <: Throwable : ClassTag](
expression: Expression,
expression: => Expression,
expectedErrMsg: String): Unit = {
checkExceptionInExpression[T](expression, InternalRow.empty, expectedErrMsg)
}
Expand Down

0 comments on commit b94d067

Please sign in to comment.