You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "findepi (via GitHub)" <gi...@apache.org> on 2025/08/13 20:44:54 UTC

[PR] Fix PartialOrd for ScalarUDF [datafusion]

findepi opened a new pull request, #17182:
URL: https://github.com/apache/datafusion/pull/17182

   - fixes https://github.com/apache/datafusion/issues/17064


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix PartialOrd for ScalarUDF [datafusion]

Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #17182:
URL: https://github.com/apache/datafusion/pull/17182#discussion_r2282823901


##########
datafusion/expr/src/udf.rs:
##########
@@ -67,14 +67,31 @@ impl PartialEq for ScalarUDF {
     }
 }
 
-// TODO (https://github.com/apache/datafusion/issues/17064) PartialOrd is not consistent with PartialEq for `ScalarUDF` and it should be
-// Manual implementation based on `ScalarUDFImpl::equals`
 impl PartialOrd for ScalarUDF {
     fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
-        match self.name().partial_cmp(other.name()) {
-            Some(Ordering::Equal) => self.signature().partial_cmp(other.signature()),
-            cmp => cmp,
+        let mut cmp = self.name().cmp(other.name());
+        if cmp == Ordering::Equal {
+            cmp = self.signature().partial_cmp(other.signature())?;
         }

Review Comment:
   That would make `debug_assert` below unreachable. Do you want me to delete it?



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix PartialOrd for ScalarUDF [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #17182:
URL: https://github.com/apache/datafusion/pull/17182#issuecomment-3211684262

   Look s good to me -- thanks @findepi 


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix PartialOrd for ScalarUDF [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #17182:
URL: https://github.com/apache/datafusion/pull/17182#issuecomment-3211632526

   🤖: Benchmark completed
   
   <details><summary>Details</summary>
   <p>
   
   
   ```
   group                                         findepi_fix-partialord-for-scalarudf-dfb3ab    main
   -----                                         -------------------------------------------    ----
   logical_aggregate_with_join                   1.00    638.0±3.46µs        ? ?/sec            1.00    635.2±2.29µs        ? ?/sec
   logical_select_all_from_1000                  1.00     11.1±0.04ms        ? ?/sec            1.00     11.1±0.11ms        ? ?/sec
   logical_select_one_from_700                   1.03    435.1±1.40µs        ? ?/sec            1.00    420.9±1.52µs        ? ?/sec
   logical_trivial_join_high_numbered_columns    1.02    385.4±1.11µs        ? ?/sec            1.00    377.4±2.64µs        ? ?/sec
   logical_trivial_join_low_numbered_columns     1.02    371.2±0.78µs        ? ?/sec            1.00    363.5±2.15µs        ? ?/sec
   physical_intersection                         1.02    852.2±2.60µs        ? ?/sec            1.00    838.4±4.69µs        ? ?/sec
   physical_join_consider_sort                   1.02   1429.1±5.16µs        ? ?/sec            1.00  1404.4±11.62µs        ? ?/sec
   physical_join_distinct                        1.02    362.0±1.21µs        ? ?/sec            1.00    354.9±1.08µs        ? ?/sec
   physical_many_self_joins                      1.00     10.5±0.02ms        ? ?/sec            1.00     10.4±0.03ms        ? ?/sec
   physical_plan_clickbench_all                  1.00    192.4±0.96ms        ? ?/sec            1.00    192.5±0.96ms        ? ?/sec
   physical_plan_clickbench_q1                   1.00      2.6±0.01ms        ? ?/sec            1.00      2.6±0.01ms        ? ?/sec
   physical_plan_clickbench_q10                  1.00      3.5±0.02ms        ? ?/sec            1.00      3.5±0.01ms        ? ?/sec
   physical_plan_clickbench_q11                  1.00      3.7±0.02ms        ? ?/sec            1.00      3.7±0.01ms        ? ?/sec
   physical_plan_clickbench_q12                  1.01      3.8±0.03ms        ? ?/sec            1.00      3.8±0.02ms        ? ?/sec
   physical_plan_clickbench_q13                  1.00      3.5±0.03ms        ? ?/sec            1.00      3.5±0.02ms        ? ?/sec
   physical_plan_clickbench_q14                  1.00      3.7±0.02ms        ? ?/sec            1.01      3.7±0.03ms        ? ?/sec
   physical_plan_clickbench_q15                  1.00      3.5±0.02ms        ? ?/sec            1.01      3.6±0.03ms        ? ?/sec
   physical_plan_clickbench_q16                  1.03      3.5±0.11ms        ? ?/sec            1.00      3.4±0.02ms        ? ?/sec
   physical_plan_clickbench_q17                  1.01      3.5±0.02ms        ? ?/sec            1.00      3.5±0.04ms        ? ?/sec
   physical_plan_clickbench_q18                  1.00      3.0±0.01ms        ? ?/sec            1.00      3.0±0.02ms        ? ?/sec
   physical_plan_clickbench_q19                  1.01      3.9±0.02ms        ? ?/sec            1.00      3.9±0.02ms        ? ?/sec
   physical_plan_clickbench_q2                   1.00      3.1±0.02ms        ? ?/sec            1.01      3.1±0.02ms        ? ?/sec
   physical_plan_clickbench_q20                  1.00      2.8±0.02ms        ? ?/sec            1.00      2.7±0.02ms        ? ?/sec
   physical_plan_clickbench_q21                  1.01      3.1±0.02ms        ? ?/sec            1.00      3.1±0.02ms        ? ?/sec
   physical_plan_clickbench_q22                  1.00      3.7±0.04ms        ? ?/sec            1.00      3.7±0.02ms        ? ?/sec
   physical_plan_clickbench_q23                  1.00      3.9±0.02ms        ? ?/sec            1.00      3.9±0.02ms        ? ?/sec
   physical_plan_clickbench_q24                  1.00      4.5±0.02ms        ? ?/sec            1.01      4.5±0.02ms        ? ?/sec
   physical_plan_clickbench_q25                  1.00      3.2±0.03ms        ? ?/sec            1.00      3.3±0.02ms        ? ?/sec
   physical_plan_clickbench_q26                  1.00      3.0±0.01ms        ? ?/sec            1.00      3.0±0.03ms        ? ?/sec
   physical_plan_clickbench_q27                  1.01      3.3±0.09ms        ? ?/sec            1.00      3.3±0.03ms        ? ?/sec
   physical_plan_clickbench_q28                  1.01      4.0±0.03ms        ? ?/sec            1.00      4.0±0.04ms        ? ?/sec
   physical_plan_clickbench_q29                  1.02      4.8±0.08ms        ? ?/sec            1.00      4.7±0.02ms        ? ?/sec
   physical_plan_clickbench_q3                   1.00      3.0±0.01ms        ? ?/sec            1.00      3.0±0.03ms        ? ?/sec
   physical_plan_clickbench_q30                  1.00     13.2±0.08ms        ? ?/sec            1.00     13.1±0.23ms        ? ?/sec
   physical_plan_clickbench_q31                  1.00      4.0±0.03ms        ? ?/sec            1.00      4.0±0.04ms        ? ?/sec
   physical_plan_clickbench_q32                  1.00      4.0±0.02ms        ? ?/sec            1.00      4.0±0.03ms        ? ?/sec
   physical_plan_clickbench_q33                  1.01      3.5±0.03ms        ? ?/sec            1.00      3.5±0.02ms        ? ?/sec
   physical_plan_clickbench_q34                  1.01      3.2±0.02ms        ? ?/sec            1.00      3.2±0.02ms        ? ?/sec
   physical_plan_clickbench_q35                  1.00      3.3±0.02ms        ? ?/sec            1.00      3.3±0.02ms        ? ?/sec
   physical_plan_clickbench_q36                  1.01      4.0±0.02ms        ? ?/sec            1.00      4.0±0.02ms        ? ?/sec
   physical_plan_clickbench_q37                  1.00      4.0±0.03ms        ? ?/sec            1.00      4.0±0.03ms        ? ?/sec
   physical_plan_clickbench_q38                  1.00      4.0±0.03ms        ? ?/sec            1.00      4.0±0.02ms        ? ?/sec
   physical_plan_clickbench_q39                  1.01      3.8±0.02ms        ? ?/sec            1.00      3.8±0.02ms        ? ?/sec
   physical_plan_clickbench_q4                   1.00      2.7±0.02ms        ? ?/sec            1.01      2.7±0.01ms        ? ?/sec
   physical_plan_clickbench_q40                  1.00      4.4±0.02ms        ? ?/sec            1.01      4.5±0.02ms        ? ?/sec
   physical_plan_clickbench_q41                  1.01      4.0±0.04ms        ? ?/sec            1.00      4.0±0.03ms        ? ?/sec
   physical_plan_clickbench_q42                  1.00      3.9±0.02ms        ? ?/sec            1.00      3.9±0.03ms        ? ?/sec
   physical_plan_clickbench_q43                  1.01      4.3±0.03ms        ? ?/sec            1.00      4.2±0.03ms        ? ?/sec
   physical_plan_clickbench_q44                  1.00      2.8±0.02ms        ? ?/sec            1.00      2.8±0.02ms        ? ?/sec
   physical_plan_clickbench_q45                  1.00      2.8±0.02ms        ? ?/sec            1.00      2.8±0.02ms        ? ?/sec
   physical_plan_clickbench_q46                  1.01      3.3±0.02ms        ? ?/sec            1.00      3.3±0.02ms        ? ?/sec
   physical_plan_clickbench_q47                  1.00      3.9±0.03ms        ? ?/sec            1.00      3.9±0.03ms        ? ?/sec
   physical_plan_clickbench_q48                  1.00      4.6±0.02ms        ? ?/sec            1.00      4.6±0.03ms        ? ?/sec
   physical_plan_clickbench_q49                  1.01      4.9±0.06ms        ? ?/sec            1.00      4.8±0.03ms        ? ?/sec
   physical_plan_clickbench_q5                   1.01      2.9±0.02ms        ? ?/sec            1.00      2.9±0.02ms        ? ?/sec
   physical_plan_clickbench_q50                  1.00      4.3±0.02ms        ? ?/sec            1.00      4.3±0.03ms        ? ?/sec
   physical_plan_clickbench_q51                  1.00      3.4±0.03ms        ? ?/sec            1.00      3.4±0.02ms        ? ?/sec
   physical_plan_clickbench_q6                   1.00      2.9±0.01ms        ? ?/sec            1.00      2.9±0.02ms        ? ?/sec
   physical_plan_clickbench_q7                   1.01      2.6±0.02ms        ? ?/sec            1.00      2.6±0.02ms        ? ?/sec
   physical_plan_clickbench_q8                   1.01      3.5±0.02ms        ? ?/sec            1.00      3.5±0.02ms        ? ?/sec
   physical_plan_clickbench_q9                   1.00      3.4±0.03ms        ? ?/sec            1.00      3.3±0.03ms        ? ?/sec
   physical_plan_tpcds_all                       1.01   1021.7±2.17ms        ? ?/sec            1.00   1015.6±2.47ms        ? ?/sec
   physical_plan_tpch_all                        1.00     62.1±0.23ms        ? ?/sec            1.00     62.1±0.25ms        ? ?/sec
   physical_plan_tpch_q1                         1.00      2.0±0.01ms        ? ?/sec            1.00      2.0±0.01ms        ? ?/sec
   physical_plan_tpch_q10                        1.00      3.8±0.01ms        ? ?/sec            1.00      3.8±0.01ms        ? ?/sec
   physical_plan_tpch_q11                        1.01      3.3±0.01ms        ? ?/sec            1.00      3.3±0.01ms        ? ?/sec
   physical_plan_tpch_q12                        1.00   1812.5±8.84µs        ? ?/sec            1.00   1804.6±5.72µs        ? ?/sec
   physical_plan_tpch_q13                        1.00   1449.8±7.39µs        ? ?/sec            1.00   1444.7±7.83µs        ? ?/sec
   physical_plan_tpch_q14                        1.00  1960.4±11.34µs        ? ?/sec            1.00   1962.8±6.71µs        ? ?/sec
   physical_plan_tpch_q16                        1.01      2.5±0.01ms        ? ?/sec            1.00      2.5±0.00ms        ? ?/sec
   physical_plan_tpch_q17                        1.01      2.4±0.01ms        ? ?/sec            1.00      2.4±0.01ms        ? ?/sec
   physical_plan_tpch_q18                        1.00      2.7±0.01ms        ? ?/sec            1.00      2.7±0.01ms        ? ?/sec
   physical_plan_tpch_q19                        1.01      3.2±0.01ms        ? ?/sec            1.00      3.2±0.01ms        ? ?/sec
   physical_plan_tpch_q2                         1.00      5.5±0.02ms        ? ?/sec            1.00      5.5±0.02ms        ? ?/sec
   physical_plan_tpch_q20                        1.01      3.1±0.01ms        ? ?/sec            1.00      3.1±0.01ms        ? ?/sec
   physical_plan_tpch_q21                        1.00      4.1±0.01ms        ? ?/sec            1.00      4.1±0.01ms        ? ?/sec
   physical_plan_tpch_q22                        1.01      2.7±0.00ms        ? ?/sec            1.00      2.7±0.01ms        ? ?/sec
   physical_plan_tpch_q3                         1.01      2.6±0.01ms        ? ?/sec            1.00      2.6±0.01ms        ? ?/sec
   physical_plan_tpch_q4                         1.00   1512.1±4.57µs        ? ?/sec            1.00  1511.2±10.09µs        ? ?/sec
   physical_plan_tpch_q5                         1.00      3.1±0.01ms        ? ?/sec            1.00      3.1±0.01ms        ? ?/sec
   physical_plan_tpch_q6                         1.01    860.2±4.61µs        ? ?/sec            1.00    855.7±3.95µs        ? ?/sec
   physical_plan_tpch_q7                         1.00      4.2±0.01ms        ? ?/sec            1.00      4.2±0.02ms        ? ?/sec
   physical_plan_tpch_q8                         1.00      5.2±0.01ms        ? ?/sec            1.00      5.1±0.01ms        ? ?/sec
   physical_plan_tpch_q9                         1.01      4.1±0.02ms        ? ?/sec            1.00      4.1±0.01ms        ? ?/sec
   physical_select_aggregates_from_200           1.00     16.6±0.12ms        ? ?/sec            1.00     16.7±0.05ms        ? ?/sec
   physical_select_all_from_1000                 1.00     24.5±0.12ms        ? ?/sec            1.00     24.4±0.05ms        ? ?/sec
   physical_select_one_from_700                  1.02   1126.0±4.54µs        ? ?/sec            1.00   1099.3±5.89µs        ? ?/sec
   physical_sorted_union_orderby                 1.00     41.6±0.09ms        ? ?/sec            1.00     41.5±0.12ms        ? ?/sec
   physical_theta_join_consider_sort             1.01   1780.2±4.55µs        ? ?/sec            1.00   1768.3±8.61µs        ? ?/sec
   physical_unnest_to_join                       1.02   1332.6±4.74µs        ? ?/sec            1.00   1308.2±5.55µs        ? ?/sec
   with_param_values_many_columns                1.00    141.7±0.86µs        ? ?/sec            1.00    141.5±0.76µs        ? ?/sec
   ```
   
   
   </p>
   </details>
   
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix PartialOrd for ScalarUDF [datafusion]

Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on PR #17182:
URL: https://github.com/apache/datafusion/pull/17182#issuecomment-3187133065

   cc @ngli-me @jayzhan211 @alamb


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix PartialOrd for ScalarUDF [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #17182:
URL: https://github.com/apache/datafusion/pull/17182


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix PartialOrd for ScalarUDF [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #17182:
URL: https://github.com/apache/datafusion/pull/17182#discussion_r2282409901


##########
datafusion/expr/src/udf.rs:
##########
@@ -67,14 +67,31 @@ impl PartialEq for ScalarUDF {
     }
 }
 
-// TODO (https://github.com/apache/datafusion/issues/17064) PartialOrd is not consistent with PartialEq for `ScalarUDF` and it should be
-// Manual implementation based on `ScalarUDFImpl::equals`
 impl PartialOrd for ScalarUDF {
     fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
-        match self.name().partial_cmp(other.name()) {
-            Some(Ordering::Equal) => self.signature().partial_cmp(other.signature()),
-            cmp => cmp,
+        let mut cmp = self.name().cmp(other.name());
+        if cmp == Ordering::Equal {
+            cmp = self.signature().partial_cmp(other.signature())?;
         }

Review Comment:
   I think we could short circut the comparison if the ordering is not equal 
   
   Something like this, which should avoid computation in many cases
   
   ```rust
          if cmp != Ordering::Equal {
             return cmp
           }
   ```



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix PartialOrd for ScalarUDF [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #17182:
URL: https://github.com/apache/datafusion/pull/17182#discussion_r2282993023


##########
datafusion/expr/src/udf.rs:
##########
@@ -67,14 +67,31 @@ impl PartialEq for ScalarUDF {
     }
 }
 
-// TODO (https://github.com/apache/datafusion/issues/17064) PartialOrd is not consistent with PartialEq for `ScalarUDF` and it should be
-// Manual implementation based on `ScalarUDFImpl::equals`
 impl PartialOrd for ScalarUDF {
     fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
-        match self.name().partial_cmp(other.name()) {
-            Some(Ordering::Equal) => self.signature().partial_cmp(other.signature()),
-            cmp => cmp,
+        let mut cmp = self.name().cmp(other.name());
+        if cmp == Ordering::Equal {
+            cmp = self.signature().partial_cmp(other.signature())?;
         }

Review Comment:
   No, I think the debug assert is good. Sorry for not being clear



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix PartialOrd for ScalarUDF [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #17182:
URL: https://github.com/apache/datafusion/pull/17182#issuecomment-3211477902

   🤖 `./gh_compare_branch_bench.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/gh_compare_branch_bench.sh) Running
   Linux aal-dev 6.14.0-1014-gcp #15~24.04.1-Ubuntu SMP Fri Jul 25 23:26:08 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
   Comparing findepi/fix-partialord-for-scalarudf-dfb3ab (e2968e750dba62808053006d780a9ae79f924af9) to 541fdfbc0d882709d76924971c1f78377b017782 [diff](https://github.com/apache/datafusion/compare/541fdfbc0d882709d76924971c1f78377b017782..e2968e750dba62808053006d780a9ae79f924af9)
   BENCH_NAME=sql_planner
   BENCH_COMMAND=cargo bench --bench sql_planner
   BENCH_FILTER=
   BENCH_BRANCH_NAME=findepi_fix-partialord-for-scalarudf-dfb3ab
   Results will be posted here when complete
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org