Class: RBHive::Connection
- Inherits:
-
Object
- Object
- RBHive::Connection
show all
- Defined in:
- lib/rbhive/connection.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(server, port = 10_000, logger = StdOutLogger.new) ⇒ Connection
Returns a new instance of Connection.
28
29
30
31
32
33
34
35
|
# File 'lib/rbhive/connection.rb', line 28
def initialize(server, port=10_000, logger=StdOutLogger.new)
@socket = Thrift::Socket.new(server, port)
@transport = Thrift::BufferedTransport.new(@socket)
@protocol = Thrift::BinaryProtocol.new(@transport)
@client = ThriftHive::Client.new(@protocol)
@logger = logger
@logger.info("Connecting to #{server} on port #{port}")
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
81
82
83
|
# File 'lib/rbhive/connection.rb', line 81
def method_missing(meth, *args)
client.send(meth, *args)
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
26
27
28
|
# File 'lib/rbhive/connection.rb', line 26
def client
@client
end
|
Instance Method Details
#add_columns(schema) ⇒ Object
77
78
79
|
# File 'lib/rbhive/connection.rb', line 77
def add_columns(schema)
execute(schema.add_columns_statement)
end
|
#close ⇒ Object
41
42
43
|
# File 'lib/rbhive/connection.rb', line 41
def close
@transport.close
end
|
#create_table(schema) ⇒ Object
64
65
66
|
# File 'lib/rbhive/connection.rb', line 64
def create_table(schema)
execute(schema.create_table_statement)
end
|
#drop_table(name) ⇒ Object
68
69
70
71
|
# File 'lib/rbhive/connection.rb', line 68
def drop_table(name)
name = name.name if name.is_a?(TableSchema)
execute("DROP TABLE `#{name}`")
end
|
#execute(query) ⇒ Object
49
50
51
52
|
# File 'lib/rbhive/connection.rb', line 49
def execute(query)
@logger.info("Executing Hive Query: #{query}")
client.execute(query)
end
|
#fetch(query) ⇒ Object
54
55
56
57
|
# File 'lib/rbhive/connection.rb', line 54
def fetch(query)
execute(query)
ResultSet.new(client.fetchAll)
end
|
#first(query) ⇒ Object
59
60
61
62
|
# File 'lib/rbhive/connection.rb', line 59
def first(query)
execute(query)
ResultSet.new([client.fetchOne])
end
|
#open ⇒ Object
37
38
39
|
# File 'lib/rbhive/connection.rb', line 37
def open
@transport.open
end
|
#replace_columns(schema) ⇒ Object
73
74
75
|
# File 'lib/rbhive/connection.rb', line 73
def replace_columns(schema)
execute(schema.replace_columns_statement)
end
|