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

Add adapter property to change table count limit #134

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

exaSR
Copy link
Collaborator

@exaSR exaSR commented Feb 22, 2023

  • new MAX_TABLE_COUNT property will fix Add adapter property for maximum number of tables #133
  • central function in JDBCAdapter to validate properties on create and setProperty events.
  • also prepares for an optimization in exasol-virtual-schema; by making some private members protected

- add tests for new table limit
- new methods JDBCAdapter::validateProperties and ::validateAdapterProperties
- added parameter validation tests
- add property documentation in README
@exaSR exaSR added the feature Product feature label Feb 23, 2023
@exaSR exaSR marked this pull request as ready for review February 23, 2023 12:39
doc/changes/changes_10.1.1.md Outdated Show resolved Hide resolved
doc/changes/changes_10.1.1.md Outdated Show resolved Hide resolved
Comment on lines +169 to +186
protected void validateAdapterProperties(AdapterProperties properties) throws PropertyValidationException {
if (properties.containsKey(JDBC_MAXTABLES_PROPERTY)) {
int result = 0;
try {
result = Integer.parseUnsignedInt(properties.get(JDBC_MAXTABLES_PROPERTY));
} catch (NumberFormatException e) {
// pass
}
if( result == 0 ) {
throw new PropertyValidationException(ExaError.messageBuilder("E-VSCJDBC-43") //
.message("Invalid parameter value.") //
.mitigation(
"The adapter property {{max_tables_property}}" + " if present, must be a positive integer.") //
.parameter("max_tables_property", JDBC_MAXTABLES_PROPERTY) //
.toString());
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
protected void validateAdapterProperties(AdapterProperties properties) throws PropertyValidationException {
if (properties.containsKey(JDBC_MAXTABLES_PROPERTY)) {
int result = 0;
try {
result = Integer.parseUnsignedInt(properties.get(JDBC_MAXTABLES_PROPERTY));
} catch (NumberFormatException e) {
// pass
}
if( result == 0 ) {
throw new PropertyValidationException(ExaError.messageBuilder("E-VSCJDBC-43") //
.message("Invalid parameter value.") //
.mitigation(
"The adapter property {{max_tables_property}}" + " if present, must be a positive integer.") //
.parameter("max_tables_property", JDBC_MAXTABLES_PROPERTY) //
.toString());
}
}
}
protected void validateAdapterProperties(final AdapterProperties properties) throws PropertyValidationException {
try {
validatePropertyValue(properties.get(JDBC_MAXTABLES_PROPERTY));
} catch (final IllegalArgumentException exception) {
throw new PropertyValidationException(ExaError.messageBuilder("E-VSCJDBC-43") //
.message("Invalid parameter value.") //
.mitigation("The adapter property {{max_tables_property}}" //
+ " if present, must be a positive integer.") //
.parameter("max_tables_property", JDBC_MAXTABLES_PROPERTY) //
.toString());
}
}
private void validatePropertyValue(final String string) {
if (string == null) {
return;
}
final int value = Integer.parseUnsignedInt(string);
if (value == 0) {
throw new IllegalArgumentException();
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm.... the method was meant to be extendable with more property checks -- (property, value and error message) should all be in one place.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was tempted to think the same - please feel free!

Comment on lines +188 to +194
// Validate properties for both the base adapter and the sql dialect
private void validateProperties(AdapterProperties properties) throws PropertyValidationException {
validateAdapterProperties(properties);
if( this.sqlDialectFactory != null ) {
this.sqlDialectFactory.createSqlDialect(null, properties).validateProperties();
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Dialect properties will be validated in method readMetaData() (two signatures).
But we could avoid code duplication in these methods:

Suggested change
// Validate properties for both the base adapter and the sql dialect
private void validateProperties(AdapterProperties properties) throws PropertyValidationException {
validateAdapterProperties(properties);
if( this.sqlDialectFactory != null ) {
this.sqlDialectFactory.createSqlDialect(null, properties).validateProperties();
}
}
private SqlDialect createDialect(final AdapterProperties properties, final ExaMetadata exasolMetadata)
throws PropertyValidationException {
final ConnectionFactory connectionFactory = new RemoteConnectionFactory(exasolMetadata, properties);
final SqlDialect dialect = createDialect(connectionFactory, properties);
dialect.validateProperties();
return dialect;
}

@@ -40,6 +42,7 @@ public CreateVirtualSchemaResponse createVirtualSchema(final ExaMetadata exasolM
final CreateVirtualSchemaRequest request) throws AdapterException {
logCreateVirtualSchemaRequestReceived(request);
final AdapterProperties properties = getPropertiesFromRequest(request);
validateProperties(properties);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
validateProperties(properties);
validateAdapterProperties(properties);

Comment on lines +150 to +152

validateProperties(mergedProperties);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Dialect properties will be validated in method readMetaData()

Suggested change
validateProperties(mergedProperties);
validateAdapterProperties(mergedProperties);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But that reopens the problem that you can ALTER your virtual schema without any errors, and it will only explode on refresh or use...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is your concern, that isRefreshingVirtualSchemaRequired() might return false and hence avoiding a call to readMetadata()?

@sonarcloud
Copy link

sonarcloud bot commented Feb 24, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

97.4% 97.4% Coverage
0.0% 0.0% Duplication

ckunki added a commit that referenced this pull request Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Product feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add adapter property for maximum number of tables
2 participants