Class: Piglet::Relation::Join
- Inherits:
-
Object
- Object
- Piglet::Relation::Join
- Includes:
- Relation
- Defined in:
- lib/piglet/relation/join.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes included from Relation
Instance Method Summary collapse
-
#initialize(relation, interpreter, description) ⇒ Join
constructor
A new instance of Join.
- #schema ⇒ Object
- #to_s ⇒ Object
Methods included from Relation
#[], #alias, #cogroup, #cross, #distinct, #eql?, #field, #filter, #foreach, #group, #hash, #join, #limit, #method_missing, #nested_foreach, #next_field_alias, #order, #sample, #split, #stream, #union
Constructor Details
#initialize(relation, interpreter, description) ⇒ Join
Returns a new instance of Join.
8 9 10 11 12 13 14 |
# File 'lib/piglet/relation/join.rb', line 8 def initialize(relation, interpreter, description) @interpreter = interpreter @join_fields = Hash[*description.select { |k, v| k.is_a?(Relation) }.flatten] @sources = @join_fields.keys @using = description[:using] @parallel = description[:parallel] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Piglet::Relation::Relation
Instance Method Details
#schema ⇒ Object
16 17 18 19 |
# File 'lib/piglet/relation/join.rb', line 16 def schema schemas = @sources.map { |s| s.schema } schemas.first.union(schemas[1..-1]) end |
#to_s ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/piglet/relation/join.rb', line 21 def to_s joins = @sources.map { |s| "#{s.alias} BY #{@join_fields[s]}" }.join(', ') str = "JOIN #{joins}" str << " USING \"#{@using.to_s}\"" if @using str << " PARALLEL #{@parallel}" if @parallel str end |