A Ruby client for Druid.
Add following line to Gemfile:
gem 'claw_druid', '~> 0.0.5'
Install it directly:
gem install claw_druid -v 0.0.5
client = ClawDruid.new(url: 'http://druid_broker.com:port/druid/v2/', source: 'table_name')
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})
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)
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})
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)
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)
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)
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 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)
Get the limited results by using limit.
client.group(:dimension1, :dimension2).sum(:dimension1, :dimension2).limit(100)
Get the top results by using topN.
client.where(dimension1: v1, dimension2: v2).select(:dimension1, :dimension2).top(100)
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)
The page method could only using in Select.
client.where(dimension1: v1).page(1)
client.where(dimension1: v1).page(2)
Set the intervals by adding begin_time and end_time to where conditions.
client.where(begin_time: time1, end_time: time2)
Get the result.
client.where().group().sum().query
client.time_boundary
client.max_time
client.min_time
client.source_meta
client.segment_meta
records = client.where().group().sum()
result = records.to_a
records.map do |record|
# value
end
records.each do |record|
# do something
end