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

Fix invalid characters for project, featureset, entity and features creation #976

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public static void validateSpec(FeatureSet featureSet) {
throw new IllegalArgumentException("Feature set label keys must not be empty");
}

checkValidCharacters(featureSet.getSpec().getProject(), "project");
checkValidCharacters(featureSet.getSpec().getName(), "name");
checkValidCharacters(featureSet.getSpec().getProject(), "project::name");
checkValidCharacters(featureSet.getSpec().getName(), "featureset::name");
Copy link
Member

Choose a reason for hiding this comment

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

Would it make more sense to have a new argument like resource and field instead of ::

Copy link
Member Author

Choose a reason for hiding this comment

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

I added resource. I think it's clearer to show what they inputted as well, so I replaced field with the actual input itself in the error message.

checkUniqueColumns(
featureSet.getSpec().getEntitiesList(), featureSet.getSpec().getFeaturesList());
checkReservedColumns(featureSet.getSpec().getFeaturesList());
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/feast/core/validators/Matchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class Matchers {

private static Pattern UPPER_SNAKE_CASE_REGEX = Pattern.compile("^[A-Z0-9]+(_[A-Z0-9]+)*$");
private static Pattern LOWER_SNAKE_CASE_REGEX = Pattern.compile("^[a-z0-9]+(_[a-z0-9]+)*$");
private static Pattern VALID_CHARACTERS_REGEX = Pattern.compile("^[a-zA-Z0-9\\-_]*$");
private static Pattern VALID_CHARACTERS_REGEX = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$");
private static Pattern VALID_CHARACTERS_REGEX_WITH_ASTERISK_WILDCARD =
Pattern.compile("^[a-zA-Z0-9\\-_*]*$");

private static String ERROR_MESSAGE_TEMPLATE = "invalid value for field %s: %s";
private static String ERROR_MESSAGE_TEMPLATE = "invalid value for %s: %s";

public static void checkUpperSnakeCase(String input, String fieldName)
throws IllegalArgumentException {
Expand Down Expand Up @@ -57,7 +57,7 @@ public static void checkValidCharacters(String input, String fieldName)
String.format(
ERROR_MESSAGE_TEMPLATE,
fieldName,
"argument must only contain alphanumeric characters, dashes and underscores."));
"argument must only contain alphanumeric characters and underscores."));
}
}

Expand Down
23 changes: 23 additions & 0 deletions core/src/test/java/feast/core/service/SpecServiceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,29 @@ public void shouldThrowExceptionGivenReservedFeatureName() {
reservedNamesString, "event_timestamp")));
}

@Test
public void shouldThrowExceptionGivenFeatureSetWithDash() {
StatusRuntimeException exc =
assertThrows(
StatusRuntimeException.class,
() ->
apiClient.simpleApplyFeatureSet(
DataGenerator.createFeatureSet(
DataGenerator.getDefaultSource(),
"project",
"dash-name",
ImmutableMap.of("entity", ValueProto.ValueType.Enum.STRING),
ImmutableMap.of("test_string", ValueProto.ValueType.Enum.STRING))));

assertThat(
exc.getMessage(),
equalTo(
String.format(
"INTERNAL: invalid value for %s: %s",
"featureset::name",
"argument must only contain alphanumeric characters and underscores.")));
}

@Test
public void shouldReturnFeatureSetIfFeatureSetHasNotChanged() {
FeatureSetProto.FeatureSet featureSet = apiClient.getFeatureSet("default", "fs1");
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/feast/core/validators/MatchersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void checkUpperSnakeCaseShouldThrowIllegalArgumentExceptionWithFieldForIn
exception.expect(IllegalArgumentException.class);
exception.expectMessage(
Strings.lenientFormat(
"invalid value for field %s: %s",
"invalid value for %s: %s",
"someField",
"argument must be in upper snake case, and cannot include any special characters."));
String in = "redis";
Expand All @@ -62,7 +62,7 @@ public void checkLowerSnakeCaseShouldThrowIllegalArgumentExceptionWithFieldForIn
exception.expect(IllegalArgumentException.class);
exception.expectMessage(
Strings.lenientFormat(
"invalid value for field %s: %s",
"invalid value for %s: %s",
"someField",
"argument must be in lower snake case, and cannot include any special characters."));
String in = "Invalid_feature name";
Expand Down