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 java class name validation #1084

Merged
merged 1 commit into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion core/src/main/java/feast/core/validators/Matchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Matchers {
private static Pattern BIGQUERY_TABLE_REF_REGEX =
Pattern.compile("[a-zA-Z0-9-]+[:]+[a-zA-Z0-9_]+[.]+[a-zA-Z0-9_]*");
private static Pattern CLASS_PATH_REGEX =
Pattern.compile("[a-zA-Z_$][a-zA-Z0-9_$]*(\\.[a-zA-Z_$][a-zA-Z0-9_$]*)");
Pattern.compile("[a-zA-Z_][a-zA-Z0-9_]*(\\.[a-zA-Z_][a-zA-Z0-9_]*)*$");
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-Z_][a-zA-Z0-9_]*$");
Expand Down
19 changes: 19 additions & 0 deletions core/src/test/java/feast/core/validators/MatchersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static feast.core.validators.Matchers.checkLowerSnakeCase;
import static feast.core.validators.Matchers.checkUpperSnakeCase;
import static feast.core.validators.Matchers.checkValidClassPath;

import com.google.common.base.Strings;
import org.junit.Rule;
Expand Down Expand Up @@ -70,4 +71,22 @@ public void checkLowerSnakeCaseShouldThrowIllegalArgumentExceptionWithFieldForIn
String in = "Invalid_feature name";
checkLowerSnakeCase(in, "feature");
}

@Test
public void checkValidClassPathSuccess() {
checkValidClassPath("com.example.foo", "FeatureTable");
checkValidClassPath("com.example", "FeatureTable");
}

@Test
public void checkValidClassPathEmpty() {
exception.expect(IllegalArgumentException.class);
checkValidClassPath("", "FeatureTable");
}

@Test
public void checkValidClassPathDigits() {
exception.expect(IllegalArgumentException.class);
checkValidClassPath("123", "FeatureTable");
}
}