module NoSE::StatementSupportQuery

Extend {Statement} objects to allow them to generate support queries

Public Instance Methods

modifies_index?(index) click to toggle source

Determine if this statement modifies a particular index

# File lib/nose/statements.rb, line 563
def modifies_index?(index)
  !(@settings.map(&:field).to_set & index.all_fields).empty?
end
support_queries(_index) click to toggle source

Support queries required to updating the given index with this statement @return [Array<SupportQuery>]

# File lib/nose/statements.rb, line 569
def support_queries(_index)
  []
end

Private Instance Methods

build_support_query(entity, index, graph, select, conditions) click to toggle source

Build a support query to update a given index and select fields with certain conditions @return [SupportQuery]

# File lib/nose/statements.rb, line 578
def build_support_query(entity, index, graph, select, conditions)
  return nil if select.empty?

  params = {
    select: select,
    graph: graph,
    key_path: graph.longest_path,
    entity: key_path.first.parent,
    conditions: conditions
  }

  support_query = SupportQuery.new entity, params, nil, group: @group
  support_query.instance_variable_set :@statement, self
  support_query.instance_variable_set :@index, index
  support_query.instance_variable_set :@comment, (hash ^ index.hash).to_s
  support_query.instance_variable_set :@text, support_query.unparse
  support_query.hash
  support_query.freeze
end
split_entity(subgraph, graph, entity) click to toggle source

Determine which entity a subgraph was split at @return [Entity]

# File lib/nose/statements.rb, line 621
def split_entity(subgraph, graph, entity)
  graph.keys_from_entity(entity).find do |key|
    subgraph.entities.include? key.entity
  end.entity
end
support_queries_for_entity(index, select) click to toggle source

Produce support queries for the entity of the statement which select the given set of fields @return [Array<SupportQuery>]

# File lib/nose/statements.rb, line 601
def support_queries_for_entity(index, select)
  graphs = index.graph.size > 1 ? index.graph.split(entity, true) : []

  graphs.map do |graph|
    support_fields = select.select do |field|
      field.parent != entity && graph.entities.include?(field.parent)
    end.to_set

    conditions = {
      entity.id_field.id => Condition.new(entity.id_field, :'=', nil)
    }

    split_entity = split_entity graph, index.graph, entity
    build_support_query split_entity, index, graph, support_fields,
                        conditions
  end.compact
end