You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@spark.apache.org by Jacek Laskowski <ja...@japila.pl> on 2021/08/11 14:41:28 UTC

TreeNode.exists?

Hi,

It's been a couple of times already when I ran into a code like the
following ([1]):

    val isCommand = plan.find {
      case _: Command | _: ParsedStatement | _: InsertIntoDir => true
      case _ => false
    }.isDefined

I think that this and the other places beg (scream?) for TreeNode.exists
that could do the simplest thing possible:

  find(f).isDefined

or even

  collectFirst(...).isDefined

It'd surely help a lot for people like myself reading the code. WDYT?

[1]
https://github.com/apache/spark/pull/33671/files#diff-4d16a733f8741de9a4b839ee7c356c3e9b439b4facc70018f5741da1e930c6a8R51-R54

Pozdrawiam,
Jacek Laskowski
----
https://about.me/JacekLaskowski
"The Internals Of" Online Books <https://books.japila.pl/>
Follow me on https://twitter.com/jaceklaskowski

<https://twitter.com/jaceklaskowski>

Re: TreeNode.exists?

Posted by Sean Owen <sr...@gmail.com>.
If this is repeated a bunch of places in the code, sure, a utility method
could be good.
I think .find(x).isDefined is even not optimal - .exists(x) is a little
easier and may be slightly faster?
If you find a chance for refactoring, sure open a minor PR.

On Wed, Aug 11, 2021 at 9:42 AM Jacek Laskowski <ja...@japila.pl> wrote:

> Hi,
>
> It's been a couple of times already when I ran into a code like the
> following ([1]):
>
>     val isCommand = plan.find {
>       case _: Command | _: ParsedStatement | _: InsertIntoDir => true
>       case _ => false
>     }.isDefined
>
> I think that this and the other places beg (scream?) for TreeNode.exists
> that could do the simplest thing possible:
>
>   find(f).isDefined
>
> or even
>
>   collectFirst(...).isDefined
>
> It'd surely help a lot for people like myself reading the code. WDYT?
>
> [1]
> https://github.com/apache/spark/pull/33671/files#diff-4d16a733f8741de9a4b839ee7c356c3e9b439b4facc70018f5741da1e930c6a8R51-R54
>
> Pozdrawiam,
> Jacek Laskowski
> ----
> https://about.me/JacekLaskowski
> "The Internals Of" Online Books <https://books.japila.pl/>
> Follow me on https://twitter.com/jaceklaskowski
>
> <https://twitter.com/jaceklaskowski>
>