-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implement monotonicity for ScalarUDF #8799
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @guojidan
Can we have tests for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @comphead 's request for a test
I was thinking about how we could write a test for this feature.
The easiest way would probably be a unit test using create_physical_expr
with a scalarUDF that shows the correct monotonicity.
A more end to end style one would be to show different explains depending on the monotonicity of a udf. For example, abs
is not monotonic and sqrt
is and thus they generate subtlely different plans:
For the abs
(non- montonic) the sort is done after the Projection
For sqrt
(monotonic) the sort is pushed below the Projection
❯ create table t as values (1), (3), (2);
0 rows in set. Query took 0.003 seconds.
❯ explain select abs(column1) as x from (SELECT * FROM t ORDER BY column1) ORDER BY x;
+---------------+---------------------------------------------------+
| plan_type | plan |
+---------------+---------------------------------------------------+
| logical_plan | Sort: x ASC NULLS LAST |
| | Projection: abs(t.column1) AS x |
| | Sort: t.column1 ASC NULLS LAST |
| | TableScan: t projection=[column1] |
| physical_plan | SortExec: expr=[x@0 ASC NULLS LAST] |
| | ProjectionExec: expr=[abs(column1@0) as x] |
| | MemoryExec: partitions=1, partition_sizes=[1] |
| | |
+---------------+---------------------------------------------------+
2 rows in set. Query took 0.004 seconds.
❯ explain select sqrt(column1) as x from (SELECT * FROM t ORDER BY column1) ORDER BY x;
+---------------+--------------------------------------------------------------+
| plan_type | plan |
+---------------+--------------------------------------------------------------+
| logical_plan | Sort: x ASC NULLS LAST |
| | Projection: sqrt(CAST(t.column1 AS Float64)) AS x |
| | Sort: t.column1 ASC NULLS LAST |
| | TableScan: t projection=[column1] |
| physical_plan | ProjectionExec: expr=[sqrt(CAST(column1@0 AS Float64)) as x] |
| | SortExec: expr=[column1@0 ASC NULLS LAST] |
| | MemoryExec: partitions=1, partition_sizes=[1] |
| | |
+---------------+--------------------------------------------------------------+
2 rows in set. Query took 0.003 seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which issue does this PR close?
Closes #8756 .
Rationale for this change
What changes are included in this PR?
add monotonicity function, User can define fun monotonicity by themselves