Class: Druid::Query::AggregationsValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/druid/query.rb

Constant Summary collapse

TYPES =
%w(timeseries groupBy topN)

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/druid/query.rb', line 121

def validate_each(record, attribute, value)
  if TYPES.include?(record.queryType)
    if !value.is_a?(Array) || value.blank?
      record.errors.add(attribute, 'must be a list with at least one aggregator')
    else
      value.each(&:valid?) # trigger validation
      value.each do |avalue|
        avalue.errors.messages.each do |k, v|
          record.errors.add(attribute, { k => v })
        end
      end
    end
  else
    record.errors.add(attribute, "is not supported by type=#{record.queryType}") if value
  end
end