class ActiveRecord::ConnectionAdapters::KuduAdapter

Main Impala connection adapter class

Constants

ADAPTER_NAME
NATIVE_DATABASE_TYPES

Attributes

connection[R]

@!attribute [r] connection

@return [::Impala::Connection] Connection which we are working on

Public Class Methods

new(connection, logger, connection_params) click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 74
def initialize(connection, logger, connection_params)
  super(connection, logger)

  @connection_params = connection_params
  connect
  @visitor = ::KuduAdapter::BindSubstition.new self
end

Public Instance Methods

active?() click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 104
def active?
  @connection.execute('SELECT now()')
  true
rescue
  false
end
connect() click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 82
def connect
  @connection = ::Impala.connect(
    @connection_params[:host],
    @connection_params[:port]
  )

  db_names = @connection.query('SHOW DATABASES').map {|db| db[:name]}

  @connection.execute('USE ' + @connection_params[:database]) if
    @connection_params[:database].present? && db_names.include?(@connection_params[:database])
end
create_database(database_name) click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 167
def create_database(database_name)
  # TODO: escape name
  execute "CREATE DATABASE IF NOT EXISTS `#{database_name}`"
end
disconnect!() click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 94
def disconnect!
  @connection.close if @connection.open?
  @connection = nil
end
execute(sql, name = nil) click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 111
def execute(sql, name = nil)
  with_auto_reconnect do
    log(sql, name) { @connection.execute(sql) }
  end
end
initialize_type_map(mapping) click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 145
def initialize_type_map(mapping)
  mapping.register_type(/bigint/i, ::ActiveRecord::ConnectionAdapters::Kudu::Type::BigInt.new)
  mapping.register_type(/boolean/i, ::ActiveRecord::ConnectionAdapters::Kudu::Type::Boolean.new)
  mapping.register_type(/char/i, ::ActiveRecord::ConnectionAdapters::Kudu::Type::Char.new)
  mapping.register_type(/datetime/i, ::ActiveRecord::ConnectionAdapters::Kudu::Type::DateTime.new)
  mapping.register_type(/double/i, ::ActiveRecord::ConnectionAdapters::Kudu::Type::Double.new)
  mapping.register_type(/float/i, ::ActiveRecord::ConnectionAdapters::Kudu::Type::Float.new)
  mapping.register_type(/integer/i, ::ActiveRecord::ConnectionAdapters::Kudu::Type::Integer.new)
  mapping.register_type(/smallint/i, ::ActiveRecord::ConnectionAdapters::Kudu::Type::SmallInt.new)
  mapping.register_type(/string/i, ::ActiveRecord::ConnectionAdapters::Kudu::Type::String.new)
  mapping.register_type(/(date){0}time/i, ::ActiveRecord::ConnectionAdapters::Kudu::Type::Time.new)
  mapping.register_type(/tinyint/i, ::ActiveRecord::ConnectionAdapters::Kudu::Type::TinyInt.new)
end
lookup_cast_type_from_column(column) click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 125
def lookup_cast_type_from_column(column)
  lookup_cast_type column.type.to_s
end
native_database_types() click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 141
def native_database_types
  ::ActiveRecord::ConnectionAdapters::KuduAdapter::NATIVE_DATABASE_TYPES
end
query(sql, name = nil) click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 117
def query(sql, name = nil)
  with_auto_reconnect do
    log(sql, name) do
      @connection.query sql
    end
  end
end
reconnect!() click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 99
def reconnect!
  disconnect!
  connect
end
supports_migrations?() click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 129
def supports_migrations?
  true
end
supports_multi_insert?() click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 133
def supports_multi_insert?
  false
end
supports_primary_key?() click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 137
def supports_primary_key?
  true
end
with_auto_reconnect() { || ... } click to toggle source
# File lib/active_record/connection_adapters/kudu_adapter.rb, line 159
def with_auto_reconnect
  yield
rescue Thrift::TransportException => e
  raise unless e.message == 'end of file reached'
  reconnect!
  yield
end