Skip to content

Commit e478d39

Browse files
committed
Fix invalid characters for project creation
1 parent c8db3db commit e478d39

4 files changed

Lines changed: 30 additions & 7 deletions

File tree

core/src/main/java/feast/core/validators/FeatureSetValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public static void validateSpec(FeatureSet featureSet) {
4444
throw new IllegalArgumentException("Feature set label keys must not be empty");
4545
}
4646

47-
checkValidCharacters(featureSet.getSpec().getProject(), "project");
48-
checkValidCharacters(featureSet.getSpec().getName(), "name");
47+
checkValidCharacters(featureSet.getSpec().getProject(), "project::name");
48+
checkValidCharacters(featureSet.getSpec().getName(), "featureset::name");
4949
checkUniqueColumns(
5050
featureSet.getSpec().getEntitiesList(), featureSet.getSpec().getFeaturesList());
5151
checkReservedColumns(featureSet.getSpec().getFeaturesList());

core/src/main/java/feast/core/validators/Matchers.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public class Matchers {
2222

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

29-
private static String ERROR_MESSAGE_TEMPLATE = "invalid value for field %s: %s";
29+
private static String ERROR_MESSAGE_TEMPLATE = "invalid value for %s: %s";
3030

3131
public static void checkUpperSnakeCase(String input, String fieldName)
3232
throws IllegalArgumentException {
@@ -57,7 +57,7 @@ public static void checkValidCharacters(String input, String fieldName)
5757
String.format(
5858
ERROR_MESSAGE_TEMPLATE,
5959
fieldName,
60-
"argument must only contain alphanumeric characters, dashes and underscores."));
60+
"argument must only contain alphanumeric characters and underscores."));
6161
}
6262
}
6363

core/src/test/java/feast/core/service/SpecServiceIT.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,29 @@ public void shouldThrowExceptionGivenReservedFeatureName() {
228228
reservedNamesString, "event_timestamp")));
229229
}
230230

231+
@Test
232+
public void shouldThrowExceptionGivenFeatureSetWithDash() {
233+
StatusRuntimeException exc =
234+
assertThrows(
235+
StatusRuntimeException.class,
236+
() ->
237+
apiClient.simpleApplyFeatureSet(
238+
DataGenerator.createFeatureSet(
239+
DataGenerator.getDefaultSource(),
240+
"project",
241+
"dash-name",
242+
ImmutableMap.of("entity", ValueProto.ValueType.Enum.STRING),
243+
ImmutableMap.of("test_string", ValueProto.ValueType.Enum.STRING))));
244+
245+
assertThat(
246+
exc.getMessage(),
247+
equalTo(
248+
String.format(
249+
"INTERNAL: invalid value for %s: %s",
250+
"featureset::name",
251+
"argument must only contain alphanumeric characters and underscores.")));
252+
}
253+
231254
@Test
232255
public void shouldReturnFeatureSetIfFeatureSetHasNotChanged() {
233256
FeatureSetProto.FeatureSet featureSet = apiClient.getFeatureSet("default", "fs1");

core/src/test/java/feast/core/validators/MatchersTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void checkUpperSnakeCaseShouldThrowIllegalArgumentExceptionWithFieldForIn
4444
exception.expect(IllegalArgumentException.class);
4545
exception.expectMessage(
4646
Strings.lenientFormat(
47-
"invalid value for field %s: %s",
47+
"invalid value for %s: %s",
4848
"someField",
4949
"argument must be in upper snake case, and cannot include any special characters."));
5050
String in = "redis";
@@ -62,7 +62,7 @@ public void checkLowerSnakeCaseShouldThrowIllegalArgumentExceptionWithFieldForIn
6262
exception.expect(IllegalArgumentException.class);
6363
exception.expectMessage(
6464
Strings.lenientFormat(
65-
"invalid value for field %s: %s",
65+
"invalid value for %s: %s",
6666
"someField",
6767
"argument must be in lower snake case, and cannot include any special characters."));
6868
String in = "Invalid_feature name";

0 commit comments

Comments
 (0)