assertEquals(
"SELECT persons.column_number FROM s.persons WHERE (persons.name = 'kasper' OR persons.role = 'user')",
q.toString());
DataContext dc = new QueryPostprocessDataContext() {
@Override
public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
assertEquals(3, columns.length);
assertEquals("column_number", columns[0].getName());
assertEquals("name", columns[1].getName());
assertEquals("role", columns[2].getName());
SelectItem[] selectItems = new SelectItem[] { new SelectItem(col1), new SelectItem(col2),
new SelectItem(col3) };
DataSetHeader header = new CachingDataSetHeader(selectItems);
List<Row> rows = new LinkedList<Row>();
rows.add(new DefaultRow(header, new Object[] { "foo", "bar", 1 }));
rows.add(new DefaultRow(header, new Object[] { "kasper", "developer", 2 }));
rows.add(new DefaultRow(header, new Object[] { "admin", "admin", 3 }));
rows.add(new DefaultRow(header, new Object[] { "elikeon", "user", 4 }));
rows.add(new DefaultRow(header, new Object[] { "someuser", "user", 5 }));
rows.add(new DefaultRow(header, new Object[] { "hmm", "what-the", 6 }));
return new InMemoryDataSet(header, rows);
}
@Override
protected String getMainSchemaName() throws MetaModelException {
return "s";
}
@Override
protected Schema getMainSchema() throws MetaModelException {
return schema;
}
};
DataSet result = dc.executeQuery(q);
List<Object[]> objectArrays = result.toObjectArrays();
assertEquals(3, objectArrays.size());
assertEquals(2, objectArrays.get(0)[0]);
assertEquals(4, objectArrays.get(1)[0]);
assertEquals(5, objectArrays.get(2)[0]);