Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10677#discussion_r51644299
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/bitwiseExpressions.scala
 ---
    @@ -124,3 +124,47 @@ case class BitwiseNot(child: Expression) extends 
UnaryExpression with ExpectsInp
     
       protected override def nullSafeEval(input: Any): Any = not(input)
     }
    +
    +/**
    +  * A function that reverse the lowest N bits of a integer.
    +  *
    +  * Note: this is only used for grouping_id()
    +  */
    +case class BitwiseReverse(child: Expression, width: Int)
    +  extends UnaryExpression with ExpectsInputTypes {
    +
    +  override def inputTypes: Seq[AbstractDataType] = Seq(IntegerType)
    +
    +  override def dataType: DataType = IntegerType
    +
    +  override def toString: String = s"^$child"
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): 
String = {
    +    nullSafeCodeGen(ctx, ev, c => {
    +      val v = ctx.freshName("v")
    +      val i = ctx.freshName("i")
    +      s"""
    +         | int $v = $c;
    +         | ${ev.value} = 0;
    +         | for (int $i = 0; $i < $width; $i ++) {
    +         |   ${ev.value} <<= 1;
    +         |   ${ev.value} |= $v & 1;
    +         |   $v >>>= 1;
    +         | }
    +       """.stripMargin
    +    })
    +  }
    +
    +  protected override def nullSafeEval(input: Any): Any = {
    +    var v = input.asInstanceOf[Int]
    --- End diff --
    
    Great, will do.


---
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]

Reply via email to