Skip to content

Commit

Permalink
Fix division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
janmotl committed Apr 17, 2018
1 parent 2a8ad6f commit 6c4eb34
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/vendor/MSSQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void getColumnStatistics(String databaseName, String schemaName, List<Tab
"\t) nullCounter\n" +
"\n" +
" \tDELETE FROM #Density\n" +
" \tdelete FROM #Histogram\n" +
" \tDELETE FROM #Histogram\n" +
"-- End\n" +
"FETCH NEXT FROM MY_CURSOR INTO @TABLE_NAME, @STAT_NAME\n" +
"END\n" +
Expand Down Expand Up @@ -182,8 +182,8 @@ public void getColumnStatistics(String databaseName, String schemaName, List<Tab
}
column.setTextMin(rs.getString(3));
column.setTextMax(rs.getString(4));
column.setNullRatio(column.getRowCount()==null ? null : rs.getDouble(5) / column.getRowCount());
column.setUniqueRatio(column.getRowCount()==null ? null : (1/rs.getDouble(6)) / column.getRowCount());
column.setNullRatio((column.getRowCount()==null || column.getRowCount()==0) ? null : rs.getDouble(5) / column.getRowCount());
column.setUniqueRatio(column.getRowCount()==null || column.getRowCount()==0 ? null : (1/rs.getDouble(6)) / column.getRowCount());
column.setWidthAvg(rs.getDouble(7));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/vendor/Oracle.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ public void getColumnStatistics(String databaseName, String schemaName, List<Tab
if (table == null) continue; // The table is blacklisted -> skip it
@Nullable Column column = table.getColumn(rs.getString(2)); // Oracle supports "hidden" columns that are by default not listed in getColumns() JDBC call but statistics is still calculated on them
if (column == null) continue;
column.setUniqueRatio(column.getRowCount()==null ? null : rs.getDouble(3) / column.getRowCount()); // If we have no knowledge about the column, return null
column.setUniqueRatio(column.getRowCount()==null || column.getRowCount()==0 ? null : rs.getDouble(3) / column.getRowCount()); // If we have no knowledge about the column, return null
column.setTextMin(rs.getString(4));
column.setTextMax(rs.getString(5));
column.setNullRatio(column.getRowCount()==null ? null : rs.getDouble(6) / column.getRowCount());
column.setNullRatio(column.getRowCount()==null || column.getRowCount()==0 ? null : rs.getDouble(6) / column.getRowCount());
column.setWidthAvg(rs.getDouble(7));
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/vendor/QualityControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ public static void qcNumericalValues(List<Table> tables) {
for (Table table : tables) {
for (Column column : table.getColumnList()) {
// Doubles
if (column.getNullRatio() != null && column.getNullRatio().isInfinite()) LOGGER.severe("NullRatio is infinite");
if (column.getUniqueRatio() != null && column.getUniqueRatio().isInfinite()) LOGGER.severe("UniqueRatio is infinite");
if (column.getWidthAvg() != null && column.getWidthAvg().isInfinite()) LOGGER.severe("WidthAvg is infinite");
if (column.getNullRatio() != null && column.getNullRatio().isInfinite()) LOGGER.severe("NullRatio in " + table.getName() + "." + column.getName() + " is infinite");
if (column.getUniqueRatio() != null && column.getUniqueRatio().isInfinite()) LOGGER.severe("UniqueRatio " + table.getName() + "." + column.getName() + " is infinite");
if (column.getWidthAvg() != null && column.getWidthAvg().isInfinite()) LOGGER.severe("WidthAvg " + table.getName() + "." + column.getName() + " is infinite");

if (column.getNullRatio() != null && column.getNullRatio().isNaN()) LOGGER.severe("NullRatio is NaN");
if (column.getUniqueRatio() != null && column.getUniqueRatio().isNaN()) LOGGER.severe("UniqueRatio is NaN");
if (column.getWidthAvg() != null && column.getWidthAvg().isNaN()) LOGGER.severe("WidthAvg is NaN");
if (column.getNullRatio() != null && column.getNullRatio().isNaN()) LOGGER.severe("NullRatio " + table.getName() + "." + column.getName() + " is NaN");
if (column.getUniqueRatio() != null && column.getUniqueRatio().isNaN()) LOGGER.severe("UniqueRatio " + table.getName() + "." + column.getName() + " is NaN");
if (column.getWidthAvg() != null && column.getWidthAvg().isNaN()) LOGGER.severe("WidthAvg " + table.getName() + "." + column.getName() + " is NaN");

if (column.getNullRatio() != null && column.getNullRatio() < 0) LOGGER.severe("NullRatio is negative");
if (column.getUniqueRatio() != null && column.getUniqueRatio() < 0) LOGGER.severe("UniqueRatio is negative");
if (column.getWidthAvg() != null && column.getWidthAvg() < 0) LOGGER.severe("WidthAvg is negative");
if (column.getNullRatio() != null && column.getNullRatio() < 0) LOGGER.severe("NullRatio " + table.getName() + "." + column.getName() + " is negative");
if (column.getUniqueRatio() != null && column.getUniqueRatio() < 0) LOGGER.severe("UniqueRatio " + table.getName() + "." + column.getName() + " is negative");
if (column.getWidthAvg() != null && column.getWidthAvg() < 0) LOGGER.severe("WidthAvg " + table.getName() + "." + column.getName() + " is negative");

// Integers
if (column.getRowCount() != null && column.getRowCount() < 0) LOGGER.severe("RowCount is negative");
if (column.getRowCount() != null && column.getRowCount() < 0) LOGGER.severe("RowCount " + table.getName() + "." + column.getName() + " is negative");
}
}
}
Expand Down

0 comments on commit 6c4eb34

Please sign in to comment.