You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/02/07 12:27:25 UTC

[GitHub] [spark] ulysses-you opened a new pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

ulysses-you opened a new pull request #31509:
URL: https://github.com/apache/spark/pull/31509


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   Add a new function `DelegateFunction`.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   Delegate is just like a big box that can include some other expressions. It will execute all of children and return the last child result as its result.
   
    
   
   The origin idea is from debug. Debug SQL is hard since SQL is always quite long and complex. This new function can help debug with inject some help functions, e.g., `println, sleep, raise_error`.
   
    
   
   Two usage examples:
   ```sql
   -- 1
   -- raw sql
   INSERT INTO TABLE t1
   SELECT coalesce(c1, c2) as c FROM t2
    
   -- print the column data
   INSERT INTO TABLE t1
   SELECT delegate(
   java_method('scala.Console', 'println', concat('c1: ', c1, ', c2: ', c2)),
   coalesce(c1, c2)
   ) as c FROM t2
    
   -- 2
   -- raw sql
   SELECT if(spark_partition_id() = 1, c1, raise_error('test error')) FROM t2
    
   -- add a sleep time before throw error
   SELECT if(spark_partition_id() = 1, c1, delegate(
   java_method('java.lang.Thread', 'sleep', 3000l),
   raise_error('test error')
   )) FROM t2
   ``` 
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   Yes, a new function.
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   Add test.


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] ulysses-you commented on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-775963123


   thankd you @rednaxelafx  your sharing is always good enough.
   
   My origin requirement is finding a way which behavior is similar with `BlockExpression`, the name `delegate` is just a alias. I see what you worried about, it may make plan and expression fuzzy that's we don't expect.
   
   "local alias" to me more like a udf but we build it in SQL directly, not sure it's accpted since it introduces some complex. Besides, the idea enhancements the Catalyst sounds excited to me, I'd like to do this. Maybe I need sometime to think about 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.

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



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


[GitHub] [spark] AmplabJenkins commented on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-774690695


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/39573/
   


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] SparkQA removed a comment on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-774672919


   **[Test build #134990 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134990/testReport)** for PR 31509 at commit [`41bb006`](https://github.com/apache/spark/commit/41bb006f3c2f6d1cdf14f3a6903cb1818319c4d9).


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] github-actions[bot] commented on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-845587359


   We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
   If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!


-- 
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.

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



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


[GitHub] [spark] ulysses-you commented on a change in pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #31509:
URL: https://github.com/apache/spark/pull/31509#discussion_r571833216



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala
##########
@@ -269,3 +269,62 @@ case class TypeOf(child: Expression) extends UnaryExpression {
     defineCodeGen(ctx, ev, _ => s"""UTF8String.fromString(${child.dataType.catalogString})""")
   }
 }
+
+@ExpressionDescription(
+  usage = """_FUNC_(expr) - Execute all children and return the last child result.""",
+  examples = """
+    Examples:
+      > SELECT _FUNC_(1, 2);
+       2
+      > SELECT _FUNC_(1 + 2, 3 + 4);
+       7
+  """,
+  since = "3.2.0",
+  group = "misc_funcs")
+case class DelegateFunction(children: Seq[Expression]) extends Expression {
+  require(children.nonEmpty, s"$prettyName function requires children is not empty.")
+
+  private lazy val lastChild = children.last
+
+  override lazy val deterministic: Boolean = children.forall(_.deterministic)
+  override lazy val resolved: Boolean = children.forall(_.resolved)
+  override def foldable: Boolean = children.forall(_.foldable)
+  override def nullable: Boolean = lastChild.nullable
+  override def dataType: DataType = lastChild.dataType
+
+  override def eval(input: InternalRow): Any = {
+    var result: Any = null
+    children.foreach { child =>
+      result = child.eval(input)
+    }
+    result

Review comment:
       Not sure what do you mean `same child` ?  This function just execute child one by one.




----------------------------------------------------------------
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.

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



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


[GitHub] [spark] github-actions[bot] closed pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed pull request #31509:
URL: https://github.com/apache/spark/pull/31509


   


-- 
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.

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



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-774690695


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/39573/
   


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] SparkQA commented on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-774716664


   **[Test build #134990 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134990/testReport)** for PR 31509 at commit [`41bb006`](https://github.com/apache/spark/commit/41bb006f3c2f6d1cdf14f3a6903cb1818319c4d9).
    * This patch passes all tests.
    * This patch merges cleanly.
    * This patch adds the following public classes _(experimental)_:
     * `case class DelegateFunction(children: Seq[Expression]) extends Expression `


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] AmplabJenkins commented on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-774724774


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/134990/
   


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-774724774


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/134990/
   


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] SparkQA commented on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-774682854


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/39573/
   


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] rednaxelafx commented on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
rednaxelafx commented on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-775610985


   Just some random thoughts:
   
   This kind of functionality is certain useful for debugging and could come in handy for writing shorthands, but I have mixed feelings about exposing it on the SQL language extension level.
   i.e. I'd love to see this if we're designing a new language from scratch, but I'm not so sure about adding it to SQL.
   
   - In terms of the IR (intermediate representation) node, it's very common in programming languages or their compilers to feature this kind of expression type. Some example names are `BlockExpression` (e.g. in [System.Linq.Expressions.BlockExpression](https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.blockexpression)), or C's [Comma expression](https://en.wikipedia.org/wiki/Comma_operator), or just Seq / Sequence expression etc. I haven't seen the term "delegate expression" used this way, though.
   - While this comes in really handy, it encourages two things:
     - side effects: yes you do want the side effects for debugging, but for regular SQL queries you should probably avoid side effects to have less surprises
     - duplicate notion of projection: the `DelegateExpression` being proposed here is really just a twp-level nested projection embedded on the expression level: 1 level for evaluating all the children expressions, and another level to discard all but the last expression's result. This duplication is somewhat annoying, as is the case for some of Spark's higher-ordered functions -- they duplicate some semantics from the plan level to the expression, but the optimizations were not updated to recognized them efficiently.
   - If we really want to make the most out of the opportunity of adding a new expression infrastructure, we might want to also allow this kind of "block expression" to support "local alias", or more commonly known as just "local variables" or "local bindings" in a programming language. Again, this is something that already exists in the `Project` plan level operator, but it's just clumsy to use in this kind of context.
   
   If we're talking about making some enhancements in the internals of Catalyst and adding a more flexible, more powerful way of representing projections, both on the plan level and on the expression level, that'd be super awesome and I'd help push it forward.
   Otherwise adding a one-off expression as proposed in this PR here doesn't feel very clean. At least I don't feel like the proposal as-is should be a regular built-in function, but maybe just something that's on the side for aiding debugging.
   
   Just my two cents


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] rednaxelafx edited a comment on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
rednaxelafx edited a comment on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-775610985


   Just some random thoughts:
   
   This kind of functionality is certain useful for debugging and could come in handy for writing shorthands, but I have mixed feelings about exposing it on the SQL language extension level.
   i.e. I'd love to see this if we're designing a new language from scratch, but I'm not so sure about adding it to SQL.
   
   - In terms of the IR (intermediate representation) node, it's very common in programming languages or their compilers to feature this kind of expression type. Some example names are `BlockExpression` (e.g. in [System.Linq.Expressions.BlockExpression](https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.blockexpression)), or C's [Comma expression](https://en.wikipedia.org/wiki/Comma_operator), or just Seq / Sequence expression etc. I haven't seen the term "delegate expression" used this way, though.
   - While this comes in really handy, it encourages two things:
     - side effects: yes you do want the side effects for debugging, but for regular SQL queries you should probably avoid side effects to have less surprises
     - duplicate notion of projection: the `DelegateExpression` being proposed here is really just a 2-level nested projection embedded on the expression level: 1 level for evaluating all the children expressions, and another level to discard all but the last expression's result. This duplication is somewhat annoying, as is the case for some of Spark's higher-ordered functions -- they duplicate some semantics from the plan level to the expression level, but the optimizations were not updated to recognized them efficiently.
   - If we really want to make the most out of the opportunity of adding a new expression infrastructure, we might want to also allow this kind of "block expression" to support "local alias", or more commonly known as just "local variables" or "local bindings" in a programming language. Again, this is something that already exists in the `Project` plan level operator, but it's just clumsy to use in this kind of context.
   
   If we're talking about making some enhancements in the internals of Catalyst and adding a more flexible, more powerful way of representing projections, both on the plan level and on the expression level, that'd be super awesome and I'd help push it forward.
   Otherwise adding a one-off expression as proposed in this PR here doesn't feel very clean. At least I don't feel like the proposal as-is should be a regular built-in function, but maybe just something that's on the side for aiding debugging.
   
   Just my two cents


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] SparkQA commented on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-774680130


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/39573/
   


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] ulysses-you commented on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-774808759


   Seems such function is not exists in other database, would you mind to take a look at this idea ? @maropu @cloud-fan @dongjoon-hyun @HyukjinKwon 


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] rednaxelafx edited a comment on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
rednaxelafx edited a comment on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-775610985


   Just some random thoughts:
   
   This kind of functionality is certain useful for debugging and could come in handy for writing shorthands, but I have mixed feelings about exposing it on the SQL language extension level.
   i.e. I'd love to see this if we're designing a new language from scratch, but I'm not so sure about adding it to SQL.
   
   - In terms of the IR (intermediate representation) node, it's very common in programming languages or their compilers to feature this kind of expression type. Some example names are `BlockExpression` (e.g. in [System.Linq.Expressions.BlockExpression](https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.blockexpression)), or C's [Comma expression](https://en.wikipedia.org/wiki/Comma_operator), or just Seq / Sequence expression etc. I haven't seen the term "delegate expression" used this way, though.
   - While this comes in really handy, it encourages two things:
     - side effects: yes you do want the side effects for debugging, but for regular SQL queries you should probably avoid side effects to have less surprises
     - duplicate notion of projection: the `DelegateExpression` being proposed here is really just a 2-level nested projection embedded on the expression level: 1 level for evaluating all the children expressions, and another level to discard all but the last expression's result. This duplication is somewhat annoying, as is the case for some of Spark's higher-ordered functions -- they duplicate some semantics from the plan level to the expression, but the optimizations were not updated to recognized them efficiently.
   - If we really want to make the most out of the opportunity of adding a new expression infrastructure, we might want to also allow this kind of "block expression" to support "local alias", or more commonly known as just "local variables" or "local bindings" in a programming language. Again, this is something that already exists in the `Project` plan level operator, but it's just clumsy to use in this kind of context.
   
   If we're talking about making some enhancements in the internals of Catalyst and adding a more flexible, more powerful way of representing projections, both on the plan level and on the expression level, that'd be super awesome and I'd help push it forward.
   Otherwise adding a one-off expression as proposed in this PR here doesn't feel very clean. At least I don't feel like the proposal as-is should be a regular built-in function, but maybe just something that's on the side for aiding debugging.
   
   Just my two cents


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] SparkQA commented on pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31509:
URL: https://github.com/apache/spark/pull/31509#issuecomment-774672919


   **[Test build #134990 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134990/testReport)** for PR 31509 at commit [`41bb006`](https://github.com/apache/spark/commit/41bb006f3c2f6d1cdf14f3a6903cb1818319c4d9).


----------------------------------------------------------------
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.

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



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


[GitHub] [spark] AngersZhuuuu commented on a change in pull request #31509: [SPARK-34396][SQL] Add a new build-in function delegate

Posted by GitBox <gi...@apache.org>.
AngersZhuuuu commented on a change in pull request #31509:
URL: https://github.com/apache/spark/pull/31509#discussion_r571802245



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala
##########
@@ -269,3 +269,62 @@ case class TypeOf(child: Expression) extends UnaryExpression {
     defineCodeGen(ctx, ev, _ => s"""UTF8String.fromString(${child.dataType.catalogString})""")
   }
 }
+
+@ExpressionDescription(
+  usage = """_FUNC_(expr) - Execute all children and return the last child result.""",
+  examples = """
+    Examples:
+      > SELECT _FUNC_(1, 2);
+       2
+      > SELECT _FUNC_(1 + 2, 3 + 4);
+       7
+  """,
+  since = "3.2.0",
+  group = "misc_funcs")
+case class DelegateFunction(children: Seq[Expression]) extends Expression {
+  require(children.nonEmpty, s"$prettyName function requires children is not empty.")
+
+  private lazy val lastChild = children.last
+
+  override lazy val deterministic: Boolean = children.forall(_.deterministic)
+  override lazy val resolved: Boolean = children.forall(_.resolved)
+  override def foldable: Boolean = children.forall(_.foldable)
+  override def nullable: Boolean = lastChild.nullable
+  override def dataType: DataType = lastChild.dataType
+
+  override def eval(input: InternalRow): Any = {
+    var result: Any = null
+    children.foreach { child =>
+      result = child.eval(input)
+    }
+    result

Review comment:
       Hmmm how about add a result map and avoid re-compute same child?




----------------------------------------------------------------
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.

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



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