Merge pull request #725 from markabey/csv_quote_char

Csv quote char
This commit is contained in:
Richard Pijnenburg 2013-10-16 08:47:22 -07:00
commit 8f0cfea42a
2 changed files with 52 additions and 1 deletions

View file

@ -24,6 +24,11 @@ class LogStash::Filters::CSV < LogStash::Filters::Base
# Optional.
config :separator, :validate => :string, :default => ","
# Define the character used to quote CSV fields. If this is not specified
# the default is a double quote '"'
# Optional.
config :quote_char, :validate => :string, :default => '"'
# Define target for placing the data
# Defaults to writing to the root of the event.
config :target, :validate => :string
@ -57,7 +62,7 @@ class LogStash::Filters::CSV < LogStash::Filters::Base
raw = event[@source].first
begin
values = CSV.parse_line(raw, :col_sep => @separator)
values = CSV.parse_line(raw, :col_sep => @separator, :quote_char => @quote_char)
if @target.nil?
# Default is to write to the root of the event.

View file

@ -35,6 +35,52 @@ describe LogStash::Filters::CSV do
end
end
describe "custom quote char" do
config <<-CONFIG
filter {
csv {
quote_char => "'"
}
}
CONFIG
sample "big,bird,'sesame street'" do
insist { subject["column1"] } == "big"
insist { subject["column2"] } == "bird"
insist { subject["column3"] } == "sesame street"
end
end
describe "default quote char" do
config <<-CONFIG
filter {
csv {
}
}
CONFIG
sample 'big,bird,"sesame, street"' do
insist { subject["column1"] } == "big"
insist { subject["column2"] } == "bird"
insist { subject["column3"] } == "sesame, street"
end
end
describe "null quote char" do
config <<-CONFIG
filter {
csv {
quote_char => "\x00"
}
}
CONFIG
sample 'big,bird,"sesame" street' do
insist { subject["column1"] } == 'big'
insist { subject["column2"] } == 'bird'
insist { subject["column3"] } == '"sesame" street'
end
end
describe "given columns" do
# The logstash config goes here.
# At this time, only filters are supported.