Skip to content

Commit 91fe489

Browse files
committed
add Byte and Short.
1 parent 1bdc69d commit 91fe489

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ class SqlParser extends AbstractSparkSQLParser {
343343
val bigIntValue = BigDecimal(value)
344344

345345
bigIntValue match {
346+
case v if bigIntValue.isValidByte => v.toByteExact
347+
case v if bigIntValue.isValidShort => v.toShortExact
346348
case v if bigIntValue.isValidInt => v.toIntExact
347349
case v if bigIntValue.isValidLong => v.toLongExact
348350
case v => v

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypes.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ case class GetItem(child: Expression, ordinal: Expression) extends Expression {
5555
// TODO: consider using Array[_] for ArrayType child to avoid
5656
// boxing of primitives
5757
val baseValue = value.asInstanceOf[Seq[_]]
58-
val o = key.asInstanceOf[Int]
58+
val o = key match {
59+
case k if k.isInstanceOf[Byte] => k.asInstanceOf[Byte]
60+
case k if k.isInstanceOf[Short] => k.asInstanceOf[Short]
61+
case k => k.asInstanceOf[Int]
62+
}
5963
if (o >= baseValue.size || o < 0) {
6064
null
6165
} else {

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ object Literal {
4747
object IntegerLiteral {
4848
def unapply(a: Any): Option[Int] = a match {
4949
case Literal(a: Int, IntegerType) => Some(a)
50+
case Literal(a: Byte, ByteType) => Some(a.toInt)
51+
case Literal(a: Short, ShortType) => Some(a.toInt)
5052
case _ => None
5153
}
5254
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,16 @@ case class Substring(str: Expression, pos: Expression, len: Expression) extends
257257
if ((string == null) || (po == null) || (ln == null)) {
258258
null
259259
} else {
260-
val start = po.asInstanceOf[Int]
261-
val length = ln.asInstanceOf[Int]
262-
260+
val start = po match {
261+
case k if k.isInstanceOf[Byte] => k.asInstanceOf[Byte]
262+
case k if k.isInstanceOf[Short] => k.asInstanceOf[Short]
263+
case k => k.asInstanceOf[Int]
264+
}
265+
val length = ln match {
266+
case k if k.isInstanceOf[Byte] => k.asInstanceOf[Byte]
267+
case k if k.isInstanceOf[Short] => k.asInstanceOf[Short]
268+
case k => k.asInstanceOf[Int]
269+
}
263270
string match {
264271
case ba: Array[Byte] => slice(ba, start, length)
265272
case other => slice(other.toString, start, length)

0 commit comments

Comments
 (0)