Class: ConceptQL::Operators::Complement
- Defined in:
- lib/conceptql/operators/complement.rb
Constant Summary
Constants inherited from Operator
Instance Attribute Summary
Attributes inherited from Operator
#arguments, #options, #upstreams, #values
Instance Method Summary collapse
- #query(db) ⇒ Object
-
#query2(db) ⇒ Object
This is an alternate, but equally accurate way to do complement.
Methods inherited from PassThru
Methods inherited from Operator
#columns, #evaluate, #initialize, #label, #select_it, #set_values, #sql, #stream, #types
Methods included from Metadatable
#allows_many_upstreams, #allows_one_upstream, #argument, #category, #desc, #humanized_class_name, #inherited, #just_class_name, #option, #predominant_types, #preferred_name, #reset_categories, #to_metadata, #types
Constructor Details
This class inherits a constructor from ConceptQL::Operators::Operator
Instance Method Details
#query(db) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/conceptql/operators/complement.rb', line 10 def query(db) upstream = upstreams.first upstream.types.map do |type| positive_query = db.from(upstream.evaluate(db)) .select(:criterion_id) .exclude(:criterion_id => nil) .where(:criterion_type => type.to_s) query = db.from(make_table_name(type)) .exclude(make_type_id(type) => positive_query) db.from(select_it(query, type)) end.inject do |union_query, q| union_query.union(q, all: true) end end |
#query2(db) ⇒ Object
This is an alternate, but equally accurate way to do complement. We’ll need to benchmark which is faster.
28 29 30 31 32 33 34 35 |
# File 'lib/conceptql/operators/complement.rb', line 28 def query2(db) upstream = upstreams.first froms = upstream.types.map do |type| select_it(db.from(make_table_name(type)), type) end big_from = froms.inject { |union_query, q| union_query.union(q, all:true) } db.from(big_from).except(upstream.evaluate(db)) end |