 ;;
 (ns com.puppetlabs.puppetdb.query
   (:require [clojure.string :as string])
-  (:use [com.puppetlabs.utils :only [parse-number]]
+  (:use [com.puppetlabs.utils :only [parse-number keyset]]
         [com.puppetlabs.puppetdb.scf.storage :only [db-serialize sql-as-numeric sql-array-query-string sql-regexp-match sql-regexp-array-match]]
         [com.puppetlabs.jdbc :only [valid-jdbc-query?]]
         [clojure.core.match :only [match]]))

        subquery-type (subquery->type (first subquery))]
    (when-not subquery-type
      (throw (IllegalArgumentException. (format "The argument to extract must be a select operator, not '%s'" (first subquery)))))
    (when-not (get-in selectable-columns [subquery-type field])
      (throw (IllegalArgumentException. (format "Can't extract unknown %s field '%s'. Acceptable fields are: %s" (name subquery-type) field (string/join ", " (sort (selectable-columns subquery-type)))))))
    {:where (format "SELECT r1.%s FROM (%s) r1" field subselect)
     :params params}))


  [ops query]
  {:post [valid-jdbc-query? %]}
  (let [{:keys [where params]} (compile-term ops query)
        sql (format "SELECT %s FROM certnames WHERE %s" (column-map->sql node-columns) where)]
    (apply vector sql params)))

(defn compile-resource-equality-v2
