public static void main(String[] args) { PlanFactory f = getInstance(); // DAU // SELECT COUNT(DISTINCT(uid)) // FROM event NATURAL JOIN user // WHERE user.register_time='2013-02-01' // AND event.date='2013-02-02' and event.event='visit' f.newGroup() .setInput( f.newDistinct() .setInput( f.newJoin() .setInput( f.newSelection() .setInput( f.newTableScan("user"), new Equals( new ColumnValue("register_time"), new Constant("2013-02-01"))), f.newSelection() .setInput( f.newTableScan("event"), new And( new Equals( new ColumnValue("date"), new Constant("2013-02-02")), new Equals( new ColumnValue("event"), new Constant("visit"))))), new ColumnValue("uid")), null, null); }
@Override public void visit(SubJoin subJoin) { FromItem left = subJoin.getLeft(); FromItem right = subJoin.getJoin().getRightItem(); FromItemVisitorImpl leftVisitor = new FromItemVisitorImpl(where); FromItemVisitorImpl rightVisitor = new FromItemVisitorImpl(where); left.accept(leftVisitor); right.accept(rightVisitor); relationProvider = PlanFactory.getInstance().newJoin(); ((Join) relationProvider) .setInput(leftVisitor.getRelationProvider(), rightVisitor.getRelationProvider()); }
@Override public void visit(Table table) { TableScan tableScan = PlanFactory.getInstance().newTableScan(table.getName()); relationProvider = PlanFactory.getInstance().newSelection(); ((Selection) relationProvider).setInput(tableScan, getWhere(tableScan)); }