slamdata/slamengine — pull request #456 by sellout (2014-11-21 06:08:24+00:00)
Title: Implement `filter`.

This is not a complete fix for #207, but it does implement `filter` and
allow certain cases of `HAVING`, etc. to work. However, there are other
cases that still fail for other reasons: bad merging, broken
`$foldLeft`, …

Selectors no longer use the FieldPhase (which has been deleted), but now
keep track of the nodes they need WorkflowBuilders for.

* make `appendOp` private, and add explicit `skip` and `limit` functions;
* implement arithmetic in JsExprPhase;
* improve WorkflowBuilder merging in a few cases;
* remove JsExprPhase dependency from SelectorPhase (WorkflowPhase now
handles generating `$where` selectors);
* reduce instances of $foldLeft (via converting a `$map` to a
`$simpleMap`);
* eliminate `$projects` and `__tmp`s in many places (via eliminating use
of `Makearray` for sort and group keys, as well as some inlining of
ExprBuilders in some cases);
* the above also means that more `select *` queries have a result at
`$$ROOT` rather than `value`;
* prevent deleteUnusedFields from deleting used fields in the case that a
shape-preserving op preceded an unknown shape op (like $map) or the
end of the query (this became apparent when the final `$projects`
disappeared as mentioned above)

This also improves the request generated for #447, but it’s uncertain
whether that is actually fixed.