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

validate the regex pattern of database-name and table-name in table f… #526

Merged
merged 2 commits into from
Oct 28, 2021

Conversation

luoyuxia
Copy link
Contributor

…actory #491

Add validation check for the regex pattern of database-name and table-name in table factory to avoid exception during runtime

Map<String, String> properties = getAllOptions();
properties.put("table-name", "*_invalid_table");
} catch (Throwable t) {
String msg = String.format("The table-name is invalid: '%s'", "*_invalid_table");
Copy link
Member

Choose a reason for hiding this comment

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

We don't need String.format here because the string is deterministic.

@@ -231,4 +234,22 @@ private void validateFetchSize(int fetchSize) {
"The value of option '%s' must larger than 1, but is %d",
SCAN_SNAPSHOT_FETCH_SIZE.key(), fetchSize));
}

private void validateDatabaseName(String databaseName) {
Copy link
Member

@wuchong wuchong Oct 27, 2021

Choose a reason for hiding this comment

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

validateDatabaseName and validateTableName can share a same method, e.g.

    /**
     * Checks the given regular expression's syntax is valid.
     *
     * @param optionName the option name of the regex
     * @param regex The regular expression to be checked
     * @throws ValidationException If the expression's syntax is invalid
     */
    private void validateRegex(String optionName, String regex) {
        try {
            Pattern.compile(regex);
        } catch (Exception e) {
            throw new ValidationException(
                    String.format(
                            "The %s '%s' is not a valid regular expression", optionName, regex),
                    e);
        }
    }

Copy link
Member

@wuchong wuchong left a comment

Choose a reason for hiding this comment

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

LGTM

@wuchong wuchong merged commit 5cf940d into apache:master Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add validation check for the regex pattern of database-name and table-name in table factory
2 participants