Class: ActiveRecordHiveAdapter::HiveConnector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, database, timeout) ⇒ HiveConnector

Returns a new instance of HiveConnector.



6
7
8
9
10
11
12
# File 'lib/activerecord_hive_adapter/hive_connector.rb', line 6

def initialize(host, port, database, timeout)
  socket = Thrift::Socket.new(host, port, timeout)
  @transport = Thrift::BufferedTransport.new(socket)
  protocol = Thrift::BinaryProtocol.new(@transport)
  @client = ThriftHive::Client.new(protocol)
  open(database)
end

Instance Attribute Details

#databaseObject

Returns the value of attribute database.



4
5
6
# File 'lib/activerecord_hive_adapter/hive_connector.rb', line 4

def database
  @database
end

Instance Method Details

#closeObject



24
25
26
# File 'lib/activerecord_hive_adapter/hive_connector.rb', line 24

def close
  @transport.close rescue IOError
end

#execute(sql) ⇒ Object



32
33
34
# File 'lib/activerecord_hive_adapter/hive_connector.rb', line 32

def execute(sql)
  @client.execute(sql)
end

#fetch_allObject



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

def fetch_all
  @client.fetchAll()
end

#get_schemaObject



40
41
42
# File 'lib/activerecord_hive_adapter/hive_connector.rb', line 40

def get_schema
  @client.getSchema()
end

#open(database) ⇒ Object



14
15
16
17
# File 'lib/activerecord_hive_adapter/hive_connector.rb', line 14

def open(database)
  @transport.open
  self.database = database
end

#open?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/activerecord_hive_adapter/hive_connector.rb', line 28

def open?
  @transport.open?
end

#reconnect!Object



19
20
21
22
# File 'lib/activerecord_hive_adapter/hive_connector.rb', line 19

def reconnect!
  close
  open(self.database)
end