diff --git a/src/Storages/MergeTree/MergeTreeData.cpp b/src/Storages/MergeTree/MergeTreeData.cpp index cfe62fefb06..a268468ea59 100644 --- a/src/Storages/MergeTree/MergeTreeData.cpp +++ b/src/Storages/MergeTree/MergeTreeData.cpp @@ -158,6 +158,16 @@ static void checkSampleExpression(const StorageInMemoryMetadata & metadata, bool ErrorCodes::ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER); } +inline UInt64 time_in_microseconds(std::chrono::time_point timepoint) +{ + return std::chrono::duration_cast(timepoint.time_since_epoch()).count(); +} + +inline UInt64 time_in_seconds(std::chrono::time_point timepoint) +{ + return std::chrono::duration_cast(timepoint.time_since_epoch()).count(); +} + MergeTreeData::MergeTreeData( const StorageID & table_id_, const String & relative_data_path_, @@ -1246,7 +1256,11 @@ void MergeTreeData::removePartsFinally(const MergeTreeData::DataPartsVector & pa PartLogElement part_log_elem; part_log_elem.event_type = PartLogElement::REMOVE_PART; - part_log_elem.event_time = time(nullptr); + + const auto time_now = std::chrono::system_clock::now(); + part_log_elem.event_time = time_in_seconds(time_now); + part_log_elem.event_time_microseconds = time_in_microseconds(time_now); + part_log_elem.duration_ms = 0; //-V1048 part_log_elem.database_name = table_id.database_name; @@ -4579,17 +4593,6 @@ bool MergeTreeData::canReplacePartition(const DataPartPtr & src_part) const return true; } -inline UInt64 time_in_microseconds(std::chrono::time_point timepoint) -{ - return std::chrono::duration_cast(timepoint.time_since_epoch()).count(); -} - - -inline UInt64 time_in_seconds(std::chrono::time_point timepoint) -{ - return std::chrono::duration_cast(timepoint.time_since_epoch()).count(); -} - void MergeTreeData::writePartLog( PartLogElement::Type type, const ExecutionStatus & execution_status, diff --git a/tests/queries/0_stateless/01686_event_time_microseconds_part_log.reference b/tests/queries/0_stateless/01686_event_time_microseconds_part_log.reference index 9766475a418..79ebd0860f4 100644 --- a/tests/queries/0_stateless/01686_event_time_microseconds_part_log.reference +++ b/tests/queries/0_stateless/01686_event_time_microseconds_part_log.reference @@ -1 +1,2 @@ ok +ok diff --git a/tests/queries/0_stateless/01686_event_time_microseconds_part_log.sql b/tests/queries/0_stateless/01686_event_time_microseconds_part_log.sql index 4a653379ef1..6063be4d1da 100644 --- a/tests/queries/0_stateless/01686_event_time_microseconds_part_log.sql +++ b/tests/queries/0_stateless/01686_event_time_microseconds_part_log.sql @@ -10,16 +10,27 @@ ORDER BY key; INSERT INTO table_with_single_pk SELECT number, toString(number % 10) FROM numbers(1000000); +-- Check NewPart SYSTEM FLUSH LOGS; - WITH ( SELECT (event_time, event_time_microseconds) FROM system.part_log - WHERE "table" = 'table_with_single_pk' - AND "database" = currentDatabase() + WHERE table = 'table_with_single_pk' AND database = currentDatabase() AND event_type = 'NewPart' ORDER BY event_time DESC LIMIT 1 ) AS time SELECT if(dateDiff('second', toDateTime(time.2), toDateTime(time.1)) = 0, 'ok', 'fail'); -DROP TABLE IF EXISTS table_with_single_pk; +-- Now let's check RemovePart +TRUNCATE TABLE table_with_single_pk; +SYSTEM FLUSH LOGS; +WITH ( + SELECT (event_time, event_time_microseconds) + FROM system.part_log + WHERE table = 'table_with_single_pk' AND database = currentDatabase() AND event_type = 'RemovePart' + ORDER BY event_time DESC + LIMIT 1 + ) AS time +SELECT if(dateDiff('second', toDateTime(time.2), toDateTime(time.1)) = 0, 'ok', 'fail'); + +DROP TABLE table_with_single_pk;