Skip to content

Commit

Permalink
#21: Added warning when tables scan result is empty. (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
redcatbear authored Jan 31, 2020
1 parent b391068 commit 4456ed8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<description>Common module for JDBC-based data access from Virtual Schemas.</description>
<url>https://github.com/exasol/virtual-schema-common-jdbc</url>
<properties>
<product.version>2.2.0</product.version>
<product.version>2.2.1</product.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private List<TableMetadata> extractTableMetadata(final DatabaseMetaData remoteMe
logTablesScan(catalogName, schemaName);
try (final ResultSet remoteTables = remoteMetadata.getTables(catalogName, schemaName, ANY_TABLE,
getTableTypeFilter())) {
return mapTables(remoteTables, selectedTables);
return this.tableMetadataReader.mapTables(remoteTables, selectedTables);
}
}

Expand Down Expand Up @@ -149,11 +149,6 @@ protected void logTablesScan(final String catalogName, final String schemaName)
});
}

private List<TableMetadata> mapTables(final ResultSet remoteTables, final Optional<List<String>> selectedTables)
throws SQLException {
return this.tableMetadataReader.mapTables(remoteTables, selectedTables);
}

@Override
public SchemaAdapterNotes getSchemaAdapterNotes() {
try {
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/exasol/adapter/jdbc/BaseTableMetadataReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@ public BaseTableMetadataReader(final Connection connection, final ColumnMetadata
public List<TableMetadata> mapTables(final ResultSet remoteTables, final Optional<List<String>> selectedTables)
throws SQLException {
final List<TableMetadata> translatedTables = new ArrayList<>();
while (remoteTables.next()) {
mapOrSkipTable(remoteTables, translatedTables, selectedTables);
if (remoteTables.next()) {
do {
mapOrSkipTable(remoteTables, translatedTables, selectedTables);
} while (remoteTables.next());
} else {
LOGGER.warning(() -> "Table scan did not find any tables. This can mean that either" //
+ " a) the source does not contain tables (yet)," + " b) the table type is not supported or" //
+ " c) the table scan filter criteria is incorrect." //
+ " Please check that the source actually contains tables. " //
+ " Also check the spelling and exact case of any catalog or schema name you provided.");
}
return translatedTables;
}
Expand All @@ -57,8 +65,8 @@ protected void mapOrSkipTable(final ResultSet remoteTables, final List<TableMeta
}
}

private void mapSupportedTables(ResultSet remoteTables, List<TableMetadata> translatedTables,
Optional<List<String>> selectedTables, String tableName) throws SQLException {
private void mapSupportedTables(final ResultSet remoteTables, final List<TableMetadata> translatedTables,
final Optional<List<String>> selectedTables, final String tableName) throws SQLException {
if (isTableSelected(tableName, selectedTables)) {
mapOrSkipSelectedTable(remoteTables, translatedTables, tableName);
} else {
Expand All @@ -85,7 +93,7 @@ protected void mapOrSkipSelectedTable(final ResultSet remoteTables, final List<T
}

private boolean isTableFilteredOut(final String tableName) {
List<String> filteredTables = this.properties.getFilteredTables();
final List<String> filteredTables = this.properties.getFilteredTables();
if (filteredTables.isEmpty()) {
return false;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.exasol.adapter.jdbc;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;

import java.sql.Connection;
import java.sql.SQLException;
Expand All @@ -22,7 +23,7 @@ void testGetSchemaAdapterNotesWithSqlException() throws SQLException {

private Connection mockConnectionThrowingExceptionOnGetMetadata() throws SQLException {
final Connection connectionMock = Mockito.mock(Connection.class);
Mockito.when(connectionMock.getMetaData()).thenThrow(new SQLException("FAKE SQL exception"));
when(connectionMock.getMetaData()).thenThrow(new SQLException("FAKE SQL exception"));
return connectionMock;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.exasol.adapter.jdbc;

import static com.exasol.adapter.jdbc.TableMetadataMockUtils.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.iterableWithSize;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.mockito.Mockito.when;

import java.sql.*;
import java.util.List;
import java.util.Optional;
import java.util.logging.Logger;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -20,6 +20,7 @@
import com.exasol.adapter.dialects.BaseIdentifierConverter;
import com.exasol.adapter.metadata.DataType;
import com.exasol.adapter.metadata.TableMetadata;
import com.exasol.logging.CapturingLogHandler;

@ExtendWith(MockitoExtension.class)
class BaseTableMetadataReaderTest {
Expand Down Expand Up @@ -82,4 +83,13 @@ void testMapTablesIgnoresTablesThatHaveNoColumns() throws SQLException {
assertAll(() -> assertThat(tables, iterableWithSize(1)), //
() -> assertThat(tableA.getName(), equalTo(TABLE_A)));
}

@Test
void testWarnIfTableScanResultsAreEmpty() throws SQLException {
mockTableCount(this.tablesMock, 0);
final CapturingLogHandler capturingLogHandler = new CapturingLogHandler();
Logger.getLogger("com.exasol").addHandler(capturingLogHandler);
createDefaultTableMetadataReader().mapTables(this.tablesMock, Optional.empty());
assertThat(capturingLogHandler.getCapturedData(), containsString("Table scan did not find any tables."));
}
}

0 comments on commit 4456ed8

Please sign in to comment.