Skip to content

[SPARK-25362][JavaAPI] Replace Spark Optional class with Java Optional - #22383

Closed
mmolimar wants to merge 7 commits into
apache:masterfrom
mmolimar:SPARK-25395
Closed

[SPARK-25362][JavaAPI] Replace Spark Optional class with Java Optional#22383
mmolimar wants to merge 7 commits into
apache:masterfrom
mmolimar:SPARK-25395

Conversation

@mmolimar

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Previous Spark versions didn't require Java 8 and an Optional Spark Java API had to be implemented to support optional values.

Since Spark 2.4 uses Java 8, the Optional Spark Java API should be removed so that Spark uses the original Java API.

How was this patch tested?

OptionalSuite class was removed to test Spark Java API Optional class (this class as well).
Notice that the get method in the Spark Java API Optional class throws a NullPointerException when the value is not set whereas the native Java API java.util.Optional throws a NoSuchElementException.

@vanzin

Copy link
Copy Markdown
Contributor

We can't do this until we decide whether the next version will be a major version or not. This breaks backwards compatibility. (See the bug I duplicated your bug to.)

@srowen

Copy link
Copy Markdown
Member

Yeah this is the right kind of change but needs to wait for now. Can you update the title?

@mmolimarmmolimar changed the title [SPARK-25395][JavaAPI] Removing Optional Spark Java API[SPARK-25395][JavaAPI] Replace Spark Optional class with Java OptionalSep 11, 2018
@mmolimar

Copy link
Copy Markdown
ContributorAuthor

Done @srowen

@srowensrowen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmolimar we can move forward with this now. Can you put SPARK-25395 in the title instead? that was the original JIRA.

new Tuple2<>(4, 'w')
));
List<Tuple2<Integer,Tuple2<Integer,Optional<Character>>>> joined =
List<Tuple2<Integer,Tuple2<Integer,Optional<Character>>>> joined =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmolimar Could you revert these whitespace changes?

@mmolimar

Copy link
Copy Markdown
ContributorAuthor

Updated @srowen
The PR title already contains SPARK-25395, is that what you're expecting or another PR?

@srowen

Copy link
Copy Markdown
Member

Oops, I mean SPARK-25362. SPARK-25395 was a duplicate.

@mmolimarmmolimar changed the title [SPARK-25395][JavaAPI] Replace Spark Optional class with Java Optional[SPARK-25362][JavaAPI] Replace Spark Optional class with Java OptionalOct 11, 2018
@mmolimar

Copy link
Copy Markdown
ContributorAuthor

No problem. Done ;-)

@SparkQA

Copy link
Copy Markdown

Test build #4368 has finished for PR 22383 at commit 054c79a.

  • This patch fails MiMa tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@srowen

Copy link
Copy Markdown
Member

Yeah, you'll have to add this to the 3.0 excludes section of project/MimaExcludes:

ProblemFilters.exclude[MissingClassProblem]("org.apache.spark.api.java.Optional")

Comment threadproject/MimaExcludes.scala
@SparkQA

Copy link
Copy Markdown

Test build #4376 has finished for PR 22383 at commit 6eaa3f1.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Comment threadproject/MimaExcludes.scala
Comment threadproject/MimaExcludes.scala
Comment threadproject/MimaExcludes.scala
@SparkQA

Copy link
Copy Markdown

Test build #4379 has finished for PR 22383 at commit f188243.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@srowen

Copy link
Copy Markdown
Member

Oh, hm:

Serialization stack:
- object not serializable (class: java.util.Optional, value: Optional[x])
- field (class: scala.Tuple2, name: _2, type: class java.lang.Object)
- object (class scala.Tuple2, (1,Optional[x]))
- field (class: scala.Tuple2, name: _2, type: class java.lang.Object)
- object (class scala.Tuple2, (1,(1,Optional[x])))
- element of array (index: 0)
- array (class [Lscala.Tuple2;, size 5)

So java.util.Optional isn't Serializable. Well, that may scuttle this whole idea. I think we're going to find a number of instances where Spark or user apps need to collect()Optional objects.

Unless someone has a bright idea I think we can't do this. Same reason I was unable to change Spark to use java.util.function interfaces -- lambdas aren't otherwise Serializable in Java!

@mmolimar

Copy link
Copy Markdown
ContributorAuthor

I agree @srowen.
What do you think about reusing the current implementation we already have, for example, in the guava lib instead of having that class in Spark?

@vanzin

Copy link
Copy Markdown
Contributor

Spark's class only reason to exist is so we do not use the Guava class, since everyone and their pet want to use a different version of Guava (and Spark shades it for that reason).

@srowen

Copy link
Copy Markdown
Member

Yeah, I think we just can't do this unfortunately. It was worth looking into.

@srowensrowen mentioned this pull request Oct 24, 2018
zifeif2 pushed a commit to zifeif2/spark that referenced this pull request Nov 22, 2025
Closesapache#22567Closesapache#18457Closesapache#21517Closesapache#21858Closesapache#22383Closesapache#19219Closesapache#22401Closesapache#22811Closesapache#20405Closesapache#21933Closesapache#22819 from srowen/ClosePRs.
Authored-by: Sean Owen <sean.owen@databricks.com>
Signed-off-by: Sean Owen <sean.owen@databricks.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@mmolimar@vanzin@srowen@SparkQA