Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #100 from socialcast/fix-encoding
Browse files Browse the repository at this point in the history
Fix hive boolean encoding
  • Loading branch information
mandrews committed Mar 19, 2015
2 parents 82c8952 + 962dca1 commit 057f0a0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
16 changes: 11 additions & 5 deletions lib/masamune/schema/column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def csv_value(value)
return nil if value.nil?
case type
when :boolean
value ? 'TRUE' : 'FALSE'
value ? 'TRUE' : (hive_encoding? ? nil : 'FALSE')
when :yaml
value.to_hash.to_yaml
when :json, :key_value
Expand Down Expand Up @@ -313,12 +313,18 @@ def null_value?(value)
if type == :json || array_value?
return true if value == 'NULL'
end
return false unless parent && parent.store
return false unless value
case parent.store.type
when :hive
if hive_encoding?
value.to_s == '\N'
when :postgres
else
false
end
end

def hive_encoding?
if parent && parent.store
parent.store.type == :hive
else
false
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/masamune/schema/column_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,24 @@
end
end

context 'with type :boolean with store :hive' do
let(:column) { described_class.new(id: 'bool', type: :boolean) }

before do
allow(column).to receive_message_chain(:parent, :store, :type).and_return(:hive)
end

context 'when true' do
let(:value) { true }
it { is_expected.to eq('TRUE') }
end

context 'when false' do
let(:value) { false }
it { is_expected.to eq(nil) }
end
end

context 'with type :integer and :array' do
let(:column) { described_class.new(id: 'int[]', type: :integer, array: true) }

Expand Down
4 changes: 2 additions & 2 deletions spec/masamune/schema/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@

let(:target_data) do
<<-EOS.strip_heredoc
1 30 FALSE {}
2 40 2014-02-26T18:15:51.000Z FALSE "{""enabled"":true}"
1 30 {}
2 40 2014-02-26T18:15:51.000Z "{""enabled"":true}"
EOS
end

Expand Down

0 comments on commit 057f0a0

Please sign in to comment.