module ElasticGraph::GraphQL::Aggregation::Key

def self.encode(parts)

def self.encode(parts)
  parts.join(DELIMITER)
end

def self.extract_aggregation_name_from(agg_name_or_key)

multiple aggregations (some with `grouped_by`, some without) in the same query.
where some hash keys are in one form and some are in the other form. This can happen when we run
It's also possible for these two forms to be mixed under `aggregations` on a datastore response,

`[agg_name]:[field_path]:[function]`.
directly under `aggregations` in the datastore response will take a from like:
- For aggregations with no `grouped_by`, we encode the aggregation name in the key, and the keys
that shows up as a key directly under `aggregations` in the datastore response.
- When we use `grouped_by`, we run a composite aggregation that has the aggregation name, and

be an encoded key. We need this for dealing with the multiple forms that aggregation responses take:
Extracts an aggregation name from a string that could either already be an aggregation name, or could
def self.extract_aggregation_name_from(agg_name_or_key)
  agg_name_or_key.split(DELIMITER, 2).first || agg_name_or_key
end

def self.missing_value_bucket_key(base_key)

documents that are missing a value for the field being grouped on.
Encodes the key used for a `missing` aggregation used to provide a bucket for
def self.missing_value_bucket_key(base_key)
  Key.encode([base_key, "m"])
end

def self.verify_no_delimiter_in(*parts)

def self.verify_no_delimiter_in(*parts)
  parts.each do |part|
    if part.to_s.include?(DELIMITER)
      raise Errors::InvalidArgumentValueError, %("#{part}" contains delimiter: "#{DELIMITER}")
    end
  end
end