-
Notifications
You must be signed in to change notification settings - Fork 2
FullExample
gerritjvv edited this page Jan 6, 2012
·
1 revision
public class QueryParserApp {
public static void main(String[] args) throws Throwable {
String str = "SELECT 1, b, a*0.5/2, \"STR\",c , COUNT(1) FROM table WHERE a>=1 AND b<5 GROUP BY a, b";
TableDef tableDef = new SimpleTableDef("mytbl",
new SimpleColumnDef(Integer.class, "a", new IntCell()),
new SimpleColumnDef(Integer.class, "b", new IntCell()),
new SimpleColumnDef(String.class, "c", new StringCell()));
ExecutorService execService = Executors.newCachedThreadPool();
SQLCompiler compiler = new SimpleSQLCompiler(execService);
SQLExecutor exec = compiler.compile(tableDef, str);
Object[][] data = new Object[][]{
new Object[]{ 1, 2, "hi"},
new Object[]{ 1, 3, "hi there"},
new Object[]{ 1, 3, "hi there"}
};
AggregateStore store = new HashMapAggregateStore(exec.getTransforms().toArray(new TransformFunction[0]));
final List<Object[]> dataList = Arrays.asList(data);
exec.pump(new DataSource() {
@Override
public Iterator<Object[]> iterator() {
return dataList.iterator();
}
@Override
public long getEstimatedSize() {
return dataList.size();
}
}, store, null);
execService.shutdown();
store.write(new DataSink() {
@Override
public boolean fill(Key key, Cell<?>[] data) {
System.out.println(key.asString().hashCode() + " : " + Arrays.toString(data));
return true;
}
});
}
}