class Sequel::Impala::Database
Constants
- DatasetClass
- DisconnectExceptions
- ImpalaExceptions
Exception classes used by
Impala
.
Public Instance Methods
connect(server)
click to toggle source
Connect to the Impala
server. Currently, only the :host and :port options are respected, and they default to 'localhost' and 21000, respectively.
# File lib/sequel/adapters/impala.rb 30 def connect(server) 31 opts = server_opts(server) 32 ::Impala.connect(opts[:host]||'localhost', (opts[:port]||21000).to_i, opts) 33 end
database_error_classes()
click to toggle source
# File lib/sequel/adapters/impala.rb 35 def database_error_classes 36 ImpalaExceptions 37 end
disconnect_connection(c)
click to toggle source
# File lib/sequel/adapters/impala.rb 39 def disconnect_connection(c) 40 c.close 41 rescue *DisconnectExceptions 42 end
execute(sql, opts=OPTS) { |cursor| ... }
click to toggle source
# File lib/sequel/adapters/impala.rb 44 def execute(sql, opts=OPTS) 45 synchronize(opts[:server]) do |c| 46 begin 47 cursor = record_query_id(opts) do 48 log_yield(sql) do 49 c.execute(sql){} 50 end 51 end 52 yield cursor if block_given? 53 nil 54 rescue *ImpalaExceptions => e 55 puts $!.message 56 puts $!.backtrace.join("\n") 57 raise_error(e) 58 rescue 59 puts $!.message 60 puts $!.backtrace.join("\n") 61 raise 62 ensure 63 record_profile(cursor, opts) 64 cursor.close if cursor && cursor.open? 65 end 66 end 67 end
profile_for(profile_name=:default)
click to toggle source
# File lib/sequel/adapters/impala.rb 69 def profile_for(profile_name=:default) 70 Sequel.synchronize{@runtime_profiles[profile_name]} 71 end
query_id_for(query_id_name=:default)
click to toggle source
# File lib/sequel/adapters/impala.rb 73 def query_id_for(query_id_name=:default) 74 Sequel.synchronize{@query_ids[query_id_name]} 75 end
Private Instance Methods
adapter_initialize()
click to toggle source
# File lib/sequel/adapters/impala.rb 98 def adapter_initialize 99 @runtime_profiles = {} 100 @query_ids = {} 101 end
connection_execute_method()
click to toggle source
# File lib/sequel/adapters/impala.rb 103 def connection_execute_method 104 :query 105 end
disconnect_error?(exception, opts)
click to toggle source
Impala
raises IOError if it detects a problem on the connection, and in most cases that results in an unusable connection, so treat it as a disconnect error so Sequel
will reconnect.
Calls superclass method
# File lib/sequel/adapters/impala.rb 110 def disconnect_error?(exception, opts) 111 case exception 112 when *DisconnectExceptions 113 true 114 else 115 super 116 end 117 end
record_profile(cursor, opts)
click to toggle source
# File lib/sequel/adapters/impala.rb 79 def record_profile(cursor, opts) 80 if cursor && profile_name = opts[:profile_name] 81 profile = cursor.runtime_profile 82 Sequel.synchronize{@runtime_profiles[profile_name] = profile} 83 end 84 end
record_query_id(opts = OPTS) { || ... }
click to toggle source
# File lib/sequel/adapters/impala.rb 86 def record_query_id(opts = OPTS) 87 start = Time.now if opts[:query_id_name] 88 89 cursor = yield 90 91 if cursor && query_id_name = opts[:query_id_name] 92 Sequel.synchronize{ @query_ids[query_id_name] = { query_id: cursor.handle.id, start_time: start } } 93 end 94 95 cursor 96 end
schema_parse_table(table_name, opts)
click to toggle source
Use DESCRIBE to get the column names and types for the table.
# File lib/sequel/adapters/impala.rb 120 def schema_parse_table(table_name, opts) 121 m = output_identifier_meth(opts[:dataset]) 122 123 table = if opts[:schema] 124 Sequel.qualify(opts[:schema], table_name) 125 else 126 Sequel.identifier(table_name) 127 end 128 129 describe(table, opts).map do |row| 130 row[:db_type] = row[:type] 131 row[:type] = schema_column_type(row[:db_type]) 132 row[:default] = nil 133 row[:primary_key] = false 134 [m.call(row.delete(:name)), row] 135 end 136 end