-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29545][SQL] Add support for bit_xor aggregate function #26205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
b6047b4
dcd9685
9a777ca
8e04b30
ffb1a60
97eeab2
1481aa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| package org.apache.spark.sql.catalyst.expressions.aggregate | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.{AttributeReference, BitwiseAnd, BitwiseOr, ExpectsInputTypes, Expression, ExpressionDescription, If, IsNull, Literal} | ||
| import org.apache.spark.sql.catalyst.expressions.{AttributeReference, BitwiseAnd, BitwiseOr, BitwiseXor, ExpectsInputTypes, Expression, ExpressionDescription, If, IsNull, Literal} | ||
| import org.apache.spark.sql.types.{AbstractDataType, DataType, IntegralType} | ||
|
|
||
| @ExpressionDescription( | ||
|
|
@@ -97,3 +97,42 @@ case class BitOrAgg(child: Expression) extends DeclarativeAggregate with Expects | |
|
|
||
| override lazy val evaluateExpression: AttributeReference = bitOr | ||
| } | ||
|
|
||
| @ExpressionDescription( | ||
| usage = "_FUNC_(expr) - Returns the bitwise XOR of all non-null input values, or null if none.", | ||
| examples = """ | ||
| Examples: | ||
| > SELECT _FUNC_(col) FROM VALUES (3), (5) AS tab(col); | ||
| 6 | ||
| """, | ||
| since = "3.0.0") | ||
| case class BitXorAgg(child: Expression) extends DeclarativeAggregate with ExpectsInputTypes { | ||
|
||
|
|
||
| override def nodeName: String = "bit_xor" | ||
|
|
||
| override def children: Seq[Expression] = child :: Nil | ||
|
|
||
| override def nullable: Boolean = true | ||
|
|
||
| override def dataType: DataType = child.dataType | ||
|
|
||
| override def inputTypes: Seq[AbstractDataType] = Seq(IntegralType) | ||
|
|
||
| private lazy val bitXOr = AttributeReference("bit_xor", child.dataType)() | ||
|
|
||
| override lazy val aggBufferAttributes: Seq[AttributeReference] = bitXOr :: Nil | ||
|
|
||
| override lazy val initialValues: Seq[Literal] = Literal.create(null, dataType) :: Nil | ||
|
|
||
| override lazy val updateExpressions: Seq[Expression] = | ||
| If(IsNull(bitXOr), | ||
| child, | ||
| If(IsNull(child), bitXOr, BitwiseXor(bitXOr, child))) :: Nil | ||
|
|
||
| override lazy val mergeExpressions: Seq[Expression] = | ||
| If(IsNull(bitXOr.left), | ||
| bitXOr.right, | ||
| If(IsNull(bitXOr.right), bitXOr.left, BitwiseXor(bitXOr.left, bitXOr.right))) :: Nil | ||
|
|
||
| override lazy val evaluateExpression: AttributeReference = bitXOr | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.