void SumTest(Table& table) {
scoped_ptr<AggregationSpecification> specification(
new AggregationSpecification());
specification->AddAggregation(SUM, "i2", "i2");
const Expression* equal_i1 = Equal(ConstInt32(0),NamedAttribute("i1"));
scoped_ptr<Operation> filter1(Filter(equal_i1,
ProjectAllAttributes(),ScanView(table.view())));
scoped_ptr<Operation> aggregation(ScalarAggregate(specification.release(),filter1.release()));
scoped_ptr<Cursor> cursor(SucceedOrDie(aggregation->CreateCursor()));
ResultView result(cursor->Next(-1));
if(result.has_data() && !result.is_eos())
{
const int32* cnts = result.view().column(0).typed_data<INT32>();
cout << result.view().column(0).attribute().name() << ":" << *cnts << endl;
}
}
int main(int,char**)
{
TupleSchema schema;
schema.add_attribute(Attribute("i1",INT32,NOT_NULLABLE));
schema.add_attribute(Attribute("i2",INT32,NOT_NULLABLE));
Table table(schema,HeapBufferAllocator::Get());
TableRowWriter writer(&table);
writer.AddRow();
writer.Int32(1);
writer.Int32(1);
SumTest(table);
return 0;
}
在 2014年3月13日星期四UTC+8下午5时04分46秒,ptab写道: