Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' of github.com:apache/spark into hex
Conflicts:
	sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala
	sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathFunctionsSuite.scala
  • Loading branch information
Davies Liu committed Jul 2, 2015
commit 49e325feee237a4cba040799434a9668a2f7e2e9
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,104 @@ case class Pow(left: Expression, right: Expression)
}
}

case class ShiftLeft(left: Expression, right: Expression) extends BinaryExpression {

override def checkInputDataTypes(): TypeCheckResult = {
(left.dataType, right.dataType) match {
case (NullType, _) | (_, NullType) => return TypeCheckResult.TypeCheckSuccess
case (_, IntegerType) => left.dataType match {
case LongType | IntegerType | ShortType | ByteType =>
return TypeCheckResult.TypeCheckSuccess
case _ => // failed
}
case _ => // failed
}
TypeCheckResult.TypeCheckFailure(
s"ShiftLeft expects long, integer, short or byte value as first argument and an " +
s"integer value as second argument, not (${left.dataType}, ${right.dataType})")
}

override def eval(input: InternalRow): Any = {
val valueLeft = left.eval(input)
if (valueLeft != null) {
val valueRight = right.eval(input)
if (valueRight != null) {
valueLeft match {
case l: Long => l << valueRight.asInstanceOf[Integer]
case i: Integer => i << valueRight.asInstanceOf[Integer]
case s: Short => s << valueRight.asInstanceOf[Integer]
case b: Byte => b << valueRight.asInstanceOf[Integer]
}
} else {
null
}
} else {
null
}
}

override def dataType: DataType = {
left.dataType match {
case LongType => LongType
case IntegerType | ShortType | ByteType => IntegerType
case _ => NullType
}
}

override protected def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
nullSafeCodeGen(ctx, ev, (result, left, right) => s"$result = $left << $right;")
}
}

case class ShiftRight(left: Expression, right: Expression) extends BinaryExpression {

override def checkInputDataTypes(): TypeCheckResult = {
(left.dataType, right.dataType) match {
case (NullType, _) | (_, NullType) => return TypeCheckResult.TypeCheckSuccess
case (_, IntegerType) => left.dataType match {
case LongType | IntegerType | ShortType | ByteType =>
return TypeCheckResult.TypeCheckSuccess
case _ => // failed
}
case _ => // failed
}
TypeCheckResult.TypeCheckFailure(
s"ShiftRight expects long, integer, short or byte value as first argument and an " +
s"integer value as second argument, not (${left.dataType}, ${right.dataType})")
}

override def eval(input: InternalRow): Any = {
val valueLeft = left.eval(input)
if (valueLeft != null) {
val valueRight = right.eval(input)
if (valueRight != null) {
valueLeft match {
case l: Long => l >> valueRight.asInstanceOf[Integer]
case i: Integer => i >> valueRight.asInstanceOf[Integer]
case s: Short => s >> valueRight.asInstanceOf[Integer]
case b: Byte => b >> valueRight.asInstanceOf[Integer]
}
} else {
null
}
} else {
null
}
}

override def dataType: DataType = {
left.dataType match {
case LongType => LongType
case IntegerType | ShortType | ByteType => IntegerType
case _ => NullType
}
}

override protected def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
nullSafeCodeGen(ctx, ev, (result, left, right) => s"$result = $left >> $right;")
}
}

case class Hypot(left: Expression, right: Expression)
extends BinaryMathExpression(math.hypot, "HYPOT")

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.