Class: Hog::Tuple

Inherits:
Object
  • Object
show all
Defined in:
lib/hog/tuple.rb

Constant Summary collapse

SCHEMAS =
{
  :udf => UdfSchema.new,
  :pig => PigSchema.new,
  :hive => HiveSchema.new
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, block) ⇒ Tuple

Returns a new instance of Tuple.



17
18
19
20
21
# File 'lib/hog/tuple.rb', line 17

def initialize(name, block)
  @name = name
  @fields = []
  self.instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/hog/tuple.rb', line 44

def method_missing(meth, *args, &block)
  if [:chararray, :float, :double, :int, :long, :map].include?(meth)
    f = Field.new(meth.to_s, *args)
    @fields << f
    return f
  else
    super
  end
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



7
8
9
# File 'lib/hog/tuple.rb', line 7

def fields
  @fields
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/hog/tuple.rb', line 8

def name
  @name
end

Instance Method Details

#prepare(&block) ⇒ Object



32
33
34
# File 'lib/hog/tuple.rb', line 32

def prepare(&block)
  @prepare = block
end

#process(hsh) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/hog/tuple.rb', line 23

def process(hsh)
  @prepare.call(hsh)
  res = []
  @fields.each do |f|
    res << f.get(hsh)
  end
  res
end

#schema(kind = :udf) ⇒ Object



40
41
42
# File 'lib/hog/tuple.rb', line 40

def schema(kind=:udf)
  SCHEMAS[kind].schema(self)
end

#to_sObject



36
37
38
# File 'lib/hog/tuple.rb', line 36

def to_s
  "(#{@fields.map{|f| f.to_s }.join(',')})"
end