class PigSpec::JavaPigTest
Wrapper for java Pigtest class.
Public Class Methods
new(bridge, instance)
click to toggle source
# File lib/pigspec/javabridge.rb, line 96 def initialize(bridge, instance) @bridge = bridge @instance = instance end
Public Instance Methods
override(name, query)
click to toggle source
# File lib/pigspec/javabridge.rb, line 115 def override(name, query) @instance.override name, query end
register_script()
click to toggle source
# File lib/pigspec/javabridge.rb, line 101 def register_script # runScript method only register pigscript. # pig uses 'lazy run' to decide really output alias. @instance.runScript end
run_script(goal_alias)
click to toggle source
# File lib/pigspec/javabridge.rb, line 107 def run_script(goal_alias) items = [] @instance.getAlias(goal_alias).each do |item| items.push read_tuple(item) end items end
Private Instance Methods
read_as(type, value)
click to toggle source
# File lib/pigspec/javabridge.rb, line 121 def read_as(type, value) # rubocop:disable Metrics/AbcSize, Style/CyclomaticComplexity, Style/MethodLength return value unless type # AllTypes: http://pig.apache.org/docs/r0.11.1/api/org/apache/pig/data/DataType.html types = @bridge.data_type_enum case type when types.CHARARRAY, types.BYTEARRAY, types.DATETIME then value.toString # daringly no cast to test convinience when types.DATETIME then value.toString when types.LONG, types.INTEGER, types.BYTE then value.toString.to_i when types.DOUBLE, types.FLOAT then value.toString.to_f when types.BOOLEAN then value.toString.downcase.include? 't' when types.TUPLE then read_tuple value when types.BAG then read_bag value # TODO: types.MAP is schemaless...How to cast it...? when types.MAP then value.toString # read_map value when types.UNKNOWN then nil else nil end end
read_bag(bag)
click to toggle source
# File lib/pigspec/javabridge.rb, line 141 def read_bag(bag) casted = [] bag.each do |tuple| casted.push read_tuple(tuple) end casted end
read_tuple(tuple)
click to toggle source
# File lib/pigspec/javabridge.rb, line 149 def read_tuple(tuple) casted = [] tuple.size.times do|index| type = tuple.getType index value = nil value = tuple.get(index) unless tuple.isNull index casted.push read_as(type, value) end casted end