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

bugfix

parent e75bf018
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,6 @@ import java.util.List; ...@@ -14,7 +14,6 @@ import java.util.List;
public class DataUtil { public class DataUtil {
private static final int MAX_NB_SAMPLES = 200; private static final int MAX_NB_SAMPLES = 200;
private static final int TABLESAMPLE_SEED = 42;
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
private String featuresMainTable; private String featuresMainTable;
...@@ -30,22 +29,25 @@ public class DataUtil { ...@@ -30,22 +29,25 @@ public class DataUtil {
{ {
JsonObject data = new JsonObject(); JsonObject data = new JsonObject();
if (filters.length() > 0)
{
filters = String.format("AND %s", filters);
}
for (String var : vars) { for (String var : vars) {
JsonArray currentVarData = new JsonArray(); JsonArray currentVarData = new JsonArray();
long nbRows = countDatasetRows(); long nbRows = countDatasetRows();
if (nbRows >= 1) { if (nbRows >= 1) {
List<Object> queryResult;
long nb_samples = Math.min(nbRows, MAX_NB_SAMPLES); synchronized(this){
int samplingPercentage = (int) (100 * nb_samples / nbRows); jdbcTemplate.execute("SELECT SETSEED(0.42)");
if (filters.length() > 0) { queryResult = jdbcTemplate.queryForList(
filters = "WHERE " + filters; String.format("SELECT %s FROM %s WHERE %s IS NOT NULL %s ORDER BY Random() LIMIT %d",
var, featuresMainTable, var, filters, MAX_NB_SAMPLES),
Object.class);
} }
List<Object> queryResult = jdbcTemplate.queryForList(
String.format("SELECT %s FROM %s TABLESAMPLE SYSTEM (%d) REPEATABLE (%d) %s",
var, featuresMainTable, samplingPercentage, TABLESAMPLE_SEED, filters),
Object.class);
for (Object value : queryResult) { for (Object value : queryResult) {
if (value == null) { if (value == null) {
currentVarData.add((String) null); currentVarData.add((String) null);
......
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