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

Spark 3.5: Add validation to SparkConfParser #10315

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aokolnychyi
Copy link
Contributor

@aokolnychyi aokolnychyi commented May 11, 2024

This PR adds a way to validate parsed configs in SparkConfParser. It is intended for the following use:

public int parquetBatchSize() {
  return confParser
      .intConf()
      ...
      .check(value -> value > 0, "Parquet batch size must be > 0")
      .parse();
}

@github-actions github-actions bot added the spark label May 11, 2024
return self();
}

protected T parseAndCheck(Function<String, T> conversion, T defaultValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible for ProcedureInput to utilize this method as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one depends on some state, I'll have to take a look ProcedureInput.

@aokolnychyi aokolnychyi force-pushed the spark-conf-parsing-validation branch from f9d49e0 to c774a63 Compare May 17, 2024 17:04
}

protected T parseOptionalAndCheck(Function<String, T> conversion, T defaultValue) {
T value = parse(conversion, defaultValue);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need a new method? In the existing parse() methods, if check != null can be the case to trigger the check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean what's the benefit of having parseOptionalAndCheck if we can simply call check in children?

Copy link
Collaborator

@szehon-ho szehon-ho May 17, 2024

Choose a reason for hiding this comment

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

Oh I meant, why not just add in existing base ConfParser.parse(Function<String, T> conversion, T defaultValue) method

if (check != null) {
   check(value);
}

}
}

abstract class ConfParser<ThisT, T> {
private final List<String> optionNames = Lists.newArrayList();
private String sessionConfName;
private String tablePropertyName;
private Predicate<T> check;
Copy link
Contributor

@jerqi jerqi May 22, 2024

Choose a reason for hiding this comment

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

Maybe validator or checker is a better name.


protected T parseOptionalAndCheck(Function<String, T> conversion, T defaultValue) {
T value = parse(conversion, defaultValue);
check(value);
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 skip the check if this value is null for optional config?

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.

None yet

4 participants