yaooqinn commented on code in PR #54034:
URL: https://github.com/apache/spark/pull/54034#discussion_r2744450474
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionResolution.scala:
##########
@@ -258,14 +228,46 @@ class FunctionResolution(
"FILTER clause"
)
}
- if (u.ignoreNulls) {
+ if (u.ignoreNulls.isDefined) {
throw QueryCompilationErrors.functionWithUnsupportedSyntaxError(
func.prettyName,
"IGNORE NULLS"
)
}
}
+ /**
+ * Resolves the IGNORE NULLS / RESPECT NULLS clause for a function.
+ * If ignoreNulls is defined, applies it to the function; otherwise returns
unchanged.
+ */
+ private def resolveIgnoreNulls[T <: Expression](func: T, ignoreNulls:
Option[Boolean]): T = {
+ ignoreNulls.map(applyIgnoreNulls(func, _)).getOrElse(func)
+ }
+
+ /**
+ * Applies the IGNORE NULLS / RESPECT NULLS clause to functions that support
it.
+ * Returns the modified function if supported, throws error otherwise.
+ */
+ private def applyIgnoreNulls[T <: Expression](func: T, ignoreNulls:
Boolean): T = {
+ val result = func match {
+ // Window functions
+ case nthValue: NthValue => nthValue.copy(ignoreNulls = ignoreNulls)
+ case lead: Lead => lead.copy(ignoreNulls = ignoreNulls)
+ case lag: Lag => lag.copy(ignoreNulls = ignoreNulls)
+ // Aggregate functions
+ case first: First => first.copy(ignoreNulls = ignoreNulls)
+ case last: Last => last.copy(ignoreNulls = ignoreNulls)
+ case anyValue: AnyValue => anyValue.copy(ignoreNulls = ignoreNulls)
+ case collectList: CollectList => collectList.copy(ignoreNulls =
ignoreNulls)
+ case _ =>
+ throw QueryCompilationErrors.functionWithUnsupportedSyntaxError(
Review Comment:
This makes sense.
--
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]