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_schema, 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.
9 10 11 12 |
# File 'lib/rspec/hive/connection_delegator.rb', line 9 def initialize(connection, config) super(connection) @config = config end |
Instance Method Details
#create_database(name) ⇒ Object
47 48 49 |
# File 'lib/rspec/hive/connection_delegator.rb', line 47 def create_database(name) execute("CREATE DATABASE IF NOT EXISTS `#{name}`") end |
#create_table(table_schema) ⇒ Object
14 15 16 17 18 |
# File 'lib/rspec/hive/connection_delegator.rb', line 14 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
55 56 57 |
# File 'lib/rspec/hive/connection_delegator.rb', line 55 def drop_database(name) execute("DROP DATABASE `#{name}`") end |
#load_into_table(table_schema, values, partitions = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rspec/hive/connection_delegator.rb', line 26 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(table_schema, partitions) if partitions load_file_to_hive_table( table_name, docker_path(file), partition_query ) end end |
#load_partitions(table_schema, partitions) ⇒ Object
20 21 22 23 24 |
# File 'lib/rspec/hive/connection_delegator.rb', line 20 def load_partitions(table_schema, partitions) partitions = partition_clause(table_schema, partitions) query = "ALTER TABLE #{table_schema.name} ADD #{partitions}" execute(query) end |
#show_databases ⇒ Object
59 60 61 |
# File 'lib/rspec/hive/connection_delegator.rb', line 59 def show_databases fetch('SHOW DATABASES') end |
#show_tables ⇒ Object
43 44 45 |
# File 'lib/rspec/hive/connection_delegator.rb', line 43 def show_tables fetch('SHOW TABLES') end |
#switch_database(db_name) ⇒ Object
63 64 65 66 |
# File 'lib/rspec/hive/connection_delegator.rb', line 63 def switch_database(db_name) create_database(db_name) use_database(db_name) end |
#use_database(name) ⇒ Object
51 52 53 |
# File 'lib/rspec/hive/connection_delegator.rb', line 51 def use_database(name) execute("USE `#{name}`") end |