Class: Bmg::Operator::Allbut

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

Overview

Allbut operator.

Projects operand’s tuples on all but given attributes, that is, removes attributes in the list. The operator takes care of removing duplicates.

Example:

[{ a: 1, b: 2 }] allbut [:b] => [{ a: 1 }]

All attributes in the butlist SHOULD be existing attributes of the input tuples.

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, #constants, #extend, #image, #matching, #project, #rename, #restrict, #spied, #union, #unspied

Constructor Details

#initialize(type, operand, butlist) ⇒ Allbut

Returns a new instance of Allbut.



20
21
22
23
24
# File 'lib/bmg/operator/allbut.rb', line 20

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

Instance Method Details

#deleteObject



56
57
58
# File 'lib/bmg/operator/allbut.rb', line 56

def delete
  operand.delete
end

#eachObject



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

def each
  seen = {}
  @operand.each do |tuple|
    allbuted = tuple_allbut(tuple)
    unless seen.has_key?(allbuted)
      yield(allbuted)
      seen[allbuted] = true
    end
  end
end

#insert(arg) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/bmg/operator/allbut.rb', line 43

def insert(arg)
  case arg
  when Hash       then operand.insert(valid_tuple!(arg))
  when Enumerable then operand.insert(arg.map{|t| valid_tuple!(t) })
  else
    super
  end
end

#to_astObject



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

def to_ast
  [:allbut, operand.to_ast, butlist.dup]
end

#update(tuple) ⇒ Object



52
53
54
# File 'lib/bmg/operator/allbut.rb', line 52

def update(tuple)
  operand.update(valid_tuple!(tuple))
end