class PigSpec::JavaBridge
bridge for java pig classies
Attributes
data_type_enum[R]
Public Class Methods
new(pig_path, pigunit_path, options)
click to toggle source
# File lib/pigspec/javabridge.rb, line 8 def initialize(pig_path, pigunit_path, options) load_pig pig_path, pigunit_path, options import_classies end
Public Instance Methods
cluster()
click to toggle source
# File lib/pigspec/javabridge.rb, line 43 def cluster @pig_test_class.getCluster end
context()
click to toggle source
# File lib/pigspec/javabridge.rb, line 31 def context @pig_test_class.getPigServer.getPigContext end
create_hdfs_temp()
click to toggle source
# File lib/pigspec/javabridge.rb, line 35 def create_hdfs_temp @file_localizer_class.getTemporaryPath(context).toString end
create_test(script, *args)
click to toggle source
# File lib/pigspec/javabridge.rb, line 26 def create_test(script, *args) instance = @pig_test_class.new script, args JavaPigTest.new self, instance end
schema(alias_name)
click to toggle source
# File lib/pigspec/javabridge.rb, line 51 def schema(alias_name) raw_schema = server.dumpSchema(alias_name) builder = @string_builder_class.new @schema_class.stringifySchema(builder, raw_schema, @data_type_enum.TUPLE) str_schema = builder.toString return nil if str_schema.split("\n").join('') == '()' str_schema end
server()
click to toggle source
# File lib/pigspec/javabridge.rb, line 39 def server @pig_test_class.getPigServer end
stringify(alias_values)
click to toggle source
# File lib/pigspec/javabridge.rb, line 60 def stringify(alias_values) @string_util_class.join(alias_values, "\n") end
unload()
click to toggle source
# File lib/pigspec/javabridge.rb, line 13 def unload @pig_test_class = nil @cluster_class = nil @file_localizer_class = nil @pig_server_class = nil @schema_class = nil @string_builder_class = nil @data_type_enum = nil @string_util_class = nil Rjb.unload GC.start end
upload_text(text, path)
click to toggle source
# File lib/pigspec/javabridge.rb, line 47 def upload_text(text, path) cluster.copyFromLocalFile(text, path, true) end
Private Instance Methods
import_classies()
click to toggle source
# File lib/pigspec/javabridge.rb, line 81 def import_classies require 'rjb/list' @pig_test_class = Rjb.import('org.apache.pig.pigunit.PigTest') @cluster_class = Rjb.import('org.apache.pig.pigunit.Cluster') @file_localizer_class = Rjb.import('org.apache.pig.impl.io.FileLocalizer') @pig_server_class = Rjb.import('org.apache.pig.pigunit.pig.PigServer') @schema_class = Rjb.import('org.apache.pig.impl.logicalLayer.schema.Schema') @string_builder_class = Rjb.import('java.lang.StringBuilder') @data_type_enum = Rjb.import('org.apache.pig.data.DataType') @string_util_class = Rjb.import('org.apache.commons.lang.StringUtils') end
load_pig(pig_path, pigunit_path, options)
click to toggle source
# File lib/pigspec/javabridge.rb, line 68 def load_pig(pig_path, pigunit_path, options) fail ArgumentError, 'pig_path must not be nil.' if pig_path.nil? fail ArgumentError, 'pigunit_path must not be nil.' if pigunit_path.nil? Rjb.add_classpath(pig_path) Rjb.add_classpath(pigunit_path) Rjb.load '.', options Rjb.add_jar(pig_path) Rjb.add_jar(pigunit_path) end