Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EnumConfParser to SparkConfParser #10311

Merged
merged 3 commits into from
May 13, 2024
Merged

Conversation

huaxingao
Copy link
Contributor

Add EnumConfParser to SparkConfParser to parse Enum type properties

@github-actions github-actions bot added the spark label May 10, 2024
@huaxingao
Copy link
Contributor Author

cc @aokolnychyi

@@ -197,6 +201,34 @@ private Duration toDuration(String time) {
}
}

class EnumConfParser<T extends Enum<T>> extends ConfParser<EnumConfParser<T>, T> {
private T defaultValue;
private final Function<String, T> toEnum;
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: We usually have final vars before mutable. Can we switch the order of these two?

@@ -70,6 +70,10 @@ public DurationConfParser durationConf() {
return new DurationConfParser();
}

public <T extends Enum<T>> EnumConfParser<T> enumConf(Function<String, T> func) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: What about func -> toEnum?

.enumConf(PlanningMode::fromName)
.sessionConf(SparkSQLProperties.DATA_PLANNING_MODE)
.tableProperty(TableProperties.DATA_PLANNING_MODE)
.defaultValue(PlanningMode.fromName(TableProperties.PLANNING_MODE_DEFAULT))
Copy link
Contributor

@aokolnychyi aokolnychyi May 13, 2024

Choose a reason for hiding this comment

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

We can also offer defaultValue(String value) in addition to defaultValue(T value) and call toEnum(value) internally.

Copy link
Contributor

@aokolnychyi aokolnychyi left a comment

Choose a reason for hiding this comment

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

LGTM, pending tests.

@aokolnychyi aokolnychyi merged commit 02b1ff9 into apache:main May 13, 2024
31 checks passed
@huaxingao
Copy link
Contributor Author

Thanks @aokolnychyi @nastra

@huaxingao huaxingao deleted the enumConfParser branch May 13, 2024 21:44
sasankpagolu pushed a commit to sasankpagolu/iceberg that referenced this pull request Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants