Project

claw_druid

0.0
No commit activity in last 3 years
No release in over 3 years
A ruby client of Druid.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.14.0
~> 1.7
~> 12.0
 Project Readme

claw_druid

Gem Version

A Ruby client for Druid.

Installation

Add following line to Gemfile:

gem 'claw_druid', '~> 0.0.5'

Install it directly:

gem install claw_druid -v 0.0.5

Initization

client = ClawDruid.new(url: 'http://druid_broker.com:port/druid/v2/', source: 'table_name')

select

The complex 'sum', 'max', 'min' and 'count' with operators will be transformed into Post-Aggregations automatically. The select of lookups shoud be a hash.

client.select(:dimension1, :dimension2, :column1, :column2)
client.select("sum(column1) as sum_column1, sum(column2)")
client.select("sum(column1 + column2) as col1_col2")
client.select("(sum(column1 + column2) // sum(column3)) as col1_col2_col3")

client.select({dimension: :dimension_id, output: :dimension_name, name: :lookup_names})

where

Add the conditions to filters.

client.where(dimension1: v1, dimension2: v2)
client.where("dimension1 = #{v1} and dimension2 > #{v2}")
client.where("dimension1 >= ? or dimension2 <= ?", v1, v2)
client.where(dimension1: [v1, v2, v3]) # dimension1 in (v1, v2, v4)

group

Add the dimensions to dimensions by groupBy. The groupby of lookups shoud be a hash.

client.group(:dimension1)
client.group(:dimension1, :dimension2)

client.group({dimension: :game_cd, output: :game_name, name: :lookup_names})

having

Add the having conditions to having.

client.group(:dimension1).having("sum(column1)" => v1)
client.group(:dimension1).having("sum(column1) > #{v1}")
client.group(:dimension1, :dimension2).having("sum(column1)" => v1, "sum(column2)" => v2)
client.group(:dimension1, :dimension2).having("sum(column1) > ? and sum(column2) <= ?", v1, v2)

sum

Get the sum result by using methods in Aggregations

client.where(dimension1: v1, dimension2: v2).sum(:column1)
client.where(dimension1: v1, dimension2: v2).sum(:column1, :column2)

client.group(:dimension1, :dimension2).sum(:column1)
client.group(:dimension1, :dimension2).sum(:column1, :column2)

client.group(:dimension1, :dimension2).having("sum(column1) > ? and sum(column2) <= ?", v1, v2).sum(:column1, :column2)

max, min

Get the max min result by using methods in Aggregations

client.where(dimension1: v1, dimension2: v2).max(:column1)
client.where(dimension1: v1, dimension2: v2).min(:column1, :column2)

client.group(:dimension1, :dimension2).min(:column1)
client.group(:dimension1, :dimension2).max(:column1, :column2)

client.group(:dimension1, :dimension2).having("max(column1) > ? and min(column2) <= ?", v1, v2).max(:column1).min(:column2)

count

Get the count.

client.where(dimension1: v1, dimension2: v2).count

client.group(:dimension1, :dimension2).count
client.group(:dimension1, :dimension2).having("min(column1) > ? and min(column2) <= ?", v1, v2).count

count cardinality

Count cardinality of columns.

client.where(dimension1: v1, dimension2: v2).count(:column1)
client.where(dimension1: v1, dimension2: v2).count(:column1, :column2)

client.group(:dimension1, :dimension2).count(:column1)
client.group(:dimension1, :dimension2).count(:column1, :column2)

client.group(:dimension1, :dimension2).having("min(column1) > ? and min(column2) <= ?", v1, v2).count(:column1, :column2)

limit

Get the limited results by using limit.

client.group(:dimension1, :dimension2).sum(:dimension1, :dimension2).limit(100)

topN

Get the top results by using topN.

client.where(dimension1: v1, dimension2: v2).select(:dimension1, :dimension2).top(100)

order

Get the orderd results by using order.

client.where(dimension1: v1, dimension2: v2).select(:dimension1, :dimension2).order(:dimension1, :dimension2)
client.where(dimension1: v1, dimension2: v2).select(:dimension1, :dimension2).order(dimension1: :desc)
client.where(dimension1: v1, dimension2: v2).select(:dimension1, :dimension2).order(dimension1: :desc, :dimension2)

page

The page method could only using in Select.

client.where(dimension1: v1).page(1)
client.where(dimension1: v1).page(2)

Intervals

Set the intervals by adding begin_time and end_time to where conditions.

client.where(begin_time: time1, end_time: time2)

query

Get the result.

client.where().group().sum().query
client.time_boundary
client.max_time
client.min_time
client.source_meta
client.segment_meta

Enumerable

records = client.where().group().sum()
result  = records.to_a
records.map do |record| 
  # value
end
records.each do |record|
  # do something
end