Skip to content

Commit

Permalink
Merge pull request #111 from kaizenplatform/convert-hash-to-json-depr…
Browse files Browse the repository at this point in the history
…ecated

Make `convert_hash_to_json` deprecated.
  • Loading branch information
joker1007 committed Jan 16, 2017
2 parents 2a952b6 + 7b3f44d commit b8112a8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/fluent/plugin/bigquery/schema.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'multi_json'

module Fluent
module BigQuery
class FieldSchema
Expand Down Expand Up @@ -56,7 +58,11 @@ def type
end

def format_one(value)
value.to_s
if value.is_a?(Hash) || value.is_a?(Array)
MultiJson.dump(value)
else
value.to_s
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/fluent/plugin/out_bigquery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ def configure(conf)
else
@get_insert_id = nil
end

warn "[DEPRECATION] `convert_hash_to_json` param is deprecated. If Hash value is inserted string field, plugin convert it to json automatically." if @convert_hash_to_json
end

def start
Expand Down
17 changes: 17 additions & 0 deletions test/plugin/test_record_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ def test_format_one
)
end

def test_format_one_convert_array_or_hash_to_json
fields = Fluent::BigQuery::RecordSchema.new("record")
fields.load_schema(base_schema, false)

time = Time.local(2016, 2, 7, 19, 0, 0).utc

formatted = fields.format_one({
"time" => time, "tty" => ["tty1", "tty2", "tty3"], "pwd" => "/home", "user" => {name: "joker1007", uid: 10000}, "argv" => ["foo", 42]
})
assert_equal(
formatted,
{
"time" => time.strftime("%Y-%m-%d %H:%M:%S.%6L %:z"), "tty" => MultiJson.dump(["tty1", "tty2", "tty3"]), "pwd" => "/home", "user" => MultiJson.dump({name: "joker1007", uid: 10000}), "argv" => ["foo", "42"]
}
)
end

def test_format_one_with_extra_column
fields = Fluent::BigQuery::RecordSchema.new("record")
fields.load_schema(base_schema, false)
Expand Down

0 comments on commit b8112a8

Please sign in to comment.