mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-09 06:42:57 +00:00
* fix: Rename current_timestamp to current_time_millis, fix resolution Fix current_timestamp returns seconds resolution, also add a test for this method * chore: Use slice of array instead of Vec Save some heap allocations * test: Compare std and chrono timestamp The original test always success even the current_time_millis returns in seconds resolution * chore: Store current time in gmt_created/gmt_modified
This commit is contained in:
@@ -5,6 +5,7 @@ use std::sync::Arc;
|
||||
use common_query::logical_plan::Expr;
|
||||
use common_recordbatch::SendableRecordBatchStream;
|
||||
use common_telemetry::debug;
|
||||
use common_time::util;
|
||||
use datatypes::prelude::{ConcreteDataType, ScalarVector};
|
||||
use datatypes::schema::{ColumnSchema, Schema, SchemaRef};
|
||||
use datatypes::vectors::{BinaryVector, Int64Vector, UInt8Vector};
|
||||
@@ -152,7 +153,7 @@ pub fn build_table_insert_request(full_table_name: String, table_id: TableId) ->
|
||||
let mut columns_values = HashMap::with_capacity(6);
|
||||
columns_values.insert(
|
||||
"entry_type".to_string(),
|
||||
Arc::new(UInt8Vector::from_vec(vec![EntryType::Table as u8])) as _,
|
||||
Arc::new(UInt8Vector::from_slice(&[EntryType::Table as u8])) as _,
|
||||
);
|
||||
|
||||
columns_values.insert(
|
||||
@@ -163,7 +164,7 @@ pub fn build_table_insert_request(full_table_name: String, table_id: TableId) ->
|
||||
// Timestamp in key part is intentionally left to 0
|
||||
columns_values.insert(
|
||||
"timestamp".to_string(),
|
||||
Arc::new(Int64Vector::from_vec(vec![0])) as _,
|
||||
Arc::new(Int64Vector::from_slice(&[0])) as _,
|
||||
);
|
||||
|
||||
columns_values.insert(
|
||||
@@ -177,12 +178,12 @@ pub fn build_table_insert_request(full_table_name: String, table_id: TableId) ->
|
||||
|
||||
columns_values.insert(
|
||||
"gmt_created".to_string(),
|
||||
Arc::new(Int64Vector::from_vec(vec![0])) as _,
|
||||
Arc::new(Int64Vector::from_slice(&[util::current_time_millis()])) as _,
|
||||
);
|
||||
|
||||
columns_values.insert(
|
||||
"gmt_modified".to_string(),
|
||||
Arc::new(Int64Vector::from_vec(vec![0])) as _,
|
||||
Arc::new(Int64Vector::from_slice(&[util::current_time_millis()])) as _,
|
||||
);
|
||||
|
||||
InsertRequest {
|
||||
|
||||
@@ -6,4 +6,4 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4"
|
||||
chrono = "0.4"
|
||||
|
||||
@@ -1,4 +1,31 @@
|
||||
/// Calculates the time duration since UNIX_EPOCH in milliseconds.
|
||||
pub fn current_timestamp() -> i64 {
|
||||
chrono::Utc::now().timestamp()
|
||||
/// Returns the time duration since UNIX_EPOCH in milliseconds.
|
||||
pub fn current_time_millis() -> i64 {
|
||||
chrono::Utc::now().timestamp_millis()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::time::{self, SystemTime};
|
||||
|
||||
use chrono::{Datelike, TimeZone, Timelike};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_current_time_millis() {
|
||||
let now = current_time_millis();
|
||||
|
||||
let millis_from_std = SystemTime::now()
|
||||
.duration_since(time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_millis() as i64;
|
||||
let datetime_now = chrono::Utc.timestamp_millis(now);
|
||||
let datetime_std = chrono::Utc.timestamp_millis(millis_from_std);
|
||||
|
||||
assert_eq!(datetime_std.year(), datetime_now.year());
|
||||
assert_eq!(datetime_std.month(), datetime_now.month());
|
||||
assert_eq!(datetime_std.day(), datetime_now.day());
|
||||
assert_eq!(datetime_std.hour(), datetime_now.hour());
|
||||
assert_eq!(datetime_std.minute(), datetime_now.minute());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user