updated example and docs

This commit is contained in:
Guillaume Buisson 2015-05-22 12:12:11 +02:00
parent f1b9d5e316
commit 5071ff5268
5 changed files with 45 additions and 19 deletions

View file

@ -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"

View file

@ -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))))

View file

@ -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. Its 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.
Its essentially the equivalent of the WHERE clause in SQL. Druid supports the following types of filters."
(s/either selectorFilter
regexFilter
javascriptFilter

View file

@ -46,7 +46,7 @@
(s/defschema intervals
"Druid interval schema"
[String])
[s/Str])
(s/defschema queryType
"Druid queryType option schema"

View file

@ -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