Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make convert_hash_to_json deprecated. #111

Merged
merged 1 commit into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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