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.

Instance Attribute Summary

Attributes included from Bmg::Operator

#type

Instance Method Summary collapse

Methods included from Unary

#bind

Methods included from Bmg::Operator

#inspect, #to_s

Methods included from Relation

#bind, #count, #debug, empty, #empty?, new, #one, #one_or_nil, #to_csv, #to_json, #to_xlsx, #type, #visit, #with_type, #with_type_attrlist, #with_typecheck, #without_typecheck, #y_by_x, #ys_by_x

Methods included from Algebra

#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #left_join, #matching, #materialize, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #ungroup, #union, #unspied, #unwrap

Methods included from Algebra::Shortcuts

#exclude, #image, #images, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix, #ungroup, #unwrap, #where

Constructor Details

#initialize(type, operand, the_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, the_constants)
  @type = type
  @operand = operand
  @the_constants = the_constants
end

Instance Method Details

#_countObject



60
61
62
# File 'lib/bmg/operator/constants.rb', line 60

def _count
  operand._count
end

#delete(predicate = Predicate.tautology) ⇒ Object



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

def delete(predicate = Predicate.tautology)
  operand.delete(predicate)
end

#eachObject



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

def each
  return to_enum unless block_given?
  @operand.each do |tuple|
    yield extend_it(tuple)
  end
end

#insert(arg) ⇒ Object



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

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

#to_astObject



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

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

#update(tuple, predicate = Predicate.tautology) ⇒ Object

Raises:



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

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