Class: HipsterSqlToHbase::Executor

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

Overview

This class takes the magic provided by the ThriftCallGroup and turns it into an HBase reality by opening a connection to a specified host and port and executing the pertinent Thrift calls.

Constant Summary collapse

@@host =
nil
@@port =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.hostObject

Get class variable host when NOT instantiated.



26
27
28
# File 'lib/executor.rb', line 26

def self.host
  @@host
end

.host=(host_s) ⇒ Object

Set class variable host when NOT instantiated.



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

def self.host=(host_s)
  @@host=host_s
end

.portObject

Get class variable port when NOT instantiated.



46
47
48
# File 'lib/executor.rb', line 46

def self.port
  @@port
end

.port=(port_n) ⇒ Object

Set class variable port when NOT instantiated.



41
42
43
# File 'lib/executor.rb', line 41

def self.port=(port_n)
  @@port=port_n
end

Instance Method Details

#execute(thrift_call_group, host_s = nil, port_n = nil, incr = false) ⇒ Object

Initialize a Thrift connection to the specified host and port and execute the provided ThriftCallGroup object.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/executor.rb', line 52

def execute(thrift_call_group,host_s=nil,port_n=nil,incr=false)
  @@host = host_s if !host_s.nil?
  @@port = port_n if !port_n.nil?
  socket = Thrift::Socket.new(@@host, @@port)

  transport = Thrift::BufferedTransport.new(socket)
  transport.open

  protocol = Thrift::BinaryProtocol.new(transport)
  client = HBase::Client.new(protocol)
  
  results = []
  
  if incr
    not_incr = true
    c_row = 0
  end
  
  thrift_call_group.each do |thrift_call|
    if incr
      if not_incr
        c_row = increment_table_row_index(thrift_call[:arguments][0],thrift_call_group.length,client) 
        not_incr = false
      end
      c_row += 1
      thrift_call[:arguments][1] = c_row.to_s 
    end
    results << client.send(thrift_call[:method],*thrift_call[:arguments])
  end
  
  results.flatten
end

#hostObject

Get class variable host when instantiated.



16
17
18
# File 'lib/executor.rb', line 16

def host
  self.class.host
end

#host=(host_s) ⇒ Object

Set class variable host when instantiated.



11
12
13
# File 'lib/executor.rb', line 11

def host=(host_s)
  self.class.host=host_s
end

#portObject

Get class variable port when instantiated.



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

def port
  self.class.port
end

#port=(port_n) ⇒ Object

Set class variable port when instantiated.



31
32
33
# File 'lib/executor.rb', line 31

def port=(port_n)
  self.class.port=port_n
end