Skip to content
Snippets Groups Projects
Commit fe703c66 authored by Ludovic Claude's avatar Ludovic Claude
Browse files

Fix data sampling

parent d4886d81
No related branches found
No related tags found
No related merge requests found
...@@ -33,25 +33,41 @@ public class DataUtil { ...@@ -33,25 +33,41 @@ public class DataUtil {
for (String var : vars) { for (String var : vars) {
JsonArray currentVarData = new JsonArray(); JsonArray currentVarData = new JsonArray();
int nbRows = (int) countDatasetRows(); long nbRows = countDatasetRows();
if (nbRows < 1) { return data; }
if (nbRows >= 1) {
int nb_samples = Math.min(nbRows, MAX_NB_SAMPLES);
int samplingPercentage = 100 * nb_samples / nbRows; long nb_samples = Math.min(nbRows, MAX_NB_SAMPLES);
List<Object> queryResult = jdbcTemplate.queryForList( int samplingPercentage = (int) (100 * nb_samples / nbRows);
"SELECT " + var + " FROM "+featuresMainTable+" " + List<Object> queryResult = jdbcTemplate.queryForList(
"TABLESAMPLE SYSTEM ("+ samplingPercentage +") REPEATABLE ( "+ TABLESAMPLE_SEED +" )", Object.class); String.format("SELECT %s FROM %s TABLESAMPLE SYSTEM (%d) REPEATABLE (%d)",
for (Object value : queryResult) var, featuresMainTable, samplingPercentage, TABLESAMPLE_SEED),
{ Object.class);
String strValue = String.valueOf(value); for (Object value : queryResult) {
try { if (value == null) {
double numValue = Double.parseDouble(strValue); currentVarData.add((String) null);
currentVarData.add(numValue); } else {
} catch (NumberFormatException e2) { if (value instanceof Double) {
currentVarData.add(strValue); currentVarData.add((Double) value);
} else if (value instanceof Float) {
currentVarData.add((Float) value);
} else if (value instanceof Integer) {
currentVarData.add((Integer) value);
} else if (value instanceof Long) {
currentVarData.add((Long) value);
} else {
String strValue = String.valueOf(value);
try {
double numValue = Double.parseDouble(strValue);
currentVarData.add(numValue);
} catch (NumberFormatException e2) {
currentVarData.add(strValue);
}
}
}
} }
data.add(var, currentVarData);
} }
data.add(var, currentVarData);
} }
return data; return data;
......
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