Skip to content

Commit

Permalink
Merge pull request #17 from lyrasis/bugfix
Browse files Browse the repository at this point in the history
Bugfix for `Merge::MultiRowLookup`
  • Loading branch information
kspurgin authored May 26, 2021
2 parents 9a23a4f + 7428d88 commit e39b72c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
kiba-extend (1.11.0)
kiba-extend (1.12.0)
activesupport
kiba (>= 4.0.0)
kiba-common (>= 1.5.0)
Expand Down
6 changes: 4 additions & 2 deletions lib/kiba/extend/transforms/merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ def initialize(fieldmap:, constantmap: {}, lookup:, keycolumn:,
end

def process(row)
id_data = row.fetch(@keycolumn)
ids = @multikey ? id_data.split(@delim) : [id_data]
field_data = Kiba::Extend::Fieldset.new(@fieldmap.values)

id_data = row.fetch(@keycolumn, '')
id_data = id_data.nil? ? '' : id_data
ids = @multikey ? id_data.split(@delim) : [id_data]


ids.each do |id|
field_data.populate(rows_to_merge(id, row))
Expand Down
2 changes: 1 addition & 1 deletion lib/kiba/extend/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Kiba
module Extend
VERSION = "1.12.0"
VERSION = "1.12.1"
end
end
21 changes: 16 additions & 5 deletions spec/kiba/extend/transforms/merge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@
[2, 'Kernel', 'f', 'adopted'],
[3, 'Boris', 'm', 'adopted'],
[4, 'Earlybird', 'f', 'hatched'],
[5, 'Lazarus', 'm', 'adopted']
[5, 'Lazarus', 'm', 'adopted'],
[nil, 'Null', '', '']
] }
lookup_rows = [
['id', 'date', 'treatment'],
Expand Down Expand Up @@ -236,9 +237,12 @@
:date=>nil,
:event=>nil},
{:id=>'5', :name=>'Lazarus', :sex=>'m', :source=>'adopted',
:date=>nil,
:event=>nil} ,
{:id=>nil, :name=>'Null', :sex=>'', :source=>'',
:date=>nil,
:event=>nil}
]
]
result = execute_job(filename: test_csv, xform: Merge::MultiRowLookup, xformopt: xformopt)
expect(result).to eq(expected)
end
Expand All @@ -265,6 +269,10 @@
:event=>nil,
:by=>nil, :loc=>nil},
{:id=>'5', :name=>'Lazarus', :sex=>'m', :source=>'adopted',
:date=>nil,
:event=>nil,
:by=>nil, :loc=>nil},
{:id=>nil, :name=>'Null', :sex=>'', :source=>'',
:date=>nil,
:event=>nil,
:by=>nil, :loc=>nil}
Expand All @@ -284,7 +292,8 @@
['a|b|c'],
['d'],
['e|f|g'],
['h']
['h'],
[nil]
] }
lookup_rows = [
['single', 'double', 'triple'],
Expand Down Expand Up @@ -316,7 +325,8 @@
{single: 'a|b|c', doubles: 'aa|bb|beebee|cc', triples: 'aaa|bbb||ccc'},
{single: 'd', doubles: 'dd', triples: 'ddd'},
{single: 'e|f|g', doubles: 'ee|', triples: 'eee|ggg'},
{single: 'h', doubles: nil, triples: nil}
{single: 'h', doubles: nil, triples: nil},
{single: nil, doubles: nil, triples: nil}
]
result = execute_job(filename: test_csv, xform: Merge::MultiRowLookup, xformopt: xformopt)
expect(result).to eq(expected)
Expand All @@ -328,7 +338,8 @@
{single: 'a|b|c', doubles: 'aa|bb|beebee|cc', triples: 'aaa|bbb||ccc', quad: '4|4|4|4', pent: '5|5|5|5'},
{single: 'd', doubles: 'dd', triples: 'ddd', quad: '4', pent: '5'},
{single: 'e|f|g', doubles: 'ee|', triples: 'eee|ggg', quad: '4|4', pent: '5|5'},
{single: 'h', doubles: nil, triples: nil, quad: nil, pent: nil}
{single: 'h', doubles: nil, triples: nil, quad: nil, pent: nil},
{single: nil, doubles: nil, triples: nil, quad: nil, pent: nil}
]
result = execute_job(filename: test_csv, xform: Merge::MultiRowLookup, xformopt: opt)
expect(result).to eq(expected)
Expand Down

0 comments on commit e39b72c

Please sign in to comment.