Skip to content

Commit

Permalink
deprecate FROM_RESULT_SET value
Browse files Browse the repository at this point in the history
  • Loading branch information
pj-spoelders committed Dec 21, 2023
1 parent 0db2922 commit c52ca66
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ public String rewrite(final SqlStatement statement, final List<DataType> selectL
properties);
final String connectionDefinition = this.connectionDefinitionBuilder
.buildConnectionDefinition(properties, exaConnectionInformation);
if (calculateDatatypes(selectListDataTypes, properties)) {
final String importStatement = generateImportStatement(connectionDefinition,
selectListDataTypes, pushdownQuery);

if (DataTypeDetection.from(properties).getStrategy() == Strategy.EXASOL_CALCULATED) {
String importStatement;
if (!selectListDataTypes.isEmpty()) {
importStatement = generateImportStatement(connectionDefinition, selectListDataTypes,
pushdownQuery);
} else {
importStatement = generateImportStatement(connectionDefinition, pushdownQuery);
}
LOGGER.finer(() -> "Import push-down statement:\n" + importStatement);
return importStatement;
} else {
Expand All @@ -64,12 +70,6 @@ public String rewrite(final SqlStatement statement, final List<DataType> selectL
}
}

private boolean calculateDatatypes(final List<DataType> selectListDataTypes,
final AdapterProperties properties) {
return (DataTypeDetection.from(properties).getStrategy() == Strategy.EXASOL_CALCULATED)
&& !selectListDataTypes.isEmpty();
}

private String createPushdownQuery(final SqlStatement statement, final AdapterProperties properties)
throws AdapterException {
final SqlGenerationContext context = new SqlGenerationContext(properties.getCatalogName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public static PropertyValidator getValidator() {
}

private static void validatePropertyValue(final String value) throws PropertyValidationException {
if (value == Strategy.FROM_RESULT_SET.toString()) {
throw new PropertyValidationException(ExaError.messageBuilder("E-VSCJDBC-47")
.message("Property `IMPORT_DATA_TYPES` value 'FROM_RESULT_SET' is no longer supported.")
.mitigation(
"Please remove the `IMPORT_DATA_TYPES` property from the virtual schema so the default value 'EXASOL_CALCULATED' is used.")
.toString());
}
if (!strategies(Collectors.toSet()).contains(value)) {
throw new PropertyValidationException(ExaError.messageBuilder("E-VSCJDBC-41")
.message("Invalid value {{value}} for property {{property}}.", value, STRATEGY_PROPERTY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.sql.SQLException;
import java.util.*;
Expand All @@ -16,33 +17,50 @@
import com.exasol.adapter.dialects.dummy.DummySqlDialect;
import com.exasol.adapter.jdbc.BaseRemoteMetadataReader;
import com.exasol.adapter.metadata.DataType;
import com.exasol.adapter.properties.DataTypeDetection;
import com.exasol.adapter.sql.TestSqlStatementFactory;

class ImportFromJDBCQueryRewriterTest extends AbstractQueryRewriterTestBase {
private static final List<DataType> EMPTY_SELECT_LIST_DATA_TYPES = Collections.emptyList();

@Test
void rewriteWithJdbcConnection() throws AdapterException, SQLException {
final AdapterProperties properties = new AdapterProperties(Map.of("CONNECTION_NAME", CONNECTION_NAME));
final SqlDialect dialect = new DummySqlDialect(null, properties);
final BaseRemoteMetadataReader metadataReader = new BaseRemoteMetadataReader(mockConnection(), properties);
final QueryRewriter queryRewriter = new ImportFromJDBCQueryRewriter(dialect, metadataReader);
assertThat(
queryRewriter.rewrite(TestSqlStatementFactory.createSelectOneFromDual(), EMPTY_SELECT_LIST_DATA_TYPES,
EXA_METADATA, properties),
equalTo("IMPORT FROM JDBC AT " + CONNECTION_NAME + " STATEMENT 'SELECT 1 FROM \"DUAL\"'"));
}

@Test
void rewriteWithCustomConnectionDefinitionBuilder() throws AdapterException, SQLException {
final SqlDialect dialect = new DummySqlDialect(null, AdapterProperties.emptyProperties());
final BaseRemoteMetadataReader metadataReader = new BaseRemoteMetadataReader(mockConnection(),
AdapterProperties.emptyProperties());
final QueryRewriter queryRewriter = new ImportFromJDBCQueryRewriter(dialect, metadataReader,
new DummyConnectionDefinitionBuilder());
assertThat(
queryRewriter.rewrite(TestSqlStatementFactory.createSelectOneFromDual(), EMPTY_SELECT_LIST_DATA_TYPES,
EXA_METADATA, AdapterProperties.emptyProperties()),
equalTo("IMPORT FROM JDBC MY DUMMY DEFINITION BUILDER STATEMENT 'SELECT 1 FROM \"DUAL\"'"));
}
private static final List<DataType> EMPTY_SELECT_LIST_DATA_TYPES = Collections.emptyList();

@Test
void rewriteWithJdbcConnection() throws AdapterException, SQLException {
final AdapterProperties properties = new AdapterProperties(Map.of("CONNECTION_NAME", CONNECTION_NAME));
final SqlDialect dialect = new DummySqlDialect(null, properties);
final BaseRemoteMetadataReader metadataReader = new BaseRemoteMetadataReader(mockConnection(),
properties);
final QueryRewriter queryRewriter = new ImportFromJDBCQueryRewriter(dialect, metadataReader);
assertThat(queryRewriter.rewrite(TestSqlStatementFactory.createSelectOneFromDual(),
EMPTY_SELECT_LIST_DATA_TYPES, EXA_METADATA, properties),
equalTo("IMPORT FROM JDBC AT " + CONNECTION_NAME
+ " STATEMENT 'SELECT 1 FROM \"DUAL\"'"));
}

@Test
void rewriteWithCustomConnectionDefinitionBuilder() throws AdapterException, SQLException {
final SqlDialect dialect = new DummySqlDialect(null, AdapterProperties.emptyProperties());
final BaseRemoteMetadataReader metadataReader = new BaseRemoteMetadataReader(mockConnection(),
AdapterProperties.emptyProperties());
final QueryRewriter queryRewriter = new ImportFromJDBCQueryRewriter(dialect, metadataReader,
new DummyConnectionDefinitionBuilder());
assertThat(queryRewriter.rewrite(TestSqlStatementFactory.createSelectOneFromDual(),
EMPTY_SELECT_LIST_DATA_TYPES, EXA_METADATA, AdapterProperties.emptyProperties()),
equalTo("IMPORT FROM JDBC MY DUMMY DEFINITION BUILDER STATEMENT 'SELECT 1 FROM \"DUAL\"'"));
}

@Test
void rewriteWithFromResultSetDatatypeDetection() throws AdapterException, SQLException {
final SqlDialect dialect = new DummySqlDialect(null, AdapterProperties.emptyProperties());
final BaseRemoteMetadataReader metadataReader = new BaseRemoteMetadataReader(mockConnection(),
AdapterProperties.emptyProperties());
final QueryRewriter queryRewriter = new ImportFromJDBCQueryRewriter(dialect, metadataReader,
new DummyConnectionDefinitionBuilder());
final Exception exception = assertThrows(AdapterException.class, () -> queryRewriter.rewrite(
TestSqlStatementFactory.createSelectOneFromDual(), EMPTY_SELECT_LIST_DATA_TYPES,
EXA_METADATA,
new AdapterProperties(Map.of(DataTypeDetection.STRATEGY_PROPERTY, "FROM_RESULT_SET"))));

assertThat(exception.getMessage(), equalTo(
"E-VSCJDBC-46: Property `IMPORT_DATA_TYPES` value 'FROM_RESULT_SET' is no longer supported. Please remove the `IMPORT_DATA_TYPES` property from the virtual schema so the default value 'EXASOL_CALCULATED' is used."));
}
}
Loading

0 comments on commit c52ca66

Please sign in to comment.