Skip to content

Commit

Permalink
support long type in GetArrayItem
Browse files Browse the repository at this point in the history
  • Loading branch information
cloud-fan committed May 12, 2015
1 parent b94a933 commit 89899b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ case class GetArrayItem(child: Expression, ordinal: Expression)
// TODO: consider using Array[_] for ArrayType child to avoid
// boxing of primitives
val baseValue = value.asInstanceOf[Seq[_]]
val index = ordinal.asInstanceOf[Int]
val index = ordinal.asInstanceOf[Number].longValue()
if (index >= baseValue.size || index < 0) {
null
} else {
baseValue(index)
baseValue(index.asInstanceOf[Int])
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1313,4 +1313,10 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {

checkAnswer(sql("SELECT a.`c.b`, `b.$q`[0].`a@!.q`, `q.w`.`w.i&`[0] FROM t"), Row(1, 1, 1))
}

test("SPARK-7153: Long type ordinal in GetArrayItem") {
jsonRDD(sparkContext.makeRDD(
"""{"a": [1, 2, 3], "b": 2}""" :: Nil)).registerTempTable("t")
checkAnswer(sql("SELECT a[b] FROM t"), Row(3))
}
}

0 comments on commit 89899b0

Please sign in to comment.