cloud-fan commented on code in PR #42755:
URL: https://github.com/apache/spark/pull/42755#discussion_r1325576026
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/Mode.scala:
##########
@@ -35,24 +42,60 @@ import org.apache.spark.util.collection.OpenHashMap
0-10
> SELECT _FUNC_(col) FROM VALUES (0), (10), (10), (null), (null), (null)
AS tab(col);
10
+ > SELECT _FUNC_(col, false) FROM VALUES (-10), (0), (10) AS tab(col);
+ 0
+ > SELECT _FUNC_(col, true) FROM VALUES (-10), (0), (10) AS tab(col);
+ -10
""",
group = "agg_funcs",
since = "3.4.0")
// scalastyle:on line.size.limit
case class Mode(
child: Expression,
mutableAggBufferOffset: Int = 0,
- inputAggBufferOffset: Int = 0) extends TypedAggregateWithHashMapAsBuffer
- with ImplicitCastInputTypes with UnaryLike[Expression] {
+ inputAggBufferOffset: Int = 0,
+ deterministicExpr: Expression = Literal.FalseLiteral)
+ extends TypedAggregateWithHashMapAsBuffer with ImplicitCastInputTypes
+ with BinaryLike[Expression] {
def this(child: Expression) = this(child, 0, 0)
+ def this(child: Expression, deterministicExpr: Expression) = {
+ this(child, 0, 0, deterministicExpr)
+ }
+
+ @transient
+ protected lazy val deterministicResult =
deterministicExpr.eval().asInstanceOf[Boolean]
+
+ override def left: Expression = child
+
+ override def right: Expression = deterministicExpr
+
// Returns null for empty inputs
override def nullable: Boolean = true
override def dataType: DataType = child.dataType
- override def inputTypes: Seq[AbstractDataType] = Seq(AnyDataType)
+ override def inputTypes: Seq[AbstractDataType] = Seq(AnyDataType,
BooleanType)
+
+ override def checkInputDataTypes(): TypeCheckResult = {
+ val defaultCheck = super.checkInputDataTypes()
+ if (defaultCheck.isFailure) {
+ return defaultCheck
+ }
+ if (!deterministicExpr.foldable) {
+ DataTypeMismatch(
+ errorSubClass = "NON_FOLDABLE_INPUT",
+ messageParameters = Map(
+ "inputName" -> toSQLId("deterministic"),
+ "inputType" -> toSQLType(deterministicExpr.dataType),
+ "inputExpr" -> toSQLExpr(deterministicExpr)
+ )
+ )
+ } else {
+ TypeCheckSuccess
Review Comment:
shall we fail for null deterministic flag?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]