cloud-fan commented on code in PR #54297:
URL: https://github.com/apache/spark/pull/54297#discussion_r2862077866
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/collect.scala:
##########
@@ -592,6 +594,159 @@ case class ListAgg(
false
}
+ /**
+ * Returns true if the order value may be ambiguous after DISTINCT
deduplication.
+ *
+ * For LISTAGG(DISTINCT child) WITHIN GROUP (ORDER BY order_expr),
correctness requires
+ * a functional dependency (child -> order_expr, where equality is defined
by GROUP BY
+ * semantics): each distinct child value must map to exactly one order
value. Otherwise,
+ * after deduplication on child, the order value is ambiguous.
+ *
+ * When child = Cast(order_expr, T), child -> order_expr is trivially
satisfied since Cast is
Review Comment:
I don't think it's trivially satisfied, as CAST is usually not reversible,
things like truncation and normalization can easily breaking it.
Since `listagg` only accepts string or binary inputs, let's focus on these
two types.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/collect.scala:
##########
@@ -592,6 +594,159 @@ case class ListAgg(
false
}
+ /**
+ * Returns true if the order value may be ambiguous after DISTINCT
deduplication.
+ *
+ * For LISTAGG(DISTINCT child) WITHIN GROUP (ORDER BY order_expr),
correctness requires
+ * a functional dependency (child -> order_expr, where equality is defined
by GROUP BY
+ * semantics): each distinct child value must map to exactly one order
value. Otherwise,
+ * after deduplication on child, the order value is ambiguous.
+ *
+ * When child = Cast(order_expr, T), child -> order_expr is trivially
satisfied since Cast is
Review Comment:
I don't think it's trivially satisfied, as CAST is usually not reversible,
things like truncation and normalization can easily break it.
Since `listagg` only accepts string or binary inputs, let's focus on these
two types.
--
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]