Skip to content

Conversation

@yaooqinn
Copy link
Member

@yaooqinn yaooqinn commented Apr 24, 2025

What changes were proposed in this pull request?

Like what we‘ve improved in #50674.

This PR introduces TypedConfigBuilder for Java enums and leverages it for existing configurations that use enums as parameters.

Before this PR, we need to change them from Enumeration to string, string to Enumeration, back and forth... We also need to do upper-case transformation, .checkValues validation one by one.

After this PR, those steps are centralized.

Why are the changes needed?

Better support for java-enum-like configurations

Does this PR introduce any user-facing change?

no

How was this patch tested?

new tests

Was this patch authored or co-authored using generative AI tooling?

no

@yaooqinn
Copy link
Member Author

cc @dongjoon-hyun @cloud-fan @LuciferYang, thank you in advance


test("local mode, FIFO scheduler") {
val conf = new SparkConf().set(SCHEDULER_MODE, "FIFO")
val conf = new SparkConf().set(SCHEDULER_MODE.key, "FIFO")
Copy link
Member

Choose a reason for hiding this comment

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

Ur, is this a breaking change, @yaooqinn ?

Copy link
Member

Choose a reason for hiding this comment

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

It seems that I missed this in Scala version PR. I'm curious if we can avoid this kind of programing behavior change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @dongjoon-hyun,set with ConfigEntry is in private scope

"Invalid value for 'spark.sql.planChangeLog.level'. Valid values are " +
s"${VALID_LOG_LEVELS.mkString(", ")}.")
.createWithDefault("trace")
.enumConf(classOf[Level])
Copy link
Contributor

Choose a reason for hiding this comment

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

Level is from log4j?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's org.slf4j.event.Level

Copy link
Contributor

Choose a reason for hiding this comment

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

If slf4j is no longer used in the future, will there be a risk of introducing breaking changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi, there is no such risk since these changes are all targeting private APIs.

Assuming removing slf4j does break stuff here, it will break w/ or w/o this PR, see

https://github.com/apache/spark/pull/50691/files#diff-13c5b65678b327277c68d17910ae93629801af00117a0e3da007afd95b6c6764R5933

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it

s"${VALID_LOG_LEVELS.mkString(", ")}.")
.createWithDefault("trace")
.enumConf(classOf[Level])
.createWithDefault(Level.TRACE)
Copy link
Member

Choose a reason for hiding this comment

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

What do we get if we get this conf from PySpark (or SparkR)?

Copy link
Member Author

@yaooqinn yaooqinn Apr 25, 2025

Choose a reason for hiding this comment

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

set/get as string is still available due to the underlying T=>str/str=>T conversion

case Some(enum) => enum
case None =>
throw new IllegalArgumentException(
s"$key should be one of ${enumClass.getEnumConstants.mkString(", ")}, but was $s")
Copy link
Contributor

Choose a reason for hiding this comment

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

should we have an error condition for it?

Copy link
Contributor

Choose a reason for hiding this comment

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

ditto for the scala enum

Copy link
Member Author

Choose a reason for hiding this comment

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

We can have a separate PR for this to make all the condition-less errors uniform

@yaooqinn yaooqinn closed this in 8c808af Apr 25, 2025
@yaooqinn yaooqinn deleted the SPARK-51896 branch April 25, 2025 03:10
@yaooqinn
Copy link
Member Author

Merged to master, thank you @cloud-fan @dongjoon-hyun @HyukjinKwon @LuciferYang for the review

@dongjoon-hyun
Copy link
Member

+1, late LGTM.

@LuciferYang
Copy link
Contributor

late LGTM

yhuang-db pushed a commit to yhuang-db/spark that referenced this pull request Jun 9, 2025
### What changes were proposed in this pull request?

Like what we‘ve improved in apache#50674.

This PR introduces TypedConfigBuilder for Java enums and leverages it for existing configurations that use enums as parameters.

Before this PR, we need to change them from Enumeration to string, string to Enumeration, back and forth... We also need to do upper-case transformation, .checkValues validation one by one.

After this PR, those steps are centralized.

### Why are the changes needed?

Better support for java-enum-like configurations

### Does this PR introduce _any_ user-facing change?
no

### How was this patch tested?
new tests

### Was this patch authored or co-authored using generative AI tooling?
no

Closes apache#50691 from yaooqinn/SPARK-51896.

Authored-by: Kent Yao <[email protected]>
Signed-off-by: Kent Yao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants