Class: HiveMeta::Table
- Inherits:
-
Object
- Object
- HiveMeta::Table
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/hivemeta/table.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#delimiter ⇒ Object
Returns the value of attribute delimiter.
-
#indexes ⇒ Object
Returns the value of attribute indexes.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #each ⇒ Object (also: #each_col)
- #each_with_index ⇒ Object (also: #each_col_with_index)
-
#initialize(name) ⇒ Table
constructor
A new instance of Table.
-
#process(opts = {}) ⇒ Object
process all input (default to STDIN for Hadoop Streaming) via a provided block.
-
#process_row(line, opts = {}) ⇒ Object
process a row and return a record that can be queried by column name in a variety of ways.
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Table
Returns a new instance of Table.
9 10 11 12 13 14 15 16 |
# File 'lib/hivemeta/table.rb', line 9 def initialize(name) @name = name @path = nil @indexes = {} # column indexes by name @columns = [] # column names by index @comments = [] @delimiter = "\001" end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
7 8 9 |
# File 'lib/hivemeta/table.rb', line 7 def columns @columns end |
#comments ⇒ Object
Returns the value of attribute comments.
7 8 9 |
# File 'lib/hivemeta/table.rb', line 7 def comments @comments end |
#delimiter ⇒ Object
Returns the value of attribute delimiter.
7 8 9 |
# File 'lib/hivemeta/table.rb', line 7 def delimiter @delimiter end |
#indexes ⇒ Object
Returns the value of attribute indexes.
7 8 9 |
# File 'lib/hivemeta/table.rb', line 7 def indexes @indexes end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/hivemeta/table.rb', line 7 def path @path end |
Instance Method Details
#<=>(other) ⇒ Object
38 39 40 |
# File 'lib/hivemeta/table.rb', line 38 def <=>(other) self.to_s <=> other.to_s end |
#each ⇒ Object Also known as: each_col
22 23 24 25 26 |
# File 'lib/hivemeta/table.rb', line 22 def each @columns.each do |column_name| yield column_name if column_name end end |
#each_with_index ⇒ Object Also known as: each_col_with_index
30 31 32 33 34 |
# File 'lib/hivemeta/table.rb', line 30 def each_with_index @columns.each_with_index do |column_name, index| yield column_name, index if column_name end end |
#process(opts = {}) ⇒ Object
process all input (default to STDIN for Hadoop Streaming) via a provided block
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hivemeta/table.rb', line 55 def process(opts = {}) f = opts[:file] || STDIN if not block_given? return process_row(f.readline, opts) end f.each_line do |line| begin process_row(line, opts) {|row| yield row} rescue HiveMeta::FieldCountError warning = opts[:field_count_warning] warning ||= "reporter:counter:HiveMeta,FieldCountError,1" STDERR.puts warning next end end end |
#process_row(line, opts = {}) ⇒ Object
process a row and return a record that can be queried by column name in a variety of ways
44 45 46 47 48 49 50 51 |
# File 'lib/hivemeta/table.rb', line 44 def process_row(line, opts = {}) return nil if not line if block_given? yield Record.new(line, self, opts) else return Record.new(line, self, opts) end end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/hivemeta/table.rb', line 18 def to_s "#{@name}" end |