You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ru...@apache.org on 2023/06/20 10:00:53 UTC

[spark] branch master updated: [SPARK-43944][SPARK-43942][SQL][FOLLOWUP] Directly leverage `UnresolvedFunction` for functions `startswith`/`endswith`/`contains`

This is an automated email from the ASF dual-hosted git repository.

ruifengz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 0865c0db923 [SPARK-43944][SPARK-43942][SQL][FOLLOWUP] Directly leverage `UnresolvedFunction` for functions `startswith`/`endswith`/`contains`
0865c0db923 is described below

commit 0865c0db923eadb840dd9af5834dc72ba19e43c4
Author: Ruifeng Zheng <ru...@apache.org>
AuthorDate: Tue Jun 20 18:00:33 2023 +0800

    [SPARK-43944][SPARK-43942][SQL][FOLLOWUP] Directly leverage `UnresolvedFunction` for functions `startswith`/`endswith`/`contains`
    
    ### What changes were proposed in this pull request?
    Directly leverage UnresolvedFunction for `startswith`/`endswith`/`contains`
    
    ### Why are the changes needed?
    to be more consistent with existing functions, like [ceil](https://github.com/apache/spark/blob/6b36a9368d6e97f7f1f94c4ca7f6ee76dcd0015f/sql/core/src/main/scala/org/apache/spark/sql/functions.scala#L2242-L2260), [floor](https://github.com/apache/spark/blob/6b36a9368d6e97f7f1f94c4ca7f6ee76dcd0015f/sql/core/src/main/scala/org/apache/spark/sql/functions.scala#L2397-L2416), [lpad](https://github.com/apache/spark/blob/6b36a9368d6e97f7f1f94c4ca7f6ee76dcd0015f/sql/core/src/main/scala/org/apa [...]
    
    ### Does this PR introduce _any_ user-facing change?
    no
    
    ### How was this patch tested?
    existing GA
    
    Closes #41669 from zhengruifeng/use_unresolved_func.
    
    Authored-by: Ruifeng Zheng <ru...@apache.org>
    Signed-off-by: Ruifeng Zheng <ru...@apache.org>
---
 .../main/scala/org/apache/spark/sql/functions.scala    | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala
index 68b81810da4..7c3f65e2495 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala
@@ -4051,10 +4051,8 @@ object functions {
    * @group string_funcs
    * @since 3.5.0
    */
-  def endswith(str: Column, suffix: Column): Column = {
-    // 'EndsWith' expression only supports StringType,
-    // use 'call_udf' to support both StringType and BinaryType.
-    call_udf("endswith", str, suffix)
+  def endswith(str: Column, suffix: Column): Column = withExpr {
+    UnresolvedFunction(Seq("endswith"), Seq(str.expr, suffix.expr), isDistinct = false)
   }
 
   /**
@@ -4065,10 +4063,8 @@ object functions {
    * @group string_funcs
    * @since 3.5.0
    */
-  def startswith(str: Column, prefix: Column): Column = {
-    // 'StartsWith' expression only supports StringType,
-    // use 'call_udf' to support both StringType and BinaryType.
-    call_udf("startswith", str, prefix)
+  def startswith(str: Column, prefix: Column): Column = withExpr {
+    UnresolvedFunction(Seq("startswith"), Seq(str.expr, prefix.expr), isDistinct = false)
   }
 
   /**
@@ -4145,10 +4141,8 @@ object functions {
    * @group string_funcs
    * @since 3.5.0
    */
-  def contains(left: Column, right: Column): Column = {
-    // 'Contains' expression only supports StringType
-    // use 'call_udf' to support both StringType and BinaryType.
-    call_udf("contains", left, right)
+  def contains(left: Column, right: Column): Column = withExpr {
+    UnresolvedFunction(Seq("contains"), Seq(left.expr, right.expr), isDistinct = false)
   }
 
   /**


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org