Class: Bmg::Operator::Constants

Inherits:
Object
  • Object
show all
Includes:
Unary
Defined in:
lib/bmg/operator/constants.rb

Overview

Constants operator.

Extends operand’s tuples with attributes given at construction. This is a special case of an extension, where the values are statically known.

Constant Summary

Constants included from Algebra

Algebra::METHODS

Instance Attribute Summary

Attributes included from Unary

#operand, #type

Instance Method Summary collapse

Methods included from Unary

#_visit, #operands

Methods included from Bmg::Operator

#inspect, #to_s

Methods included from Relation

#debug, empty, #empty?, new, #one, #one_or_nil, #to_json, #visit, #ys_by_x

Methods included from Algebra

#allbut, #autosummarize, #autowrap, #extend, #group, #image, #matching, #page, #project, #rename, #restrict, #rxmatch, #spied, #union, #unspied

Constructor Details

#initialize(type, operand, constants) ⇒ Constants

Returns a new instance of Constants.



13
14
15
16
17
# File 'lib/bmg/operator/constants.rb', line 13

def initialize(type, operand, constants)
  @type = type
  @operand = operand
  @constants = constants
end

Instance Method Details

#deleteObject



49
50
51
# File 'lib/bmg/operator/constants.rb', line 49

def delete
  operand.delete
end

#eachObject



25
26
27
28
29
# File 'lib/bmg/operator/constants.rb', line 25

def each
  @operand.each do |tuple|
    yield extend_it(tuple)
  end
end

#insert(arg) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/bmg/operator/constants.rb', line 31

def insert(arg)
  case arg
  when Hash       then operand.insert(allbut_constants(arg))
  when Relation   then operand.insert(arg.allbut(constants.keys))
  when Enumerable then operand.insert(arg.map{|t| allbut_constants(t) })
  else
    super
  end
end

#to_astObject



53
54
55
# File 'lib/bmg/operator/constants.rb', line 53

def to_ast
  [ :constants, operand.to_ast, constants.dup ]
end

#update(tuple) ⇒ Object

Raises:



41
42
43
44
45
46
47
# File 'lib/bmg/operator/constants.rb', line 41

def update(tuple)
  shared = tuple.keys & constants.keys
  on_tuple = TupleAlgebra.project(tuple, shared)
  on_const = TupleAlgebra.project(constants, shared)
  raise InvalidUpdateError, "Cannot violate relvar predicate" unless on_tuple == on_const
  operand.update(allbut_constants(tuple))
end