Implement limit, sample, distinct, and union in local mode

Also add functional tests

cc @mapstrchakra