class Object

Public Instance Methods

_matching(type, m_right, m_on) click to toggle source
Calls superclass method
# File lib/bmg/operator/image.rb, line 182
def _matching(type, m_right, m_on)
  if m_on.include?(as)
    super
  else
    left.matching(m_right, m_on).image(right, as, on, options)
  end
end
_page(type, ordering, page_index, opts) click to toggle source
Calls superclass method
# File lib/bmg/operator/image.rb, line 190
def _page(type, ordering, page_index, opts)
  if ordering.map{|(k,v)| k}.include?(as)
    super
  else
    left
      .page(ordering, page_index, opts)
      .image(right, as, on, options)
  end
end
_project(type, attrlist) click to toggle source
Calls superclass method
# File lib/bmg/operator/image.rb, line 200
def _project(type, attrlist)
  if attrlist.include?(as)
    super
  else
    left.project(attrlist)
  end
end
_restrict(type, predicate) click to toggle source
Calls superclass method
# File lib/bmg/operator/image.rb, line 208
def _restrict(type, predicate)
  on_as, rest = predicate.and_split([as])
  if rest.tautology?
    # push index_right situation: on_as is still the full predicate
    super
  else
    # rest makes no reference to `as` and can be pushed
    # down...
    new_left = left.restrict(rest)

    # regarding right... rest possibly makes references to the
    # join key, but also to left attributes... let split again
    # on the join key attributes, to try to remove spurious
    # attributes for right...
    on_on_and_more, left_only = rest.and_split(on)

    # it's not guaranteed! let now check whether the split led
    # to a situation where the predicate on `on` attributes
    # actually refers to no other ones...
    if !on_on_and_more.tautology? and (on_on_and_more.free_variables - on).empty?
      new_right = right.restrict(on_on_and_more)
    else
      new_right = right
    end

    # This is the image itself
    opt = new_left.image(new_right, as, on, options)

    # finaly, it still needs to be kept on the final node
    opt = opt.restrict(on_as)

    opt
  end
rescue Predicate::NotSupportedError
  super
end
allbut_constants(tuple) click to toggle source
# File lib/bmg/operator/constants.rb, line 127
def allbut_constants(tuple)
  TupleAlgebra.allbut(tuple, constants.keys)
end
allbut_extkeys(tuple) click to toggle source
# File lib/bmg/operator/extend.rb, line 168
def allbut_extkeys(tuple)
  TupleAlgebra.allbut(tuple, extension.keys)
end
autosummarize(by, summarization) click to toggle source
# File lib/bmg/type.rb, line 118
def autosummarize(by, summarization)
  known_attributes!(by + summarization.keys) if typechecked? && knows_attrlist?
  dup.tap{|x|
    x.attrlist = nil
    x.predicate = Predicate.tautology
    x.keys = nil
  }
end
autowrap(oldtype, newtype, options) click to toggle source
# File lib/bmg/support/keys.rb, line 22
def autowrap(oldtype, newtype, options)
  sep = options[:split] || Operator::Autowrap::DEFAULT_OPTIONS[:split]
  keys = @keys.map{|k|
    k.map{|a| a.to_s.split(sep).first }.uniq.map(&:to_sym)
  }
  Keys.new(keys, false)
end
autowrap_tuple(tuple) click to toggle source
# File lib/bmg/operator/autowrap.rb, line 174
def autowrap_tuple(tuple)
  separator = @options[:split]
  autowrapped = tuple.each_with_object({}){|(k,v),h|
    parts = k.to_s.split(separator).map(&:to_sym)
    sub = h
    parts[0...-1].each do |part|
      sub = (sub[part] ||= {})
    end
    unless sub.is_a?(Hash)
      raise Bmg::Error, "Autowrap conflict on attribute `#{parts[-2]}`"
    end
    sub[parts[-1]] = v
    h
  }
  autowrapped = postprocessor.call(autowrapped)
  autowrapped
end
constants(cs) click to toggle source
# File lib/bmg/type.rb, line 127
def constants(cs)
  unknown_attributes!(cs.keys) if typechecked? && knows_attrlist?
  dup.tap{|x|
    x.attrlist  = self.attrlist + cs.keys if knows_attrlist?
    x.predicate = self.predicate & Predicate.eq(cs)
    ### keys stay the same
  }
end
extend(extension) click to toggle source
# File lib/bmg/type.rb, line 136
def extend(extension)
  unknown_attributes!(extension.keys) if typechecked? && knows_attrlist?
  dup.tap{|x|
    x.attrlist  = self.attrlist + extension.keys if knows_attrlist?
    x.predicate = Predicate.tautology
    ### keys stay the same (?)
  }
end
extend_it(tuple) click to toggle source
# File lib/bmg/operator/constants.rb, line 123
def extend_it(tuple)
  tuple.merge(@constants)
end
group(oldtype, newtype, attrs, as) click to toggle source
# File lib/bmg/support/keys.rb, line 30
def group(oldtype, newtype, attrs, as)
  keys = [ oldtype.attrlist - attrs ]
  keys += @keys.map{|k| (k & attrs).empty? ? k : (k - attrs) + [as] }
  Keys.new(keys, true)
end
image(right, as, on, options) click to toggle source
# File lib/bmg/type.rb, line 157
def image(right, as, on, options)
  if typechecked? && knows_attrlist?
    join_compatible!(right, on)
    unknown_attributes!([as])
  end
  dup.tap{|x|
    x.attrlist  = self.attrlist + [as] if knows_attrlist?
    x.predicate = Predicate.tautology
    x.keys      = self._keys
  }
end
join(oldtype, newtype, right_type, on) click to toggle source
# File lib/bmg/support/keys.rb, line 36
def join(oldtype, newtype, right_type, on)
  return nil  unless rkeys = right_type.keys
  return self if rkeys.any?{|k| (k - on).empty? }
  keys = []
  @keys.each do |k1|
    right_type.keys.each do |k2|
      keys << (k1 + k2).uniq
    end
  end
  Keys.new(keys, true)
end
join_compatible!(right, on) click to toggle source
# File lib/bmg/type.rb, line 313
def join_compatible!(right, on)
  extra = on - self.attrlist
  raise TypeError, "Unknow attributes #{extra.join(', ')}" unless extra.empty?
  if right.knows_attrlist?
    extra = on - right.attrlist
    raise TypeError, "Unknow attributes #{extra.join(', ')}" unless extra.empty?
  end
end
known_attributes!(attrs) click to toggle source
# File lib/bmg/type.rb, line 303
def known_attributes!(attrs)
  extra = attrs - self.attrlist
  raise TypeError, "Unknown attributes #{extra.join(', ')}" unless extra.empty?
end
left_join(right, on, default_right_tuple) click to toggle source
# File lib/bmg/type.rb, line 178
def left_join(right, on, default_right_tuple)
  join_compatible!(right, on) if typechecked? && knows_attrlist?
  dup.tap{|x|
    x.attrlist  = (knows_attrlist? and right.knows_attrlist?) ? (self.attrlist + right.attrlist).uniq : nil
    x.predicate = Predicate.tautology
    x.keys      = nil
  }
end
matching(right, on) click to toggle source
# File lib/bmg/type.rb, line 187
def matching(right, on)
  join_compatible!(right, on) if typechecked? && knows_attrlist?
  self
end
normalize_options(options) click to toggle source
# File lib/bmg/operator/autowrap.rb, line 168
def normalize_options(options)
  opts = DEFAULT_OPTIONS.merge(options)
  opts[:postprocessor] = NoLeftJoinNoise.new(opts[:postprocessor])
  opts
end
not_matching(right, on) click to toggle source
# File lib/bmg/type.rb, line 192
def not_matching(right, on)
  join_compatible!(right, on) if typechecked? && knows_attrlist?
  self
end
page(ordering, page_size, options) click to toggle source
# File lib/bmg/type.rb, line 197
def page(ordering, page_size, options)
  known_attributes!(ordering.map{|(k,v)| k}) if typechecked? && knows_attrlist?
  self
end
postprocessor() click to toggle source
# File lib/bmg/operator/autowrap.rb, line 192
def postprocessor
  @options[:postprocessor]
end
project(oldtype, newtype, attrlist) click to toggle source
# File lib/bmg/support/keys.rb, line 48
def project(oldtype, newtype, attrlist)
  keys = @keys.select{|k| k.all?{|a| attrlist.include?(a) } }
  keys = [newtype.attrlist] if keys.empty?
  Keys.new(keys, false)
end
rename(oldtype, newtype, renaming) click to toggle source
# File lib/bmg/support/keys.rb, line 54
def rename(oldtype, newtype, renaming)
  keys = @keys.map{|k| k.map{|a| renaming[a] || a } }
  Keys.new(keys, false)
end
rename_tuple(tuple, renaming) click to toggle source
# File lib/bmg/operator/rename.rb, line 92
def rename_tuple(tuple, renaming)
  tuple.each_with_object({}){|(k,v),h|
    h[renaming[k] || k] = v
    h
  }
end
restrict(oldtype, newtype, predicate) click to toggle source
# File lib/bmg/support/keys.rb, line 59
def restrict(oldtype, newtype, predicate)
  return self if (cs = predicate.constant_variables).empty?
  keys = @keys.map{|k| k - cs }
  Keys.new(keys, false)
end
reverse_renaming() click to toggle source
# File lib/bmg/operator/rename.rb, line 99
def reverse_renaming
  renaming.each_with_object({}){|(k,v),h| h[v] = k }
end
summarize(by, summarization) click to toggle source
# File lib/bmg/type.rb, line 237
def summarize(by, summarization)
  dup.tap{|x|
    x.attrlist = by + summarization.keys
    x.keys     = Keys.new([by])
  }
end
transform(transformation, options = {}) click to toggle source
# File lib/bmg/type.rb, line 244
def transform(transformation, options = {})
  transformer = TupleTransformer.new(transformation)
  if typechecked? && knows_attrlist? && transformer.knows_attrlist?
    known_attributes!(transformer.to_attrlist)
  end
  keys = if options[:key_preserving]
    self._keys
  elsif transformer.knows_attrlist? && knows_keys?
    touched_attrs = transformer.to_attrlist
    keys = self._keys.select{|k| (k & touched_attrs).empty? }
  else
    nil
  end
  pred = if transformer.knows_attrlist?
    attr_list = transformer.to_attrlist
    predicate.and_split(attr_list).last
  else
    Predicate.tautology
  end
  dup.tap{|x|
    x.keys = keys
    x.predicate = pred
  }
end
ungroup(attrlist) click to toggle source
# File lib/bmg/type.rb, line 269
def ungroup(attrlist)
  known_attributes!(attrlist) if typechecked? && knows_attrlist?
  dup.tap{|x|
    x.attrlist  = nil
    x.predicate = Predicate.tautology
    x.keys      = nil
  }
end
union(oldtype, newtype, right_type) click to toggle source
# File lib/bmg/support/keys.rb, line 65
def union(oldtype, newtype, right_type)
  return nil unless rkeys = right_type.keys
  return nil unless (oldtype.predicate & right_type.predicate).contradiction?
  shared = @keys.select{|k| rkeys.include?(k) }
  Keys.new(shared, false)
end
unknown_attributes!(attrs) click to toggle source
# File lib/bmg/type.rb, line 308
def unknown_attributes!(attrs)
  clash = self.attrlist & attrs
  raise TypeError, "Existing attributes #{clash.join(', ')}" unless clash.empty?
end
unwrap(oldtype, newtype, attrs) click to toggle source
# File lib/bmg/support/keys.rb, line 72
def unwrap(oldtype, newtype, attrs)
  untouched = @keys.select{|k| (attrs & k).empty? }
  Keys.new(untouched, false)
end
wrapped_roots!() click to toggle source
# File lib/bmg/operator/autowrap.rb, line 159
def wrapped_roots!
  @wrapped_roots ||= wrapped_roots_of!(operand, options)
end
wrapped_roots_of!(r, opts) click to toggle source
# File lib/bmg/operator/autowrap.rb, line 163
def wrapped_roots_of!(r, opts)
  raise UnknownAttributesError unless r.type.knows_attrlist?
  Support.wrapped_roots(r.type.to_attrlist, opts[:split])
end