Class: Bmg::Operator::Project
- Inherits:
-
Object
- Object
- Bmg::Operator::Project
- Includes:
- Unary
- Defined in:
- lib/bmg/operator/project.rb
Overview
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.
Instance Attribute Summary
Attributes included from Bmg::Operator
Instance Method Summary collapse
- #delete ⇒ Object
- #each ⇒ Object
-
#initialize(type, operand, attrlist) ⇒ Project
constructor
A new instance of Project.
- #insert(arg) ⇒ Object
- #to_ast ⇒ Object
- #update(tuple) ⇒ Object
Methods included from Unary
Methods included from Bmg::Operator
Methods included from Relation
#bind, #debug, empty, #empty?, new, #one, #one_or_nil, #to_csv, #to_json, #visit, #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, #rename, #restrict, #spied, #summarize, #transform, #union, #unspied
Methods included from Algebra::Shortcuts
#image, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix
Constructor Details
#initialize(type, operand, attrlist) ⇒ Project
19 20 21 22 23 |
# File 'lib/bmg/operator/project.rb', line 19 def initialize(type, operand, attrlist) @type = type @operand = operand @attrlist = attrlist end |
Instance Method Details
#delete ⇒ Object
55 56 57 |
# File 'lib/bmg/operator/project.rb', line 55 def delete operand.delete end |
#each ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bmg/operator/project.rb', line 31 def each seen = {} @operand.each do |tuple| projected = project(tuple) unless seen.has_key?(projected) yield(projected) seen[projected] = true end end end |
#insert(arg) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/bmg/operator/project.rb', line 42 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 ⇒ Object
59 60 61 |
# File 'lib/bmg/operator/project.rb', line 59 def to_ast [ :project, operand.to_ast, attrlist ] end |
#update(tuple) ⇒ Object
51 52 53 |
# File 'lib/bmg/operator/project.rb', line 51 def update(tuple) operand.update(valid_tuple!(tuple)) end |