WIP: stats queries sans pail and thrift

Tests still need rewriting.