ruby-druid 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02fc0eb65bd4e29f2358fd4b57b2dd9307b383b0
4
- data.tar.gz: 14d2855760981c4e49243dfafbb1a1503cfe2bd8
3
+ metadata.gz: ef87663c236bf89b7937fef4c7709d3937e5f0e6
4
+ data.tar.gz: 82d29a256a0cebc175aeb9d88173f1455e9a8475
5
5
  SHA512:
6
- metadata.gz: 959f3eb9b4c822c9f1cfb4ea2656d553a81c7082d456482456df041374a4da538311f8e55ac2ec2b46a98dc0e61f481621cadae4c0c6c1708048c5e2f25c9a6d
7
- data.tar.gz: ab10bcf594ed6a080031b361455bd616426c95f5e0920064559e7833dfb8769d77ecac08955995161a72ae5b3c51b7be1ea36cef102b103ef64585656512dcf8
6
+ metadata.gz: a81d42c823310788cf35fcde9c683674fd863ea3f71557d1ab0e3c01d21f66cdeedd601a816deced10367b27db19d625fc19803d6463bfdaea3aa42f063f8875
7
+ data.tar.gz: 1a0c049e54420fc1c6773e489cbef4a118f751f4e5c9172377ace9474173dab10cba6d41253056e305e5c4156c02cc8594814f1138852ad7806272c249532583
@@ -0,0 +1,54 @@
1
+ module Druid
2
+ class Dimension
3
+ include ActiveModel::Model
4
+
5
+ attr_accessor :type
6
+ validates :type, inclusion: { in: %w(default extraction) }
7
+
8
+ attr_accessor :dimension
9
+ validates :dimension, presence: true
10
+
11
+ attr_accessor :outputName
12
+ validates :outputName, presence: true
13
+
14
+ class ExtractionFnValidator < ActiveModel::EachValidator
15
+ TYPES = %w(extraction)
16
+ def validate_each(record, attribute, value)
17
+ if TYPES.include?(record.type)
18
+ record.errors.add(attribute, 'may not be blank') if value.blank?
19
+ else
20
+ record.errors.add(attribute, "is not supported by type=#{record.type}") if value
21
+ end
22
+ end
23
+ end
24
+
25
+ attr_accessor :extractionFn
26
+ validates :extractionFn, extraction_fn: true
27
+
28
+ def initialize(params)
29
+ if params.is_a?(Hash)
30
+ super
31
+ else
32
+ super(type: 'default', dimension: params.to_s, outputName: params.to_s)
33
+ end
34
+ end
35
+
36
+ def as_json(options = {})
37
+ super(options.merge(except: %w(errors validation_context)))
38
+ end
39
+
40
+ def self.lookup(dimension, namespace, retain: true, injective: false)
41
+ new({
42
+ type: 'extraction',
43
+ dimension: dimension,
44
+ outputName: dimension,
45
+ extractionFn: {
46
+ type: 'registeredLookup',
47
+ lookup: namespace,
48
+ retainMissingValue: retain,
49
+ injective: injective,
50
+ },
51
+ })
52
+ end
53
+ end
54
+ end
data/lib/druid/query.rb CHANGED
@@ -5,6 +5,7 @@ require 'active_support/all'
5
5
  require 'active_model'
6
6
 
7
7
  require 'druid/granularity'
8
+ require 'druid/dimension'
8
9
  require 'druid/aggregation'
9
10
  require 'druid/post_aggregation'
10
11
  require 'druid/filter'
@@ -80,7 +81,16 @@ module Druid
80
81
  TYPES = %w(groupBy select)
81
82
  def validate_each(record, attribute, value)
82
83
  if TYPES.include?(record.queryType)
83
- record.errors.add(attribute, 'must be a list with at least one dimension') if !value.is_a?(Array) || value.blank?
84
+ if !value.is_a?(Array) || value.blank?
85
+ record.errors.add(attribute, 'must be a list with at least one dimension')
86
+ else
87
+ value.each(&:valid?) # trigger validation
88
+ value.each do |avalue|
89
+ avalue.errors.messages.each do |k, v|
90
+ record.errors.add(attribute, { k => v })
91
+ end
92
+ end
93
+ end
84
94
  else
85
95
  record.errors.add(attribute, "is not supported by type=#{record.queryType}") if value
86
96
  end
@@ -90,14 +100,34 @@ module Druid
90
100
  attr_accessor :dimensions
91
101
  validates :dimensions, dimensions: true
92
102
 
103
+ def dimensions
104
+ @dimensions ||= []
105
+ end
106
+
107
+ def dimensions=(value)
108
+ if value.is_a?(Array)
109
+ @dimensions = value.map do |x|
110
+ x.is_a?(Dimension) ? x : Dimension.new(x)
111
+ end
112
+ else
113
+ @dimensions = [
114
+ value.is_a?(Dimension) ? value : Dimension.new(value)
115
+ ]
116
+ end
117
+ end
118
+
93
119
  class AggregationsValidator < ActiveModel::EachValidator
94
120
  TYPES = %w(timeseries groupBy topN)
95
121
  def validate_each(record, attribute, value)
96
122
  if TYPES.include?(record.queryType)
97
- value.each(&:valid?) # trigger validation
98
- value.each do |avalue|
99
- avalue.errors.messages.each do |k, v|
100
- record.errors.add(attribute, { k => v })
123
+ if !value.is_a?(Array) || value.blank?
124
+ record.errors.add(attribute, 'must be a list with at least one aggregator')
125
+ else
126
+ value.each(&:valid?) # trigger validation
127
+ value.each do |avalue|
128
+ avalue.errors.messages.each do |k, v|
129
+ record.errors.add(attribute, { k => v })
130
+ end
101
131
  end
102
132
  end
103
133
  else
@@ -116,10 +146,12 @@ module Druid
116
146
  def aggregations=(value)
117
147
  if value.is_a?(Array)
118
148
  @aggregations = value.map do |x|
119
- Aggregation.new(x)
149
+ x.is_a?(Aggregation) ? x : Aggregation.new(x)
120
150
  end
121
151
  else
122
- @aggregations = [value]
152
+ @aggregations = [
153
+ value.is_a?(Aggregation) ? value : Aggregation.new(value)
154
+ ]
123
155
  end
124
156
  end
125
157
 
@@ -333,7 +365,9 @@ module Druid
333
365
 
334
366
  def group_by(*dimensions)
335
367
  query_type(:groupBy)
336
- @query.dimensions = dimensions.flatten
368
+ @query.dimensions = dimensions.map do |dimension|
369
+ dimension.is_a?(Dimension) ? dimension : Dimension.new(dimension)
370
+ end
337
371
  self
338
372
  end
339
373
 
data/lib/druid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Druid
2
- VERSION = "0.9.1"
2
+ VERSION = "0.10.0"
3
3
  end
@@ -21,7 +21,9 @@ describe Druid::Query do
21
21
 
22
22
  it 'takes dimensions from group_by method' do
23
23
  @query.group_by(:a, :b, :c)
24
- expect(JSON.parse(@query.query.to_json)['dimensions']).to eq(['a', 'b', 'c'])
24
+ expect(JSON.parse(@query.query.to_json)['dimensions']).to eq([{"type"=>"default", "dimension"=>"a", "outputName"=>"a"},
25
+ {"type"=>"default", "dimension"=>"b", "outputName"=>"b"},
26
+ {"type"=>"default", "dimension"=>"c", "outputName"=>"c"}])
25
27
  end
26
28
 
27
29
  it 'takes dimension, metric and threshold from topn method' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-druid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby Druid Community
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-18 00:00:00.000000000 Z
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -177,6 +177,7 @@ files:
177
177
  - lib/druid/client.rb
178
178
  - lib/druid/context.rb
179
179
  - lib/druid/data_source.rb
180
+ - lib/druid/dimension.rb
180
181
  - lib/druid/filter.rb
181
182
  - lib/druid/granularity.rb
182
183
  - lib/druid/having.rb
@@ -210,13 +211,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
211
  version: '0'
211
212
  requirements: []
212
213
  rubyforge_project:
213
- rubygems_version: 2.5.1
214
+ rubygems_version: 2.4.8
214
215
  signing_key:
215
216
  specification_version: 4
216
217
  summary: A Ruby client for Druid
217
218
  test_files:
219
+ - spec/spec_helper.rb
218
220
  - spec/lib/client_spec.rb
219
221
  - spec/lib/data_source_spec.rb
220
- - spec/lib/query_spec.rb
221
222
  - spec/lib/zk_spec.rb
222
- - spec/spec_helper.rb
223
+ - spec/lib/query_spec.rb