class PigSpec::Test

TestCase of PigSpec

Attributes

bridge[R]

Public Class Methods

construct(pig_path, pigunit_path, options) click to toggle source
# File lib/pigspec.rb, line 15
def construct(pig_path, pigunit_path, options)
  @pig_path ||= pig_path
  @pigunit_path ||= pigunit_path
  @options ||= options

  fail ArgumentError, 'This version pigspec only can same pig_path for all processes.' unless @pig_path == pig_path
  fail ArgumentError, 'This version pigspec only can same pigunit_path for all processes.' unless @pigunit_path == pigunit_path
  fail ArgumentError, 'This version pigspec only can same options for all processes.' unless @options == options

  @bridge ||= JavaBridge.new @pig_path, @pigunit_path, @options
end

Public Instance Methods

override(name, value, options = {}) click to toggle source
# File lib/pigspec.rb, line 61
def override(name, value, options = {})
  @override.push name: name, value: value, schema: options[:as]
end
pickup(name) click to toggle source

to ‘expose’

# File lib/pigspec.rb, line 67
def pickup(name)  # rubocop:disable Style/TrivialAccessors
  @pickup = name
end
run() click to toggle source
# File lib/pigspec.rb, line 72
def run
  # If no output alias, must result nil
  return nil unless @pickup

  test = Test.bridge.create_test @script, *@args
  test.register_script
  apply_override test
  test.run_script @pickup
end
script(text) click to toggle source
# File lib/pigspec.rb, line 46
def script(text)
  @script = text.split("\n")
end
script_file(path) click to toggle source
# File lib/pigspec.rb, line 51
def script_file(path)
  @script = open(path, 'r') { |f| f.each_line.to_a }
end
setup(pig_path, pigunit_path, options) click to toggle source
# File lib/pigspec.rb, line 28
def setup(pig_path, pigunit_path, options)
  fail ArgumentError, 'Must needs pig_path. It must point to your installation of Apache Pig/PigUnit jar files.' if pig_path.nil?
  fail ArgumentError, 'Must needs pigunit_path. It must point to your installation of Apache Pig/PigUnit jar files.' if pigunit_path.nil?

  Test.construct pig_path, pigunit_path, options
  @script = []
  @args = []
  @override = []
  @pickup = nil
end
shutdown() click to toggle source
# File lib/pigspec.rb, line 39
def shutdown
  # Rjb unload -> load is not work.(current restriction.)
  # s.a https://github.com/arton/rjb/issues/34
  # If the JNI bug fixed then we can uncomment follow line.
  # @bridge.unload
end
with_args(*args) click to toggle source
# File lib/pigspec.rb, line 56
def with_args(*args)
  @args = args
end

Private Instance Methods

apply_override(test) click to toggle source
# File lib/pigspec.rb, line 84
def apply_override(test)
  @override.each do |item|
    value_file = upload_override_value item
    query = compose_override_query item, value_file
    test.override item[:name], query
  end
end
compose_override_query(item, value_file) click to toggle source
# File lib/pigspec.rb, line 98
def compose_override_query(item, value_file)
  schema = compose_override_schema item
  query  = "#{item[:name]} = LOAD '#{value_file}' USING PigStorage('\\t')"
  query += " AS #{schema}" unless schema.nil?
  query += ';'
  query
end
compose_override_schema(item) click to toggle source
# File lib/pigspec.rb, line 106
def compose_override_schema(item)
  schema = item[:schema]
  schema ||= Test.bridge.schema item[:name]
  schema
end
upload_override_value(item) click to toggle source
# File lib/pigspec.rb, line 92
def upload_override_value(item)
  temp = Test.bridge.create_hdfs_temp
  Test.bridge.upload_text item[:value], temp
  temp
end