Class: Piglet::Relation::Join

Inherits:
Object
  • Object
show all
Includes:
Relation
Defined in:
lib/piglet/relation/join.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes included from Relation

#sources

Instance Method Summary collapse

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

#schemaObject



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_sObject



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