(PDB-657) Query logic refactor

First cut at creating an intermediate query language for PuppetDB. The
initial user query is expanded from the more sugared syntax to a smaller
set of basic operators and subqueries. The query then goes from the
"expanded form" to a query plan and then ultimately down to sql. The
user query is manipulated in the context of a "source query", specific
to each endpoint. This commit supports resources, but will next expand
to the other endpoints.