Skip to content

Commit

Permalink
Merge pull request #208 from GLStephen/patch-1
Browse files Browse the repository at this point in the history
Update to Support BIGNUMERIC Data Type
  • Loading branch information
joker1007 committed Oct 24, 2023
2 parents 94e9c9c + 88bd882 commit de6745e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/fluent/plugin/bigquery/schema.rb
Expand Up @@ -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
Expand Down Expand Up @@ -200,6 +210,7 @@ class RecordSchema < FieldSchema
integer: IntegerFieldSchema,
float: FloatFieldSchema,
numeric: NumericFieldSchema,
bignumeric: BigNumericFieldSchema,
boolean: BooleanFieldSchema,
timestamp: TimestampFieldSchema,
date: DateFieldSchema,
Expand Down
19 changes: 17 additions & 2 deletions test/plugin/test_record_schema.rb
Expand Up @@ -32,6 +32,11 @@ def base_schema
"name" => "utilisation",
"type" => "NUMERIC",
"mode" => "NULLABLE"
},
{
"name" => "bigutilisation",
"type" => "BIGNUMERIC",
"mode" => "NULLABLE"
}
]
end
Expand Down Expand Up @@ -72,6 +77,11 @@ def base_schema_with_new_column
"name" => "new_column",
"type" => "STRING",
"mode" => "REQUIRED"
},
{
"name" => "bigutilisation",
"type" => "BIGNUMERIC",
"mode" => "NULLABLE"
}
]
end
Expand Down Expand Up @@ -107,6 +117,11 @@ def base_schema_with_type_changed_column
"name" => "utilisation",
"type" => "NUMERIC",
"mode" => "NULLABLE"
},
{
"name" => "bigutilisation",
"type" => "BIGNUMERIC",
"mode" => "NULLABLE"
}
]
end
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit de6745e

Please sign in to comment.