diff --git a/lib/fluent/plugin/bigquery/schema.rb b/lib/fluent/plugin/bigquery/schema.rb index 0f1d285..7f30d04 100644 --- a/lib/fluent/plugin/bigquery/schema.rb +++ b/lib/fluent/plugin/bigquery/schema.rb @@ -116,6 +116,16 @@ def format_one(value, is_load: false) end end + class BigNumericFieldSchema < FieldSchema + def type + :bignumeric + end + + def format_one(value, is_load: false) + value.to_s + end + end + class BooleanFieldSchema < FieldSchema def type :boolean @@ -200,6 +210,7 @@ class RecordSchema < FieldSchema integer: IntegerFieldSchema, float: FloatFieldSchema, numeric: NumericFieldSchema, + bignumeric: BigNumericFieldSchema, boolean: BooleanFieldSchema, timestamp: TimestampFieldSchema, date: DateFieldSchema, diff --git a/test/plugin/test_record_schema.rb b/test/plugin/test_record_schema.rb index bc1ac79..8950628 100644 --- a/test/plugin/test_record_schema.rb +++ b/test/plugin/test_record_schema.rb @@ -32,6 +32,11 @@ def base_schema "name" => "utilisation", "type" => "NUMERIC", "mode" => "NULLABLE" + }, + { + "name" => "bigutilisation", + "type" => "BIGNUMERIC", + "mode" => "NULLABLE" } ] end @@ -72,6 +77,11 @@ def base_schema_with_new_column "name" => "new_column", "type" => "STRING", "mode" => "REQUIRED" + }, + { + "name" => "bigutilisation", + "type" => "BIGNUMERIC", + "mode" => "NULLABLE" } ] end @@ -107,6 +117,11 @@ def base_schema_with_type_changed_column "name" => "utilisation", "type" => "NUMERIC", "mode" => "NULLABLE" + }, + { + "name" => "bigutilisation", + "type" => "BIGNUMERIC", + "mode" => "NULLABLE" } ] end @@ -157,12 +172,12 @@ def test_format_one_convert_array_or_hash_to_json 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], "utilisation" => "0.837" + "time" => time, "tty" => ["tty1", "tty2", "tty3"], "pwd" => "/home", "user" => {name: "joker1007", uid: 10000}, "argv" => ["foo", 42], "utilisation" => "0.837", "bigutilisation" => "0.837" }) 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"], "utilisation" => "0.837" + "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"], "utilisation" => "0.837", "bigutilisation" => "0.837" } ) end