-
Notifications
You must be signed in to change notification settings - Fork 487
Improve Property Types #6487
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
base: main
Are you sure you want to change the base?
Improve Property Types #6487
Changes from all commits
a702db0
a44536b
f9d82be
a77bedb
b993313
c499e66
335922d
d472f41
ec0c0ae
2ed6245
cb9f762
fe164c9
661d99b
d51430c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,8 @@ | |
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.util.Arrays; | ||
| import java.util.HashSet; | ||
| import java.util.Objects; | ||
|
|
@@ -155,7 +157,7 @@ public enum PropertyType { | |
| BOOLEAN("boolean", in(false, null, "true", "false"), | ||
| "Has a value of either 'true' or 'false' (case-insensitive)"), | ||
|
|
||
| URI("uri", x -> true, "A valid URI"), | ||
| URI("uri", new ValidUri(), "A valid URI"), | ||
|
|
||
| FILENAME_EXT("file name extension", in(true, RFile.EXTENSION), | ||
| "One of the currently supported filename extensions for storing table data files. " | ||
|
|
@@ -247,12 +249,35 @@ public boolean test(String value) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Validate that the provided string can be used to create a valid URI. | ||
| */ | ||
| private static class ValidUri implements Predicate<String> { | ||
| private static final Logger log = LoggerFactory.getLogger(ValidUri.class); | ||
|
|
||
| @Override | ||
| public boolean test(String uri) { | ||
| if (uri == null) { | ||
| return true; | ||
| } | ||
| try { | ||
| new URI(uri); | ||
| return true; | ||
| } catch (URISyntaxException e) { | ||
| log.error("provided uri string is not valid"); | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static class ValidVolumes implements Predicate<String> { | ||
| private static final Logger log = LoggerFactory.getLogger(ValidVolumes.class); | ||
|
|
||
| @Override | ||
| public boolean test(String volumes) { | ||
| if (volumes == null) { | ||
| return true; | ||
| } else if (volumes.isEmpty()) { | ||
| return false; | ||
| } | ||
| try { | ||
|
|
@@ -306,7 +331,6 @@ public boolean test(String type) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private static final Pattern SUFFIX_REGEX = Pattern.compile("\\D*$"); // match non-digits at end | ||
|
|
@@ -413,14 +437,8 @@ public Matches(final Pattern pattern) { | |
|
|
||
| @Override | ||
| public boolean test(final String input) { | ||
| // TODO when the input is null, it just means that the property wasn't set | ||
| // we can add checks for not null for required properties with | ||
| // Predicates.and(Predicates.notNull(), ...), | ||
| // or we can stop assuming that null is always okay for a Matches predicate, and do that | ||
| // explicitly with Predicates.or(Predicates.isNull(), ...) | ||
|
Comment on lines
-416
to
-420
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment that was removed suggests that we should not check If we leave the I'm not sure if we've done either, or which would be easier to do if we haven't.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but the null is still being allowed here in the property type validation. That's kind of my point. We are allowing all nulls to pass through here, and then check them later. The comment that was removed was suggesting that we could do this better by disallowing nulls here. Consider the following, which roughly represents what we have today: // implied validation from the type
MY_PROP_ENUM("key", PropertyType.MyType, "description");The problem here is that Consider this alternative instead: // explicit validation from the type, with an optional nullable; type no longer has to allow nulls
// alternatively, the type always allows nulls, but we explicitly say that it's not null in the explicit validator
MY_PROP_ENUM("key", PropertyType.MyType, PropertyType.MyType::isValidFormat, "description");
MY_PROP_ENUM2("key2", PropertyType.MyType2, Predicate.isNull().or(PropertyType.MyType::isValidFormat), "description");Alternatively: // stored the required bit with the property
MY_PROP_ENUM("key", PropertyType.MyType, /* required = */ true, "description");
// modify the PropertyType.isValidFormat()
public boolean isValidFormat(String string, boolean required) {
// ensure non-null in here before passing to the type-specific predicate to test the non-null format
}I think the implication here is that the required set needs to be removed, and replaced with either explicit per-property validation, or an extra per-property "required" boolean parameter to track which properties allow null/empty string. |
||
| return input == null || pattern.matcher(input).matches(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public static class PortRange extends Matches { | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.