Class: RSpec::Hive::ConnectionDelegator
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- RSpec::Hive::ConnectionDelegator
- Defined in:
- lib/rspec/hive/connection_delegator.rb
Instance Method Summary collapse
- #create_database(name) ⇒ Object
- #create_table(table_schema) ⇒ Object
- #drop_database(name) ⇒ Object
-
#initialize(connection, config) ⇒ ConnectionDelegator
constructor
A new instance of ConnectionDelegator.
- #load_into_table(table_schema, values, partitions = nil) ⇒ Object
- #load_partitions(table_name, partitions) ⇒ Object
- #show_databases ⇒ Object
- #show_tables ⇒ Object
- #switch_database(db_name) ⇒ Object
- #use_database(name) ⇒ Object
Constructor Details
#initialize(connection, config) ⇒ ConnectionDelegator
Returns a new instance of ConnectionDelegator.
7 8 9 10 |
# File 'lib/rspec/hive/connection_delegator.rb', line 7 def initialize(connection, config) super(connection) @config = config end |
Instance Method Details
#create_database(name) ⇒ Object
45 46 47 |
# File 'lib/rspec/hive/connection_delegator.rb', line 45 def create_database(name) execute("CREATE DATABASE IF NOT EXISTS `#{name}`") end |
#create_table(table_schema) ⇒ Object
12 13 14 15 16 |
# File 'lib/rspec/hive/connection_delegator.rb', line 12 def create_table(table_schema) table_schema = table_schema.dup table_schema.instance_variable_set(:@location, nil) execute(table_schema.create_table_statement) end |
#drop_database(name) ⇒ Object
53 54 55 |
# File 'lib/rspec/hive/connection_delegator.rb', line 53 def drop_database(name) execute("DROP DATABASE `#{name}`") end |
#load_into_table(table_schema, values, partitions = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rspec/hive/connection_delegator.rb', line 24 def load_into_table(table_schema, values, partitions = nil) table_name = table_schema.name Tempfile.open(table_name, @config.host_shared_directory_path) do |file| write_values_to_file( file, values, table_schema.instance_variable_get(:@field_sep) ) partition_query = partition_clause(partitions) if partitions load_file_to_hive_table( table_name, docker_path(file), partition_query ) end end |
#load_partitions(table_name, partitions) ⇒ Object
18 19 20 21 22 |
# File 'lib/rspec/hive/connection_delegator.rb', line 18 def load_partitions(table_name, partitions) partitions = partition_clause(partitions) query = "ALTER TABLE #{table_name} ADD #{partitions}" execute(query) end |
#show_databases ⇒ Object
57 58 59 |
# File 'lib/rspec/hive/connection_delegator.rb', line 57 def show_databases fetch('SHOW DATABASES') end |
#show_tables ⇒ Object
41 42 43 |
# File 'lib/rspec/hive/connection_delegator.rb', line 41 def show_tables fetch('SHOW TABLES') end |
#switch_database(db_name) ⇒ Object
61 62 63 64 |
# File 'lib/rspec/hive/connection_delegator.rb', line 61 def switch_database(db_name) create_database(db_name) use_database(db_name) end |
#use_database(name) ⇒ Object
49 50 51 |
# File 'lib/rspec/hive/connection_delegator.rb', line 49 def use_database(name) execute("USE `#{name}`") end |