Skip to content

Replace non-public Validators with AccumuloValidators#3370

Open
SethSmucker wants to merge 3 commits intointegrationfrom
task/replace-validators
Open

Replace non-public Validators with AccumuloValidators#3370
SethSmucker wants to merge 3 commits intointegrationfrom
task/replace-validators

Conversation

@SethSmucker
Copy link
Collaborator

Summary

  • Create AccumuloValidators utility class with NEW_TABLE_NAME, NEW_NAMESPACE_NAME, and EXISTING_NAMESPACE_NAME validators
  • Replace usages of non-public org.apache.accumulo.core.util.Validators in InMemoryNamespaceOperations and InMemoryTableOperations

Fixes #3357
Part of #2443

Create a local AccumuloValidators class to replace usage of non-public
org.apache.accumulo.core.util.Validators in InMemoryNamespaceOperations
and InMemoryTableOperations.
public final class AccumuloValidators {

private AccumuloValidators() {
// utility class
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would throw an UnsupportedOperationException here.

/**
* Validator for new table names. Checks that the name is non-null, non-empty, and contains only valid characters.
*/
public static final Validator NEW_TABLE_NAME = new Validator("new table name", name -> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This implementation does not fully cover the checks performed by the validator returned from Validators.NEW_TABLE_NAME. That validator also checks for:

  • Any table names beginning with a dot e.g. .tablename
  • A blank namespace (e.g. ' .tablename')
  • A table name with a namespace and blank table, (e.g. 'namespace. ')
  • a table name that is longer that 1024 characters

Please add those checks here as well.

It would also be nice if the exception thrown by the Validator is detailed about what the error is. The Validator class implemented by Accumulo is a good example of how to do this by checking the Optional returned from the validate() function for an error description.

/**
* Validator for new namespace names.
*/
public static final Validator NEW_NAMESPACE_NAME = new Validator("new namespace name", name -> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Both Validators.NEW_NAMESPACE_NAME and Validators.VALID_NAME_PATTERN also check whether the namespace is more than 1024 characters.

/**
* Validators for Accumulo table and namespace names. Replaces non-public class: {@code org.apache.accumulo.core.util.Validators}
*/
public final class AccumuloValidators {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would like to see some unit tests for this class.

/**
* A simple validator that checks a predicate and throws IllegalArgumentException if validation fails.
*/
public static class Validator {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is a utility class, I think it would make more sense for Validator to not be a nested class here. We may end up wanting to utilize the Validator class outside of AccumuloValidators down the line.

}

// Pattern for valid namespace/table name characters
private static final Pattern VALID_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_]+$");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is equivalent to the regex pattern \w+, which is simpler.

- Throw UnsupportedOperationException in private constructor
- Simplify regex to \w+
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.

Replace non-public Validators

2 participants