class RSpec::Hive::QueryBuilder

Attributes

connection[RW]
partition_hash[RW]
rows[RW]
schema[R]
stubbing[RW]

Public Class Methods

new(schema, connection) click to toggle source
# File lib/rspec/hive/query_builder.rb, line 10
def initialize(schema, connection)
  @schema = schema
  @connection = connection
  @partition_hash = {}
  @rows = []
  @stubbing = false
end

Public Instance Methods

execute() click to toggle source
# File lib/rspec/hive/query_builder.rb, line 36
def execute
  if partition_hash.empty?
    connection.load_into_table(schema, transformed_rows)
  else
    connection.load_into_table(schema, transformed_rows, partition_hash)
  end
end
insert(*new_rows) click to toggle source
# File lib/rspec/hive/query_builder.rb, line 27
def insert(*new_rows)
  spawn.insert!(new_rows)
end
insert!(new_rows) click to toggle source
# File lib/rspec/hive/query_builder.rb, line 31
def insert!(new_rows)
  rows.concat(new_rows)
  self
end
partition(hash) click to toggle source
# File lib/rspec/hive/query_builder.rb, line 18
def partition(hash)
  spawn.partition!(hash)
end
partition!(partition) click to toggle source
# File lib/rspec/hive/query_builder.rb, line 22
def partition!(partition)
  partition_hash.merge!(partition)
  self
end
with_stubbing() click to toggle source
# File lib/rspec/hive/query_builder.rb, line 44
def with_stubbing
  spawn.with_stubbing!
end
with_stubbing!() click to toggle source
# File lib/rspec/hive/query_builder.rb, line 48
def with_stubbing!
  self.stubbing = true
  self
end

Private Instance Methods

missing_column_strategy() click to toggle source
# File lib/rspec/hive/query_builder.rb, line 76
def missing_column_strategy
  if stubbing?
    ValueByTypeStrategy.new
  else
    NullStrategy.new
  end
end
spawn() click to toggle source
# File lib/rspec/hive/query_builder.rb, line 61
def spawn
  clone
end
stubbing?() click to toggle source
# File lib/rspec/hive/query_builder.rb, line 65
def stubbing?
  stubbing
end
transformed_rows() click to toggle source
# File lib/rspec/hive/query_builder.rb, line 69
def transformed_rows
  transformer = RowTransformer.new(schema, missing_column_strategy)
  rows.map do |row|
    transformer.transform(row)
  end
end