@Override public Double getVectorMean(String columnName) throws DDFException { Double mean = 0.0; String command = String.format("select avg(%s) from @this", columnName); if (!Strings.isNullOrEmpty(command)) { List<String> result = this.getDDF() .sql(command, String.format("Unable to compute the mean of the given column from table %%s")).getRows(); if (result != null && !result.isEmpty() && result.get(0) != null) { mean = Double.parseDouble(result.get(0)); return mean; } } return null; }
@Override public Double getVectorMax(String columnName) throws DDFException { Double max = 0.0; String command = String.format("select max(%s) from @this", columnName); if (!Strings.isNullOrEmpty(command)) { List<String> result = this.getDDF() .sql(command, String.format("Unable to compute the maximum value of the given column from table %%s")).getRows(); if (result != null && !result.isEmpty() && result.get(0) != null) { max = Double.parseDouble(result.get(0)); return max; } } return null; }
private long numberOfNAPerColumn(String column) throws DDFException { return Long .parseLong(this.getDDF() .sql(String.format("SELECT COUNT(*) FROM %%s WHERE %s IS NULL", column), "Unable to run the query.") .getRows().get(0)); }
@Override public Double getVectorMin(String columnName) throws DDFException { Double min = 0.0; String command = String.format("select min(%s) from @this", columnName); if (!Strings.isNullOrEmpty(command)) { List<String> result = this.getDDF() .sql(command, String.format("Unable to compute the minimum value of the given column from table %%s")).getRows(); if (result != null && !result.isEmpty() && result.get(0) != null) { min = Double.parseDouble(result.get(0)); return min; } } return null; }
@Override public double getVectorCor(String xColumnName, String yColumnName) throws DDFException { double corr = 0.0; String command = String.format("select corr(%s, %s) from @this", xColumnName, yColumnName); if (!Strings.isNullOrEmpty(command)) { List<String> result = this.getDDF().sql(command, String.format("Unable to compute correlation of %s and %s from table %%s", xColumnName, yColumnName)).getRows(); if (result != null && !result.isEmpty() && result.get(0) != null) { corr = Double.parseDouble(result.get(0)); return corr; } } return Double.NaN; }
@Override public double getVectorCovariance(String xColumnName, String yColumnName) throws DDFException { double cov = 0.0; String command = String.format("select covar_samp(%s, %s) from @this", xColumnName, yColumnName); if (!Strings.isNullOrEmpty(command)) { List<String> result = this.getDDF().sql(command, String.format("Unable to compute covariance of %s and %s from table %%s", xColumnName, yColumnName)).getRows(); if (result != null && !result.isEmpty() && result.get(0) != null) { System.out.println(">>>>> parseDouble: " + result.get(0)); cov = Double.parseDouble(result.get(0)); return cov; } } return Double.NaN; }
@Override public List<String> head(int numRows) throws DDFException { return this.getDDF().sql(String.format("SELECT * FROM @this LIMIT %d", numRows), String.format("Unable to fetch %d row(s) from table %%s", numRows)).getRows(); }
@Override public Double[] getVectorVariance(String columnName) throws DDFException { Double[] sd = new Double[2]; String command = String.format("select var_samp(%s) from @this", columnName); if (!Strings.isNullOrEmpty(command)) { List<String> result = this.getDDF() .sql(command, String.format("Unable to compute the variance of the given column from table %%s")).getRows(); if (result != null && !result.isEmpty() && result.get(0) != null) { Double a = Double.parseDouble(result.get(0)); sd[0] = a; sd[1] = Math.sqrt(a); return sd; } } return null; }
public void export2csv(DDF ddf, String fileURL, String fieldSeparator, Boolean hasHead) throws DDFException { if (!fieldSeparator.equalsIgnoreCase("\t")) { throw new DDFException("only '\t' is supported as separator."); } SqlResult result = ddf.sql("select * from @this", "error"); this.export2csv(result, fileURL, fieldSeparator, hasHead); }
List<String> rs = getDDF().sql(cmd, "Cannot get vector quantiles from SQL queries").getRows(); if (rs == null || rs.size() == 0) { throw new DDFException("Cannot get vector quantiles from SQL queries");
.sql(command, String.format("Unable to get fivenum summary of the given columns from table %%s")).getRows() .get(0).replaceAll("\\[|\\]| ", "").replaceAll(",", "\t").split("\t| "); } else if (this.getDDF().getEngineType().equals(DDFManager.EngineType.POSTGRES)
Assert.assertTrue(ddf1.getSchemaHandler().getColumn("month").getOptionalFactor().getLevelMap().get("[2,4]") > 0); Assert.assertEquals(ddf1.getSchemaHandler().getColumn("month").getOptionalFactor().getLevelCounts().get("[2,4]"), 6, 0); Assert.assertFalse(Strings.isNullOrEmpty(newddf.sql("select dayofweek from @this", "").getRows().get(0))); Assert.assertFalse(Strings.isNullOrEmpty(ddf1.sql("select month from @this", "").getRows().get(0)));