metanil commented on code in PR #55885:
URL: https://github.com/apache/spark/pull/55885#discussion_r3276068885
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/functions/ReducibleFunction.java:
##########
@@ -60,6 +60,53 @@
@Evolving
public interface ReducibleFunction<I, O> {
+ /**
+ * Generic reducer for parameterized functions (bucket, truncate, etc.).
+ *
+ * If this function is 'reducible' on another function, return the {@link
Reducer}.
+ * <p>
+ * This method supports functions with any number of parameters of any type.
+ * <p>
+ * Examples:
+ * <ul>
+ * <li>bucket(4, x) and bucket(2, x):
+ * <br>thisParams = [4], otherParams = [2]
+ * <br>Extract with: thisParams.getInt(0), otherParams.getInt(0)
+ * </li>
+ * <li>truncate(x, 3) and truncate(x, 5):
+ * <br>thisParams = [3], otherParams = [5]
+ * <br>Extract with: thisParams.getInt(0), otherParams.getInt(0)
+ * </li>
+ * <li>hypothetical range_bucket(x, 0L, 100L, 4):
+ * <br>thisParams = [0L, 100L, 4]
+ * <br>Extract with: thisParams.getLong(0), thisParams.getLong(1),
thisParams.getInt(2)
+ * </li>
+ * </ul>
+ *
+ * @param thisParams parameters for this function
+ * @param otherFunction the other parameterized function
+ * @param otherParams parameters for the other function
+ * @return a reduction function if reducible, null otherwise
+ * @since 4.0.0
+ */
+ default Reducer<I, O> reducer(
+ ReducibleParameters thisParams,
+ ReducibleFunction<?, ?> otherFunction,
+ ReducibleParameters otherParams) {
+ // Default: try old Int-based API for backward compatibility
+ if (thisParams.count() == 1 && otherParams.count() == 1) {
Review Comment:
@szehon-ho Yes, this make sense. My initial idea was to not call
"deprecated" method, and when time to remove it would be only from 1 single
file (`ReducibleFunction`), but the approach is not natural (or norm), where
deprecated code calls the newer method.
When there's time to remove the method, we can remove from both, would not
be a big deal, and can't be missed too.
I'll make this change along with @sunchao mixed arity case.
--
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]