View Source Panoramix (Panoramix v0.16.3)

Post a query to Druid Broker or request its status.

Use Panoramix.Query to build a query.

Examples

Build a query like this:

use Panoramix

q = from "my_datasource",
      query_type: "timeseries",
      intervals: ["2019-03-01T00:00:00+00:00/2019-03-04T00:00:00+00:00"],
      granularity: :day,
      filter: dimensions.foo == "bar",
       aggregations: [event_count: count(),
                      unique_id_count: hyperUnique(:user_unique)]

And then send it:

Panoramix.post_query(q, :default)

Where :default is a configuration profile pointing to your Druid server.

The default value for the profile argument is :default, so if you only need a single configuration you can omit it:

Panoramix.post_query(q)

Response example:

{:ok,
 [
   %{
     "result" => %{
       "event_count" => 7544,
       "unique_id_count" => 43.18210933535
     },
     "timestamp" => "2019-03-01T00:00:00.000Z"
   },
   %{
     "result" => %{
       "event_count" => 1051,
       "unique_id_count" => 104.02052398847
     },
     "timestamp" => "2019-03-02T00:00:00.000Z"
   },
   %{
     "result" => %{
       "event_count" => 4591,
       "unique_id_count" => 79.19885795313
     },
     "timestamp" => "2019-03-03T00:00:00.000Z"
   }
 ]}

To make a nested query, pass a map of the form %{type: :query, query: inner_query} as data source. For example:

use Panoramix

inner_query = from "my_datasource",
                query_type: "topN",
                intervals: ["2019-03-01T00:00:00+00:00/2019-03-04T00:00:00+00:00"],
                granularity: :day,
                aggregations: [event_count: count()],
                dimension: "foo",
                metric: "event_count",
                threshold: 100
q = from %{type: :query, query: inner_query},
      query_type: "timeseries",
      intervals: ["2019-03-01T00:00:00+00:00/2019-03-04T00:00:00+00:00"],
      granularity: :day,
      aggregations: [foo_count: count(),
                     event_count_sum: longSum(:event_count)],
      post_aggregations: [mean_events_per_foo: aggregations.event_count_sum / aggregations.foo_count]

To make a join query, pass a map of the form %{type: :join, left: left, right: right, joinType: :INNER | :LEFT, rightPrefix: "prefix_", condition: "condition"}. Both the left and the right side can be a nested query as above, %{type: :query, query: inner_query}, which will be expanded. Other join sources will be passed to Druid unchanged. For example:

use Panoramix

from %{type: :join,
       left: "sales",
       right: %{type: :lookup, lookup: "store_to_country"},
       rightPrefix: "r.",
       condition: "store == "r.k"",
       joinType: :INNER},
  query_type: "groupBy",
  intervals: ["0000/3000"],
  granularity: "all",
  dimensions: [%{type: "default", outputName: "country", dimension: "r.v"}],
  aggregations: [country_revenue: longSum(:revenue)]

You can also build a JSON query yourself by passing it as a map to post_query:

Panoramix.post_query(%{queryType: "timeBoundary", dataSource: "my_datasource"})

To request status from Broker run

Panoramix.status(:default)

Link to this section Summary

Link to this section Functions

Format a date or a datetime into a format that Druid expects.

Examples

iex> Panoramix.format_time! ~D[2018-07-20]
"2018-07-20"
iex> Panoramix.format_time!(
...>   Timex.to_datetime({{2018,07,20},{1,2,3}}))
"2018-07-20T01:02:03+00:00"
Link to this function

post_query(query, profile \\ :default)

View Source

Specs

post_query(Panoramix.Query.t() | map(), atom()) ::
  {:ok, term()}
  | {:error, HTTPoison.Error.t() | Jason.DecodeError.t() | Panoramix.Error.t()}
Link to this function

post_query!(query, profile \\ :default)

View Source

Specs

post_query!(Panoramix.Query.t() | map(), atom()) :: term()
Link to this function

status(profile \\ :default)

View Source

Specs

status(atom()) ::
  {:ok, term()}
  | {:error, HTTPoison.Error.t() | Jason.DecodeError.t() | Panoramix.Error.t()}
Link to this function

status!(profile \\ :default)

View Source

Specs

status!(atom()) :: term()