Skip to content
Snippets Groups Projects
Commit 9139d122 authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

check if dataset is empty before sampling

parent cc1d542a
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,12 @@ public class DataUtil {
for (String var : vars) {
JsonArray currentVarData = new JsonArray();
int samplingPercentage = 100 * NB_ROWS_SAMPLING / (int) countAdniRows();
int nbRows = (int) countDatasetRows();
if (nbRows < 1)
{
return data;
}
int samplingPercentage = 100 * NB_ROWS_SAMPLING / nbRows;
List<Object> queryResult = jdbcTemplate.queryForList(
"SELECT " + var + " FROM "+scienceMainTable+" " +
"TABLESAMPLE SYSTEM ("+ samplingPercentage +") REPEATABLE ( "+ TABLESAMPLE_SEED +" )", Object.class);
......@@ -55,18 +60,16 @@ public class DataUtil {
@Cacheable("colscount")
public long countVariables()
{
long count = jdbcTemplate.queryForObject(
return jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS " +
"WHERE table_name = '"+scienceMainTable+"'", Long.class);
return count;
}
@Cacheable("rowscount")
public long countAdniRows()
public long countDatasetRows()
{
long count = jdbcTemplate.queryForObject(
return jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM "+scienceMainTable, Long.class);
return count;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment