hivemeta 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,9 @@
1
1
  * 2011-05-19 - fsf
2
- - perf: remove unnecessary string indexed assignment - thanks ruby-prof!
2
+ - thank you ruby-prof!
3
+ - perf: 4x+ faster ... now basically on par with manual split into array
4
+ - perf: create extra hash for column index by name
5
+ - perf: remove unnecessary string indexed assignment
6
+ - clean: table.each does each inside rather than each_with_index
3
7
 
4
8
  * 2011-05-17 - fsf
5
9
  - bugfix: default unspecified delimiter is ^A rather than TAB
@@ -77,8 +77,9 @@ module HiveMeta
77
77
  col_cmt = rec[2]
78
78
  tbl_loc = rec[3]
79
79
  sd_id = rec[4]
80
- table.columns[col_idx] = col_name
81
- table.comments[col_idx] = col_cmt
80
+ table.columns[col_idx] = col_name
81
+ table.indexes[col_name.to_sym] = col_idx
82
+ table.comments[col_idx] = col_cmt
82
83
  table.path = tbl_loc
83
84
  end
84
85
 
@@ -9,10 +9,11 @@ module HiveMeta
9
9
  raise FieldCountError
10
10
  end
11
11
 
12
- @columns = {}
13
- table.each_col_with_index do |col_name, i|
14
- @columns[col_name.to_sym] = @fields[i]
15
- end
12
+ @table = table
13
+ #@columns = {}
14
+ # table.each_col_with_index do |col_name, i|
15
+ # #@columns[col_name.to_sym] = @fields[i]
16
+ # end
16
17
  end
17
18
 
18
19
  # allow for column access via column name as an index
@@ -22,13 +23,15 @@ module HiveMeta
22
23
  # example: rec[7]
23
24
  def [] index
24
25
  return "#{@fields[index]}" if index.is_a? Integer
25
- "#{@columns[index.to_sym]}"
26
+ #"#{@columns[index.to_sym]}"
27
+ "#{@fields[@table.indexes[index.to_sym]]}"
26
28
  end
27
29
 
28
30
  # allow for column access via column name as a method
29
31
  # example: rec.col_name
30
32
  def method_missing(id, *args)
31
- return @columns[id] if @columns[id]
33
+ return @fields[@table.indexes[id]] if @fields[@table.indexes[id]]
34
+ #return @columns[id] if @columns[id]
32
35
  raise NoMethodError
33
36
  end
34
37
  end
@@ -4,12 +4,13 @@ module HiveMeta
4
4
  include Comparable
5
5
  include Enumerable
6
6
 
7
- attr_accessor :path, :columns, :comments, :delimiter
7
+ attr_accessor :path, :columns, :comments, :delimiter, :indexes
8
8
 
9
9
  def initialize(name)
10
10
  @name = name
11
11
  @path = nil
12
- @columns = []
12
+ @indexes = {} # column indexes by name
13
+ @columns = [] # column names by index
13
14
  @comments = []
14
15
  @delimiter = "\001"
15
16
  end
@@ -19,7 +20,7 @@ module HiveMeta
19
20
  end
20
21
 
21
22
  def each
22
- @columns.each_with_index do |column_name, index|
23
+ @columns.each do |column_name|
23
24
  yield column_name if column_name
24
25
  end
25
26
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Frank Fejes