Github user zhichao-li commented on a diff in the pull request:
https://github.com/apache/spark/pull/7035#discussion_r33843222
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala
---
@@ -521,6 +521,55 @@ case class ShiftRight(left: Expression, right:
Expression) extends BinaryExpress
}
}
+case class ShiftRightUnsigned(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"ShiftRightUnsigned 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) {
+ left.dataType match {
--- End diff --
humm, using pattern match with a typed pattern is indeed a best practice in
scala rather than type tests and casts. @chenghao-intel any comments?
---
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]