(PDB-3930) Don't json-serialize fact values during ~ comparisons
(PDB-3930) Don't json-serialize fact values during ~ comparisons

Excepting the query vector directly below, assume we're using SQL
quotation syntax.

Previously, for a comparison (say to the nodes endpoint) like

  ["~", ["fact", "osfamily"], "foo"]

the query engine would generate a path like this to look up the value:

  ...->'osfamily')::text

The -> operator produces json(b), and then the ::text serializes the
value as json, so that a value of 'bar' in the database will actually
be compared to the regular expression as '"bar"'.  Note the extra
double quotes from the json serialization.

This was originally reported because comparisons against the regex
'^foo' were failing while comparisons against '^"foo' would succeed.

For the case in question, change the query engine to generate
a (possibly nested) path lookup that uses -> only for the non-leaf
elements and uses ->> for the final retrieval.  (The ->> operator
produces the unserialzed text representation of the value.)

With that, the query should compare 'foo' to 'foo', rather than
'"foo"'.

puppetlabs/puppetdb,puppetlabs/puppetdb,puppetlabs/puppetdb,puppetlabs/puppetdb,puppetlabs/puppetdb