ds.close();
}
public void testGroupByQuery() throws Exception {
DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
Table table = dc.getDefaultSchema().getTableByName("csv_people.csv");
Query q = new Query();
q.from(table);
q.groupBy(table.getColumnByName("gender"));
q.select(new SelectItem(table.getColumnByName("gender")),
new SelectItem(FunctionType.MAX, table.getColumnByName("age")),
new SelectItem(FunctionType.MIN, table.getColumnByName("age")), new SelectItem(FunctionType.COUNT, "*",
"total"), new SelectItem(FunctionType.MIN, table.getColumnByName("id")).setAlias("firstId"));
DataSet data = dc.executeQuery(q);
assertEquals(
"[csv_people.csv.gender, MAX(csv_people.csv.age), MIN(csv_people.csv.age), COUNT(*) AS total, MIN(csv_people.csv.id) AS firstId]",
Arrays.toString(data.getSelectItems()));
String[] expectations = new String[] { "Row[values=[female, 20, 17, 5, 5]]", "Row[values=[male, 19, 17, 4, 1]]" };