From 5071ff5268f71106cdc60c5ba82a8ca3872f8834 Mon Sep 17 00:00:00 2001 From: Guillaume Buisson Date: Fri, 22 May 2015 12:12:11 +0200 Subject: [PATCH] updated example and docs --- examples/project.clj | 4 ++-- examples/src/handler.clj | 30 +++++++++++++++++++++--------- src/clj_druid/schemas/filter.clj | 11 ++++++++--- src/clj_druid/schemas/fragment.clj | 2 +- src/clj_druid/schemas/query.clj | 17 +++++++++++++---- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/examples/project.clj b/examples/project.clj index 0c2930f..43242a7 100644 --- a/examples/project.clj +++ b/examples/project.clj @@ -2,9 +2,9 @@ :description "clj-druid-examples" :dependencies [[org.clojure/clojure "1.6.0"] [clj-time "0.9.0"] ;; needed as `lein ring` is broken - [metosin/compojure-api "0.20.3"] + [metosin/compojure-api "0.20.4"] [metosin/ring-http-response "0.6.1"] - [metosin/ring-swagger-ui "2.1.1-M2"] + [metosin/ring-swagger-ui "2.1.5-M2"] [y42/clj-druid "0.2.3"]] :ring {:handler handler/app} :uberjar-name "examples.jar" diff --git a/examples/src/handler.clj b/examples/src/handler.clj index 7b941d6..2887cdd 100644 --- a/examples/src/handler.clj +++ b/examples/src/handler.clj @@ -1,9 +1,21 @@ (ns handler - (:require [compojure.api.sweet :refer :all] - [ring.util.http-response :refer :all] - [clj-druid.schemas.query :refer :all])) + (:require + [compojure.api.sweet :refer :all] + [ring.util.http-response :refer :all] + [clj-druid.schemas.query :refer :all] + [clj-druid.client :as client])) + + +(def default-druid-host "http://localhost:8083/druid/v2") +(client/connect {:hosts [default-druid-host]}) + +(defn do-query [q] + (ok (client/query + client/randomized + (:queryType q) q))) (defapi app + {:formats [:edn]} (swagger-ui) (swagger-docs {:info {:title "clj-druid + Compojure API" @@ -13,29 +25,29 @@ (POST* "/groupBy" [] :body [q groupBy] :summary "Issue a groupBy query" - (ok true)) + (do-query q)) (POST* "/topN" [] :body [q topN] :summary "Issue a topN query" - (ok true)) + (do-query q)) (POST* "/timeseries" [] :body [q timeseries] :summary "Issue a timeseries query" - (ok true)) + (do-query q)) (POST* "/search" [] :body [q search] :summary "Issue a search query" - (ok true)) + (do-query q)) (POST* "/timeBoundary" [] :body [q timeBoundary] :summary "Issue a timeBoundary query" - (ok true)) + (do-query q)) (POST* "/segmentMetadata" [] :body [q segmentMetadata] :summary "Issue a segmentMetadata query" - (ok true)))) + (do-query q)))) diff --git a/src/clj_druid/schemas/filter.clj b/src/clj_druid/schemas/filter.clj index 0a9d6fe..b4e8faa 100644 --- a/src/clj_druid/schemas/filter.clj +++ b/src/clj_druid/schemas/filter.clj @@ -2,14 +2,18 @@ (:require [schema.core :as s])) (s/defschema selectorFilter - "The simplest filter is a selector filter. The selector filter will match a specific dimension with a specific value. Selector filters can be used as the base filters for more complex Boolean expressions of filters." + "The simplest filter is a selector filter. +The selector filter will match a specific dimension with a specific value. +Selector filters can be used as the base filters for more complex Boolean expressions of filters." {:type (s/enum :selector) :dimension s/Str :value s/Any}) (s/defschema regexFilter - "The regular expression filter is similar to the selector filter, but using regular expressions. It matches the specified dimension with the given pattern. The pattern can be any standard Java regular expression." + "The regular expression filter is similar to the selector filter, + but using regular expressions. It matches the specified dimension with the given pattern. + The pattern can be any standard Java regular expression." {:type (s/enum :regex) :dimension s/Str :pattern s/Str}) @@ -20,7 +24,8 @@ :function s/Str}) (s/defschema Filter - "A filter is a JSON object indicating which rows of data should be included in the computation for a query. It’s essentially the equivalent of the WHERE clause in SQL. Druid supports the following types of filters." + "A filter is a JSON object indicating which rows of data should be included in the computation for a query. + It’s essentially the equivalent of the WHERE clause in SQL. Druid supports the following types of filters." (s/either selectorFilter regexFilter javascriptFilter diff --git a/src/clj_druid/schemas/fragment.clj b/src/clj_druid/schemas/fragment.clj index 79fda88..b4a4a36 100644 --- a/src/clj_druid/schemas/fragment.clj +++ b/src/clj_druid/schemas/fragment.clj @@ -46,7 +46,7 @@ (s/defschema intervals "Druid interval schema" - [String]) + [s/Str]) (s/defschema queryType "Druid queryType option schema" diff --git a/src/clj_druid/schemas/query.clj b/src/clj_druid/schemas/query.clj index 1a13b55..51b9a66 100644 --- a/src/clj_druid/schemas/query.clj +++ b/src/clj_druid/schemas/query.clj @@ -15,7 +15,10 @@ (s/defschema groupBy - "These types of queries take a groupBy query object and return an array of JSON objects where each object represents a grouping asked for by the query. Note: If you only want to do straight aggregates for some time range, we highly recommend using TimeseriesQueries instead. The performance will be substantially better" + "These types of queries take a groupBy query object +and return an array of JSON objects where each object represents +a grouping asked for by the query. +Note: If you only want to do straight aggregates for some time range" {:queryType (s/enum :groupBy) :dataSource s/Str :dimensions [dimensionSpec] @@ -29,7 +32,8 @@ (s/optional-key :context) context}) (s/defschema timeseries - "These types of queries take a timeseries query object and return an array of JSON objects where each object represents a value asked for by the timeseries query." + "These types of queries take a timeseries query object and return an array of JSON objects +where each object represents a value asked for by the timeseries query." {:queryType (s/enum :timeseries) :dataSource s/Str :granularity granularity @@ -40,7 +44,11 @@ (s/optional-key :context) context}) (s/defschema topN - "TopN queries return a sorted set of results for the values in a given dimension according to some criteria. Conceptually, they can be thought of as an approximate GroupByQuery over a single dimension with an Ordering spec. TopNs are much faster and resource efficient than GroupBys for this use case. These types of queries take a topN query object and return an array of JSON objects where each object represents a value asked for by the topN query." + "TopN queries return a sorted set of results for the values +in a given dimension according to some criteria. +Conceptually, they can be thought of as an approximate GroupByQuery +over a single dimension with an Ordering spec. +TopNs are much faster and resource efficient than GroupBys for this use case." {:queryType (s/enum :topN) :dataSource s/Str :granularity granularity @@ -88,7 +96,7 @@ (s/optional-key :context) context}) (s/defschema timeBoundary - "Segment Metadata query schema" + "Time boundary queries return the earliest and latest data points of a data set. " {:queryType (s/enum :timeBoundary) :dataSource s/Str (s/optional-key :toInclude) segmentMetadataToInclude @@ -96,6 +104,7 @@ (s/optional-key :context) context}) (s/defschema query + "druid query router" (s/either groupBy search segmentMetadata