Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/7178#discussion_r33751718
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala
---
@@ -351,6 +351,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]
--- End diff --
Should we use `>>>` (keeping the sign bit) or `>>` ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]