Skip to content

Instantly share code, notes, and snippets.

@AndrewTsao
Created December 31, 2012 13:25
Show Gist options
  • Select an option

  • Save AndrewTsao/4419744 to your computer and use it in GitHub Desktop.

Select an option

Save AndrewTsao/4419744 to your computer and use it in GitHub Desktop.
Learn CompoundExpression in supersonic.
static void LearnCompoundExpression() {
scoped_ptr<CompoundExpression> tuple(new CompoundExpression());
tuple->AddAs("from", ConstString("Supersonic: "));
tuple->AddAs("say",
If(Less(ConstInt32(28), ConstInt32(29)),
ConstString("Hello"),
ConstString("World")));
tuple->AddAs("comma", ConstString(","));
tuple->AddAs("new", Plus(ConstInt32(2012), ConstInt32(1)));
scoped_ptr<Operation> compute(Compute(tuple.release(), Generate(10)));
scoped_ptr<Cursor> cursor(SucceedOrDie(compute->CreateCursor()));
scoped_ptr<ResultView> result(new ResultView(cursor->Next(-1)));
if (result->has_data()) {
const View& view = result->view();
cout << view.schema().GetHumanReadableSpecification() << endl;
for (int i = 0; i < view.row_count(); i++) {
cout << view.column(0).typed_data<STRING>()[i]
<< view.column(1).typed_data<STRING>()[i]
<< view.column(2).typed_data<STRING>()[i]
<< view.column(3).typed_data<INT32>()[i]
<< endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment