class Bmg::Operator::Project
Project
operator.
Projects operand's tuples on given attributes, that is, keep those attributes only. The operator takes care of removing duplicates.
Example:
[{ a: 1, b: 2 }] project [:b] => [{ b: 2 }]
All attributes in the attrlist SHOULD be existing attributes of the input tuples.
Attributes
attrlist[R]
Public Class Methods
new(type, operand, attrlist)
click to toggle source
# File lib/bmg/operator/project.rb, line 19 def initialize(type, operand, attrlist) @type = type @operand = operand @attrlist = attrlist end
Public Instance Methods
delete()
click to toggle source
# File lib/bmg/operator/project.rb, line 56 def delete operand.delete end
each() { |projected| ... }
click to toggle source
# File lib/bmg/operator/project.rb, line 31 def each return to_enum unless block_given? seen = {} @operand.each do |tuple| projected = tuple_project(tuple) unless seen.has_key?(projected) yield(projected) seen[projected] = true end end end
insert(arg)
click to toggle source
Calls superclass method
# File lib/bmg/operator/project.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_ast()
click to toggle source
# File lib/bmg/operator/project.rb, line 60 def to_ast [ :project, operand.to_ast, attrlist ] end
update(tuple)
click to toggle source
# File lib/bmg/operator/project.rb, line 52 def update(tuple) operand.update(valid_tuple!(tuple)) end