Skip to content

Commit

Permalink
Fix MSSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
janmotl committed Jun 7, 2018
1 parent 544d34b commit 7f3a55f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'application'

group 'linkifier'
version '3.2.3'
version '3.2.4'
sourceCompatibility = 1.8
mainClassName = 'controller.MainApp'

Expand Down
10 changes: 9 additions & 1 deletion gui/controller/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class Events implements Initializable {
buttonRun.setText("Estimate");
LOGGER.severe(Throwables.getStackTraceAsString(runService.getException()));
LOGGER.info("Something went wrong...");
LOGGER.info("Linkifier version: " + getClass().getPackage().getImplementationVersion());
LOGGER.info("Please, send an email to the developer at [email protected]");
});
runService.setOnSucceeded(event -> {
Expand Down Expand Up @@ -259,7 +260,14 @@ protected Void call() throws SQLException, InterruptedException {
try (Connection connection = DataSourceFactory.getConfiguredDataSource(properties, textPassword.getText()).getConnection()) {
if (isCancelled()) return null;

LOGGER.info("Successfully connected to the database.");
// Info for easier debugging
String databaseName = connection.getCatalog();
if (connection.getSchema()!=null)
databaseName += "." + connection.getSchema();
databaseName += " @ " + connection.getMetaData().getDatabaseProductName();
databaseName += " " + connection.getMetaData().getDatabaseProductVersion();
LOGGER.info("Successfully connected to: " + databaseName);

linkifier = new Linkifier(connection, properties.getProperty("schema"), Pattern.compile(properties.getProperty("tableBlacklist")));
if (isCancelled()) return null;

Expand Down
4 changes: 3 additions & 1 deletion src/vendor/MSSQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void getColumnStatistics(String databaseName, String schemaName, List<Tab
"( " +
" AllDensity REAL, " +
" AvgLength REAL, " +
" Columns NVARCHAR(4000), " +
" Columns NVARCHAR(4000) " +
") " +

// "CREATE TABLE #StatHeader " +
Expand Down Expand Up @@ -167,6 +167,8 @@ public void getColumnStatistics(String databaseName, String schemaName, List<Tab
tableMap.put(table.getName(), table);
}

System.out.println(query);

try (Statement stmt = connection.createStatement()){
stmt.executeUpdate(query);
}
Expand Down
7 changes: 7 additions & 0 deletions src/vendor/MySQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ public void getColumnStatistics(String databaseName, String schemaName, List<Tab
column.setHistogramBounds(Histogram.rel2abs(parse(rawHistogram), Double.valueOf(column.getTextMin()), Double.valueOf(column.getTextMax())));
} catch (Exception ignored) {} // The table can be empty, the statistics may not be calculated,...
}
} catch (SQLException e) {
LOGGER.info(e.getMessage());

if (!connection.getMetaData().getDatabaseProductVersion().contains("MariaDB"))
LOGGER.info(" Explanation: The access to column statistics in MySQL is changing from one minor release to Continuing without the statistics. The estimates will be off.");
else
throw e;
}

// Output quality control (if something turns sour, we want to know about that)
Expand Down
69 changes: 56 additions & 13 deletions test/example/LinkifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void financial() throws Exception {
linkifier.estimatePk();
linkifier.estimateFk();

assertEquals(8, linkifier.getPkCount()); // There are 8 tables -> we expected 8
assertEquals(8, linkifier.getPkCount()); // There are 8 tables -> we expect 8
assertTrue(Accuracy.getPkRecall(linkifier.getTables()) > 0.99);
assertTrue(Accuracy.getPkPrecision(linkifier.getTables()) > 0.99);
assertTrue(Accuracy.getFkRecall(linkifier.getRelationships()) > 0.99);
Expand Down Expand Up @@ -119,38 +119,81 @@ public void sat() throws Exception {
}

@Test
public void firefox() throws Exception {
Jdbc3PoolingDataSource dataSource = new Jdbc3PoolingDataSource();
dataSource.setServerName("localhost"); // Private with sensitive data. Tested because it is used in published articles by the 3rd parties.
dataSource.setUser("jan");

dataSource.setDatabaseName("PredictorFactory");
dataSource.setCurrentSchema("ctu_firefox");
public void blacklist() throws Exception {
dataSource.setDatabaseName("financial");
try (Connection connection = dataSource.getConnection()){
Linkifier linkifier = new Linkifier(connection, "ctu_firefox", Pattern.compile(""));
Linkifier linkifier = new Linkifier(connection, "", Pattern.compile("loan|trans"));
linkifier.estimatePk();
linkifier.estimateFk();

assertEquals(6, linkifier.getPkCount()); // There are 8 tables, but 2 are blacklisted -> we expected 6
assertTrue(Accuracy.getPkRecall(linkifier.getTables()) > 0.99);
assertTrue(Accuracy.getPkPrecision(linkifier.getTables()) > 0.99);
assertTrue(Accuracy.getFkRecall(linkifier.getRelationships()) >= 0.7); // Misses: moz_bookmarks.fk --> moz_places.id, moz_items_annos.item_id --> moz_bookmarks.id
assertTrue(Accuracy.getFkRecall(linkifier.getRelationships()) > 0.99);
assertTrue(Accuracy.getFkPrecision(linkifier.getRelationships()) > 0.99);
}
}

@Test
public void blacklist() throws Exception {
public void nonExistingSchema() throws Exception {
// MySQL immediately returns an error. But PostgreSQL and MSSQL will silently continue...
Jdbc3PoolingDataSource dataSource = new Jdbc3PoolingDataSource();
dataSource.setServerName("localhost"); // Local only, sorry
dataSource.setUser("jan");
dataSource.setPassword("");
dataSource.setDatabaseName("PredictorFactory");

try (Connection connection = dataSource.getConnection()){
Linkifier linkifier = new Linkifier(connection, "NonExisting", Pattern.compile(""));
linkifier.estimatePk();
linkifier.estimateFk();

assertEquals(0, linkifier.getTables().size());
assertEquals(0, linkifier.getRelationships().size());
}
}

@Test
public void MySQL() throws Exception {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName("localhost"); // Local only, sorry
dataSource.setUser("root");
dataSource.setPassword("");
dataSource.setDatabaseName("financial");

try (Connection connection = dataSource.getConnection()){
Linkifier linkifier = new Linkifier(connection, "", Pattern.compile("loan|trans"));
Linkifier linkifier = new Linkifier(connection, "", Pattern.compile(""));
linkifier.estimatePk();
linkifier.estimateFk();

assertEquals(6, linkifier.getPkCount()); // There are 8 tables, but 2 are blacklisted -> we expected 6
assertEquals(8, linkifier.getPkCount()); // There are 8 tables -> we expect 8
assertTrue(Accuracy.getPkRecall(linkifier.getTables()) > 0.99);
assertTrue(Accuracy.getPkPrecision(linkifier.getTables()) > 0.99);
assertTrue(Accuracy.getFkRecall(linkifier.getRelationships()) > 0.99);
assertTrue(Accuracy.getFkPrecision(linkifier.getRelationships()) > 0.88); // Some errors are expected
}
}


@Test
public void firefox() throws Exception {
Jdbc3PoolingDataSource dataSource = new Jdbc3PoolingDataSource();
dataSource.setServerName("localhost"); // Private with sensitive data. Tested because it is used in published articles by the 3rd parties.
dataSource.setUser("jan");

dataSource.setDatabaseName("PredictorFactory");
dataSource.setCurrentSchema("ctu_firefox");
try (Connection connection = dataSource.getConnection()){
Linkifier linkifier = new Linkifier(connection, "ctu_firefox", Pattern.compile(""));
linkifier.estimatePk();
linkifier.estimateFk();

assertTrue(Accuracy.getPkRecall(linkifier.getTables()) > 0.99);
assertTrue(Accuracy.getPkPrecision(linkifier.getTables()) > 0.99);
assertTrue(Accuracy.getFkRecall(linkifier.getRelationships()) >= 0.7); // Misses: moz_bookmarks.fk --> moz_places.id, moz_items_annos.item_id --> moz_bookmarks.id
assertTrue(Accuracy.getFkPrecision(linkifier.getRelationships()) > 0.99);
}
}


}
4 changes: 2 additions & 2 deletions test/main/VendorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void init() {
}

@Test
public void MySQL() throws Exception {
public void MariaDB() throws Exception {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName("relational.fit.cvut.cz"); // Public read-only database for testing
dataSource.setUser("guest");
Expand Down Expand Up @@ -141,7 +141,7 @@ public void Oracle() throws Exception {


@Test
public void MySQL_numbers() throws Exception {
public void MariaDB_numbers() throws Exception {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName("relational.fit.cvut.cz"); // Public read-only database for testing
dataSource.setUser("guest");
Expand Down

0 comments on commit 7f3a55f

Please sign in to comment.