Class: Sequel::Hive::Database
- Inherits:
-
Database
- Object
- Database
- Sequel::Hive::Database
- Defined in:
- lib/sequel/adapters/hive.rb
Instance Method Summary collapse
- #connect(server) ⇒ Object
- #dataset(opts = nil) ⇒ Object
- #execute(sql, opts = {}) ⇒ Object (also: #do)
-
#schema(table, opts = {}) ⇒ Object
Returns the schema for the given table as an array with all members being arrays of length 2, the first member being the column name, and the second member being a hash of column information.
-
#tables(opts = {}) ⇒ Object
Returns a list of tables as symbols.
Instance Method Details
#connect(server) ⇒ Object
10 11 12 13 |
# File 'lib/sequel/adapters/hive.rb', line 10 def connect(server) opts = server_opts(server) RBHive::Connection.new(opts[:host], opts[:port] || 10_000) end |
#dataset(opts = nil) ⇒ Object
15 16 17 |
# File 'lib/sequel/adapters/hive.rb', line 15 def dataset(opts = nil) Hive::Dataset.new(self, opts) end |
#execute(sql, opts = {}) ⇒ Object Also known as: do
19 20 21 22 23 24 25 26 |
# File 'lib/sequel/adapters/hive.rb', line 19 def execute(sql, opts={}) synchronize(opts[:server]) do |conn| conn.open r = log_yield(sql){conn.fetch(sql)} yield(r) if block_given? r end end |
#schema(table, opts = {}) ⇒ Object
Returns the schema for the given table as an array with all members being arrays of length 2, the first member being the column name, and the second member being a hash of column information.
34 35 36 37 38 39 |
# File 'lib/sequel/adapters/hive.rb', line 34 def schema(table, opts={}) hero = execute("DESCRIBE #{table}") hero.map do |h| [ h[:col_name].to_sym, { :db_type => h[:data_type] , :comment => h[:comment] } ] end end |
#tables(opts = {}) ⇒ Object
Returns a list of tables as symbols.
44 45 46 |
# File 'lib/sequel/adapters/hive.rb', line 44 def tables(opts={}) execute('SHOW TABLES').map{|i| i.values}.reduce(:+).map{|i| i.to_sym} end |