Class: Tem::Mr::Search::MapReduceJob

Inherits:
Object
  • Object
show all
Defined in:
lib/tem_mr_search/map_reduce_job.rb

Overview

Expresses a Map-Reduce computation whose components are performed on TEMs.

Client code should put together Map-Reduce computations using QueryBuilder or similar builder classes. In turn, builders construct and return MapReduceJob instances.

Jobs can be serialized to a hash for network transmission. To de-serialize a job, pass the hash to the hash constructor:

hash = job.to_hash
job = MapReduceJob.new hash

Direct Known Subclasses

ClientQuery, WebClientQueryBuilder

Defined Under Namespace

Classes: Finalizer, JobPart, Mapper, Reducer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ MapReduceJob

Returns a new instance of MapReduceJob.



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

def initialize(attributes)
  @attributes = attributes[:attributes]
  @id_attribute = attributes[:id_attribute]

  @mapper = Mapper.new attributes[:map], self
  @reducer = Reducer.new attributes[:reduce], self
  @finalizer = Finalizer.new attributes[:finalize], self
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



21
22
23
# File 'lib/tem_mr_search/map_reduce_job.rb', line 21

def attributes
  @attributes
end

#finalizerObject (readonly)

Returns the value of attribute finalizer.



21
22
23
# File 'lib/tem_mr_search/map_reduce_job.rb', line 21

def finalizer
  @finalizer
end

#id_attributeObject (readonly)

Returns the value of attribute id_attribute.



21
22
23
# File 'lib/tem_mr_search/map_reduce_job.rb', line 21

def id_attribute
  @id_attribute
end

#mapperObject (readonly)

Returns the value of attribute mapper.



21
22
23
# File 'lib/tem_mr_search/map_reduce_job.rb', line 21

def mapper
  @mapper
end

#reducerObject (readonly)

Returns the value of attribute reducer.



21
22
23
# File 'lib/tem_mr_search/map_reduce_job.rb', line 21

def reducer
  @reducer
end

Instance Method Details

#bind(tem_pubeks) ⇒ Object

Binds the SECpacks in this job to the given keys.

Args:

tem_pubeks:: the public keys to bind the SECpacks to; hash with the keys
             +:mapper+, +:reducer+ and +:finalizer+; each key is mapped to
             a TEM key


57
58
59
60
61
# File 'lib/tem_mr_search/map_reduce_job.rb', line 57

def bind(tem_pubeks)
  @mapper.bind tem_pubeks[:mapper]
  @reducer.bind tem_pubeks[:reducer]
  @finalizer.bind tem_pubeks[:finalizer]
end

#to_hashObject

Serializes a job to a hash.

Useful in conjunction with ObjectProtocol in ZergSupport, for sending jobs across the wire. De-serialize with MapReduceJob#new



45
46
47
48
49
# File 'lib/tem_mr_search/map_reduce_job.rb', line 45

def to_hash
  { :attributes => @attributes, :id_attribute => @id_attribute,
    :map => @mapper.to_plain_object, :reduce => @reducer.to_plain_object,
    :finalize => @finalizer.to_plain_object }
end

#unpack_decrypted_output(output) ⇒ Object

Unpacks a decrypted output into its components.



33
34
35
36
37
38
39
# File 'lib/tem_mr_search/map_reduce_job.rb', line 33

def unpack_decrypted_output(output)
  {
    :id => output[0, 8].reverse.pack('C*').unpack('q').first,
    :score => Tem::Abi.read_tem_short(output, 8),
    :check => output[13, 10]
  }
end