y42 / clj-druid

Eclipse Public License 1.0
31 stars 10 forks source link

Make it possible to bypass validations #25

Closed slipset closed 7 years ago

slipset commented 7 years ago

Even though I like the query-validations, there are times when I need to do stuff that the schemas are not allowing. Example at hand right now is working with thetaSketches, http://druid.io/docs/latest/development/extensions-core/datasketches-aggregators.html which is not currently supported by the schema. As a work around I do this

(defn execute*
  "Issue a druid query"
  ([client balance-strategy druid-query http-params]
   (execute* client balance-strategy druid-query http-params false))
  ([client balance-strategy druid-query http-params non-strict?]
   (let [nodes (druid/nodes client)]
     (when-not non-strict?
       (v/validate druid-query (:queryType druid-query)))
     (when (empty? nodes)
       (throw (Exception.
               "No druid node available for query")))
     (http/post (balance-strategy nodes)
                (merge {:body (json/encode druid-query)
                        :as :text
                        :content-type :json}
                       http-params)))))

in my code.

Would you want this in cli-druid? if not, please just close this issue.

gbuisson commented 7 years ago

I was thinking that perhaps we should stop enforcing schema validation at runtime, and let us enable it only during tests, we could achieve that turning query into a s/defn and let developers use schema/with-fn-validation at will.

slipset commented 7 years ago

Sounds reasonable, but then you'd have to rewrite the schemas to spec (but that's maybe planned?).

gbuisson commented 7 years ago

No it's a schema feature so no need for spec, you can see how it's supposed to be used here: https://github.com/plumatic/schema#beyond-type-hints, I use it extensively on many projects.