fix: fix incorrect timestamp precision in information_schema.tables (#6872)

* fix: fix incorrect timestamp precision in information_schema.tables

Signed-off-by: WenyXu <wenymedia@gmail.com>

* fix: fix unit test

Signed-off-by: WenyXu <wenymedia@gmail.com>

---------

Signed-off-by: WenyXu <wenymedia@gmail.com>
This commit is contained in:
Weny Xu
2025-09-01 20:20:23 +08:00
committed by GitHub
parent 246b832d79
commit 0e962844ac
4 changed files with 36 additions and 21 deletions

View File

@@ -30,8 +30,7 @@ use datatypes::prelude::{ConcreteDataType, ScalarVectorBuilder, VectorRef};
use datatypes::schema::{ColumnSchema, Schema, SchemaRef};
use datatypes::value::Value;
use datatypes::vectors::{
StringVectorBuilder, TimestampMicrosecondVectorBuilder, UInt32VectorBuilder,
UInt64VectorBuilder,
StringVectorBuilder, TimestampSecondVectorBuilder, UInt32VectorBuilder, UInt64VectorBuilder,
};
use futures::TryStreamExt;
use snafu::{OptionExt, ResultExt};
@@ -107,17 +106,17 @@ impl InformationSchemaTables {
ColumnSchema::new(AUTO_INCREMENT, ConcreteDataType::uint64_datatype(), true),
ColumnSchema::new(
CREATE_TIME,
ConcreteDataType::timestamp_microsecond_datatype(),
ConcreteDataType::timestamp_second_datatype(),
true,
),
ColumnSchema::new(
UPDATE_TIME,
ConcreteDataType::timestamp_microsecond_datatype(),
ConcreteDataType::timestamp_second_datatype(),
true,
),
ColumnSchema::new(
CHECK_TIME,
ConcreteDataType::timestamp_microsecond_datatype(),
ConcreteDataType::timestamp_second_datatype(),
true,
),
ColumnSchema::new(TABLE_COLLATION, ConcreteDataType::string_datatype(), true),
@@ -194,9 +193,9 @@ struct InformationSchemaTablesBuilder {
max_index_length: UInt64VectorBuilder,
data_free: UInt64VectorBuilder,
auto_increment: UInt64VectorBuilder,
create_time: TimestampMicrosecondVectorBuilder,
update_time: TimestampMicrosecondVectorBuilder,
check_time: TimestampMicrosecondVectorBuilder,
create_time: TimestampSecondVectorBuilder,
update_time: TimestampSecondVectorBuilder,
check_time: TimestampSecondVectorBuilder,
table_collation: StringVectorBuilder,
checksum: UInt64VectorBuilder,
create_options: StringVectorBuilder,
@@ -231,9 +230,9 @@ impl InformationSchemaTablesBuilder {
max_index_length: UInt64VectorBuilder::with_capacity(INIT_CAPACITY),
data_free: UInt64VectorBuilder::with_capacity(INIT_CAPACITY),
auto_increment: UInt64VectorBuilder::with_capacity(INIT_CAPACITY),
create_time: TimestampMicrosecondVectorBuilder::with_capacity(INIT_CAPACITY),
update_time: TimestampMicrosecondVectorBuilder::with_capacity(INIT_CAPACITY),
check_time: TimestampMicrosecondVectorBuilder::with_capacity(INIT_CAPACITY),
create_time: TimestampSecondVectorBuilder::with_capacity(INIT_CAPACITY),
update_time: TimestampSecondVectorBuilder::with_capacity(INIT_CAPACITY),
check_time: TimestampSecondVectorBuilder::with_capacity(INIT_CAPACITY),
table_collation: StringVectorBuilder::with_capacity(INIT_CAPACITY),
checksum: UInt64VectorBuilder::with_capacity(INIT_CAPACITY),
create_options: StringVectorBuilder::with_capacity(INIT_CAPACITY),
@@ -380,7 +379,7 @@ impl InformationSchemaTablesBuilder {
self.create_options
.push(Some(table_info.meta.options.to_string().as_ref()));
self.create_time
.push(Some(table_info.meta.created_on.timestamp_millis().into()));
.push(Some(table_info.meta.created_on.timestamp().into()));
self.temporary
.push(if matches!(table_type, TableType::Temporary) {

View File

@@ -1975,10 +1975,10 @@ async fn test_information_schema_dot_columns(instance: Arc<dyn MockInstance>) {
| greptime | public | numbers | number | int unsigned | TAG |
| greptime | information_schema | tables | auto_increment | bigint unsigned | FIELD |
| greptime | information_schema | tables | avg_row_length | bigint unsigned | FIELD |
| greptime | information_schema | tables | check_time | timestamp(6) | FIELD |
| greptime | information_schema | tables | check_time | timestamp(0) | FIELD |
| greptime | information_schema | tables | checksum | bigint unsigned | FIELD |
| greptime | information_schema | tables | create_options | string | FIELD |
| greptime | information_schema | tables | create_time | timestamp(6) | FIELD |
| greptime | information_schema | tables | create_time | timestamp(0) | FIELD |
| greptime | information_schema | tables | data_free | bigint unsigned | FIELD |
| greptime | information_schema | tables | data_length | bigint unsigned | FIELD |
| greptime | information_schema | tables | engine | string | FIELD |
@@ -1995,7 +1995,7 @@ async fn test_information_schema_dot_columns(instance: Arc<dyn MockInstance>) {
| greptime | information_schema | tables | table_schema | string | FIELD |
| greptime | information_schema | tables | table_type | string | FIELD |
| greptime | information_schema | tables | temporary | string | FIELD |
| greptime | information_schema | tables | update_time | timestamp(6) | FIELD |
| greptime | information_schema | tables | update_time | timestamp(0) | FIELD |
| greptime | information_schema | tables | version | bigint unsigned | FIELD |
+---------------+--------------------+------------+--------------------------+-----------------+---------------+";
@@ -2033,10 +2033,10 @@ async fn test_information_schema_dot_columns(instance: Arc<dyn MockInstance>) {
| another_catalog | information_schema | columns | table_schema | string | FIELD |
| another_catalog | information_schema | tables | auto_increment | bigint unsigned | FIELD |
| another_catalog | information_schema | tables | avg_row_length | bigint unsigned | FIELD |
| another_catalog | information_schema | tables | check_time | timestamp(6) | FIELD |
| another_catalog | information_schema | tables | check_time | timestamp(0) | FIELD |
| another_catalog | information_schema | tables | checksum | bigint unsigned | FIELD |
| another_catalog | information_schema | tables | create_options | string | FIELD |
| another_catalog | information_schema | tables | create_time | timestamp(6) | FIELD |
| another_catalog | information_schema | tables | create_time | timestamp(0) | FIELD |
| another_catalog | information_schema | tables | data_free | bigint unsigned | FIELD |
| another_catalog | information_schema | tables | data_length | bigint unsigned | FIELD |
| another_catalog | information_schema | tables | engine | string | FIELD |
@@ -2053,7 +2053,7 @@ async fn test_information_schema_dot_columns(instance: Arc<dyn MockInstance>) {
| another_catalog | information_schema | tables | table_schema | string | FIELD |
| another_catalog | information_schema | tables | table_type | string | FIELD |
| another_catalog | information_schema | tables | temporary | string | FIELD |
| another_catalog | information_schema | tables | update_time | timestamp(6) | FIELD |
| another_catalog | information_schema | tables | update_time | timestamp(0) | FIELD |
| another_catalog | information_schema | tables | version | bigint unsigned | FIELD |
+-----------------+--------------------+---------------+--------------------------+-----------------+---------------+";

View File

@@ -394,10 +394,10 @@ select * from information_schema.columns order by table_schema, table_name, colu
| greptime | information_schema | table_privileges | table_schema | 3 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | tables | auto_increment | 16 | | | 20 | 0 | | | | | | select,insert | | UInt64 | bigint unsigned | FIELD | | Yes | bigint unsigned | | |
| greptime | information_schema | tables | avg_row_length | 10 | | | 20 | 0 | | | | | | select,insert | | UInt64 | bigint unsigned | FIELD | | Yes | bigint unsigned | | |
| greptime | information_schema | tables | check_time | 19 | | | | | 6 | | | | | select,insert | | TimestampMicrosecond | timestamp(6) | FIELD | | Yes | timestamp(6) | | |
| greptime | information_schema | tables | check_time | 19 | | | | | 0 | | | | | select,insert | | TimestampSecond | timestamp(0) | FIELD | | Yes | timestamp(0) | | |
| greptime | information_schema | tables | checksum | 21 | | | 20 | 0 | | | | | | select,insert | | UInt64 | bigint unsigned | FIELD | | Yes | bigint unsigned | | |
| greptime | information_schema | tables | create_options | 22 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | Yes | string | | |
| greptime | information_schema | tables | create_time | 17 | | | | | 6 | | | | | select,insert | | TimestampMicrosecond | timestamp(6) | FIELD | | Yes | timestamp(6) | | |
| greptime | information_schema | tables | create_time | 17 | | | | | 0 | | | | | select,insert | | TimestampSecond | timestamp(0) | FIELD | | Yes | timestamp(0) | | |
| greptime | information_schema | tables | data_free | 15 | | | 20 | 0 | | | | | | select,insert | | UInt64 | bigint unsigned | FIELD | | Yes | bigint unsigned | | |
| greptime | information_schema | tables | data_length | 6 | | | 20 | 0 | | | | | | select,insert | | UInt64 | bigint unsigned | FIELD | | Yes | bigint unsigned | | |
| greptime | information_schema | tables | engine | 11 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | Yes | string | | |
@@ -414,7 +414,7 @@ select * from information_schema.columns order by table_schema, table_name, colu
| greptime | information_schema | tables | table_schema | 2 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | tables | table_type | 4 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | tables | temporary | 24 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | Yes | string | | |
| greptime | information_schema | tables | update_time | 18 | | | | | 6 | | | | | select,insert | | TimestampMicrosecond | timestamp(6) | FIELD | | Yes | timestamp(6) | | |
| greptime | information_schema | tables | update_time | 18 | | | | | 0 | | | | | select,insert | | TimestampSecond | timestamp(0) | FIELD | | Yes | timestamp(0) | | |
| greptime | information_schema | tables | version | 12 | | | 20 | 0 | | | | | | select,insert | | UInt64 | bigint unsigned | FIELD | | Yes | bigint unsigned | | |
| greptime | information_schema | triggers | flownode_id | 4 | | | 20 | 0 | | | | | | select,insert | | UInt64 | bigint unsigned | FIELD | | Yes | bigint unsigned | | |
| greptime | information_schema | triggers | trigger_definition | 3 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
@@ -488,6 +488,17 @@ order by table_name;
| foo |
+------------+
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'my_db'
AND create_time > NOW() - INTERVAL 1 MINUTE;
+------------+
| table_name |
+------------+
| foo |
+------------+
select table_name
from information_schema.tables
where table_schema in ('my_db', 'public')

View File

@@ -32,6 +32,11 @@ from information_schema.tables
where table_schema = 'my_db'
order by table_name;
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'my_db'
AND create_time > NOW() - INTERVAL 1 MINUTE;
select table_name
from information_schema.tables
where table_schema in ('my_db', 'public')