Class: Piglet::Relation::Stream

Inherits:
Object
  • Object
show all
Includes:
Relation
Defined in:
lib/piglet/relation/stream.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(source, interpreter, args, options = nil) ⇒ Stream

Returns a new instance of Stream.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/piglet/relation/stream.rb', line 8

def initialize(source, interpreter, args, options=nil)
  @interpreter = interpreter
  options ||= {}
  @sources = [source]
  args.each do |arg|
    @sources << arg if arg.is_a?(Relation) || arg.is_a?(Array)
  end
  @command_reference = (args - @sources).first
  @sources = @sources.flatten
  @command = options[:command]
  @schema = options[:schema]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Piglet::Relation::Relation

Instance Method Details

#schemaObject



21
22
23
24
25
26
27
# File 'lib/piglet/relation/stream.rb', line 21

def schema
  if @schema
    Piglet::Schema::Tuple.parse(@schema)
  else
    nil
  end
end

#to_sObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/piglet/relation/stream.rb', line 29

def to_s
  source_str = @sources.map { |s| s.alias }.join(', ')
  str = "STREAM #{source_str} THROUGH"
  if @command_reference
    str << " #{@command_reference}" 
  else
    str << " `#{@command}`"
  end
  if @schema
    str << " AS #{schema}"
  end
  str
end