Skip to content

Commit

Permalink
fix: Do not use regexp for BigQuerySchemaUtil#isProtoCompatible
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Nuyanzin <[email protected]>
  • Loading branch information
snuyanzin committed Aug 9, 2023
1 parent b85c562 commit d8acd18
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@

public class BigQuerySchemaUtil {

private static final String PROTO_COMPATIBLE_NAME_REGEXP = "[A-Za-z_][A-Za-z0-9_]*";
private static final String PLACEHOLDER_FILED_NAME_PREFIX = "col_";
private static final Pattern PROTO_COMPATIBLE_NAME_PATTERN =
Pattern.compile(PROTO_COMPATIBLE_NAME_REGEXP);

/**
* * Checks if the field name is compatible with proto field naming convention.
Expand All @@ -35,7 +32,25 @@ public class BigQuerySchemaUtil {
* false.
*/
public static boolean isProtoCompatible(String fieldName) {
return PROTO_COMPATIBLE_NAME_PATTERN.matcher(fieldName).matches();
int length = fieldName.length();
if (length < 1) {
return false;
}
char ch = fieldName.charAt(0);
if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_')) {
return false;
}
for (int i = 1; i < length; i++) {
ch = fieldName.charAt(i);
if (!((ch >= 'a' && ch <= 'z')
|| (ch >= 'A' && ch <= 'Z')
|| ch == '_'
|| (ch >= '0' && ch <= '9'))) {
return false;
}
}

return true;
}

/**
Expand Down

0 comments on commit d8acd18

Please sign in to comment.