Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ca52993

Browse files
committedFeb 3, 2025·
converted to Int64
1 parent d7ffaaf commit ca52993

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed
 

‎src/event/format/json.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,11 @@ fn fields_mismatch(schema: &[Arc<Field>], body: &Value, schema_version: SchemaVe
174174
fn valid_type(data_type: &DataType, value: &Value, schema_version: SchemaVersion) -> bool {
175175
match data_type {
176176
DataType::Boolean => value.is_boolean(),
177-
DataType::Int8 | DataType::Int16 | DataType::Int32 | DataType::Int64 => value.is_i64(),
177+
DataType::Int8 | DataType::Int16 | DataType::Int32 => value.is_i64(),
178178
DataType::UInt8 | DataType::UInt16 | DataType::UInt32 | DataType::UInt64 => value.is_u64(),
179-
DataType::Float16 | DataType::Float32 => value.is_f64(),
179+
DataType::Float16 | DataType::Float32 | DataType::Float64 => value.is_f64(),
180180
// All numbers can be cast as Float64 from schema version v1
181-
DataType::Float64 if schema_version == SchemaVersion::V1 => {
182-
value.is_number() || is_parsable_as_number(value)
183-
}
184-
DataType::Float64 if schema_version != SchemaVersion::V1 => value.is_f64(),
181+
DataType::Int64 => value.is_i64() || is_parsable_as_number(value),
185182
DataType::Utf8 => value.is_string(),
186183
DataType::List(field) => {
187184
let data_type = field.data_type();
@@ -232,5 +229,5 @@ pub fn is_parsable_as_number(value: &Value) -> bool {
232229
let Value::String(s) = value else {
233230
return false;
234231
};
235-
s.parse::<f64>().is_ok()
232+
s.parse::<i64>().is_ok()
236233
}

‎src/event/format/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,18 @@ pub fn override_data_type(
318318
.get(field_name)
319319
.unwrap()
320320
.data_type()
321-
== &DataType::Float64
321+
== &DataType::Int64
322322
&& field.data_type() == &DataType::Utf8
323-
&& s.parse::<f64>().is_ok()) =>
323+
&& s.parse::<i64>().is_ok()) =>
324324
{
325325
// Update the field's data type to Float64
326-
Field::new(field_name, DataType::Float64, true)
326+
Field::new(field_name, DataType::Int64, true)
327327
}
328328

329329
// in V1 for new fields in json with inferred type number, cast as float64.
330-
(SchemaVersion::V1, Some(Value::Number(_))) if field.data_type().is_numeric() => {
330+
(SchemaVersion::V1, Some(Value::Number(_))) if field.data_type().is_integer() => {
331331
// Update the field's data type to Float64
332-
Field::new(field_name, DataType::Float64, true)
332+
Field::new(field_name, DataType::Int64, true)
333333
}
334334
// Return the original field if no update is needed
335335
_ => Field::new(field_name, field.data_type().clone(), true),

0 commit comments

Comments
 (0)
Please sign in to comment.