use of org.apache.apex.malhar.contrib.misc.streamquery.function.SumFunction in project apex-malhar by apache.
the class GroupByOperatorTest method testSqlGroupBy.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSqlGroupBy() {
// create operator
GroupByHavingOperator oper = new GroupByHavingOperator();
oper.addColumnGroupByIndex(new ColumnIndex("b", null));
try {
oper.addAggregateIndex(new SumFunction("c", null));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
EqualValueCondition condition = new EqualValueCondition();
condition.addEqualValue("a", 1);
oper.setCondition(condition);
CollectorTestSink sink = new CollectorTestSink();
oper.outport.setSink(sink);
oper.setup(null);
oper.beginWindow(1);
HashMap<String, Object> tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", 1);
tuple.put("c", 2);
oper.inport.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", 1);
tuple.put("c", 4);
oper.inport.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", 2);
tuple.put("c", 6);
oper.inport.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", 2);
tuple.put("c", 7);
oper.inport.process(tuple);
oper.endWindow();
oper.teardown();
LOG.debug("{}", sink.collectedTuples);
}
use of org.apache.apex.malhar.contrib.misc.streamquery.function.SumFunction in project apex-malhar by apache.
the class HavingOperatorTest method testSqlGroupBy.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSqlGroupBy() throws Exception {
// create operator
GroupByHavingOperator oper = new GroupByHavingOperator();
oper.addColumnGroupByIndex(new ColumnIndex("b", null));
FunctionIndex sum = new SumFunction("c", null);
oper.addAggregateIndex(sum);
// create having condition
HavingCondition having = new HavingCompareValue<Double>(sum, 6.0, 0);
oper.addHavingCondition(having);
EqualValueCondition condition = new EqualValueCondition();
condition.addEqualValue("a", 1);
oper.setCondition(condition);
CollectorTestSink sink = new CollectorTestSink();
oper.outport.setSink(sink);
oper.setup(null);
oper.beginWindow(1);
HashMap<String, Object> tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", 1);
tuple.put("c", 2);
oper.inport.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", 1);
tuple.put("c", 4);
oper.inport.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", 2);
tuple.put("c", 6);
oper.inport.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", 2);
tuple.put("c", 7);
oper.inport.process(tuple);
oper.endWindow();
oper.teardown();
LOG.debug("{}", sink.collectedTuples);
}
Aggregations