diff --git a/influxdb3_write/src/write_buffer/validator.rs b/influxdb3_write/src/write_buffer/validator.rs index 2718d42e994..c6cacff9184 100644 --- a/influxdb3_write/src/write_buffer/validator.rs +++ b/influxdb3_write/src/write_buffer/validator.rs @@ -506,7 +506,7 @@ fn convert_v3_parsed_line<'a>( // TODO: change the default time resolution to microseconds in v3 let time_value_nanos = line .timestamp - .map(|ts| apply_precision_to_timestamp(precision, ts)) + .and_then(|ts| apply_precision_to_timestamp(precision, ts)) .unwrap_or(ingest_time.timestamp_nanos()); values.push(Field { name: TIME_COLUMN_NAME.to_string(), @@ -628,7 +628,7 @@ fn convert_v1_parsed_line<'a>( // set the time value let time_value_nanos = line .timestamp - .map(|ts| apply_precision_to_timestamp(precision, ts)) + .and_then(|ts| apply_precision_to_timestamp(precision, ts)) .unwrap_or(ingest_time.timestamp_nanos()); let segment_start = segment_duration.start_time(time_value_nanos / 1_000_000_000); @@ -652,7 +652,8 @@ fn convert_v1_parsed_line<'a>( table_batch_map.lines.push(raw_line); } -fn apply_precision_to_timestamp(precision: Precision, ts: i64) -> i64 { +/// Returns `None` if calculation overflows +fn apply_precision_to_timestamp(precision: Precision, ts: i64) -> Option { let multiplier = match precision { Precision::Auto => match crate::guess_precision(ts) { Precision::Second => 1_000_000_000, @@ -667,8 +668,7 @@ fn apply_precision_to_timestamp(precision: Precision, ts: i64) -> i64 { Precision::Microsecond => 1_000, Precision::Nanosecond => 1, }; - - ts * multiplier + ts.checked_mul(multiplier) } #[cfg(test)]