mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-07 13:52:59 +00:00
feat: ignore internal columns in SHOW CREATE TABLE (#3950)
* feat: ignore internal columns * chore: add new line * chore: apply suggestions from CR * chore: apply suggestions from CR
This commit is contained in:
@@ -24,6 +24,7 @@ use sql::dialect::GreptimeDbDialect;
|
||||
use sql::parser::ParserContext;
|
||||
use sql::statements::create::{CreateTable, TIME_INDEX};
|
||||
use sql::statements::{self, OptionMap};
|
||||
use store_api::metric_engine_consts::{is_metric_engine, is_metric_engine_internal_column};
|
||||
use table::metadata::{TableInfoRef, TableMeta};
|
||||
use table::requests::{FILE_TABLE_META_KEY, TTL_KEY, WRITE_BUFFER_SIZE_KEY};
|
||||
|
||||
@@ -96,6 +97,7 @@ fn create_column_def(column_schema: &ColumnSchema, quote_style: char) -> Result<
|
||||
}
|
||||
|
||||
fn create_table_constraints(
|
||||
engine: &str,
|
||||
schema: &SchemaRef,
|
||||
table_meta: &TableMeta,
|
||||
quote_style: char,
|
||||
@@ -111,9 +113,16 @@ fn create_table_constraints(
|
||||
});
|
||||
}
|
||||
if !table_meta.primary_key_indices.is_empty() {
|
||||
let is_metric_engine = is_metric_engine(engine);
|
||||
let columns = table_meta
|
||||
.row_key_column_names()
|
||||
.map(|name| Ident::with_quote(quote_style, name))
|
||||
.flat_map(|name| {
|
||||
if is_metric_engine && is_metric_engine_internal_column(name) {
|
||||
None
|
||||
} else {
|
||||
Some(Ident::with_quote(quote_style, name))
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
constraints.push(TableConstraint::Unique {
|
||||
name: None,
|
||||
@@ -131,14 +140,20 @@ pub fn create_table_stmt(table_info: &TableInfoRef, quote_style: char) -> Result
|
||||
let table_meta = &table_info.meta;
|
||||
let table_name = &table_info.name;
|
||||
let schema = &table_info.meta.schema;
|
||||
|
||||
let is_metric_engine = is_metric_engine(&table_meta.engine);
|
||||
let columns = schema
|
||||
.column_schemas()
|
||||
.iter()
|
||||
.map(|c| create_column_def(c, quote_style))
|
||||
.filter_map(|c| {
|
||||
if is_metric_engine && is_metric_engine_internal_column(&c.name) {
|
||||
None
|
||||
} else {
|
||||
Some(create_column_def(c, quote_style))
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
let constraints = create_table_constraints(schema, table_meta, quote_style);
|
||||
let constraints = create_table_constraints(&table_meta.engine, schema, table_meta, quote_style);
|
||||
|
||||
Ok(CreateTable {
|
||||
if_not_exists: true,
|
||||
|
||||
@@ -70,3 +70,13 @@ pub const LOGICAL_TABLE_METADATA_KEY: &str = "on_physical_table";
|
||||
/// HashMap key to be used in the region server's extension response.
|
||||
/// Represent a list of column metadata that are added to physical table.
|
||||
pub const ALTER_PHYSICAL_EXTENSION_KEY: &str = "ALTER_PHYSICAL";
|
||||
|
||||
/// Returns true if it's a internal column of the metric engine.
|
||||
pub fn is_metric_engine_internal_column(name: &str) -> bool {
|
||||
name == DATA_SCHEMA_TABLE_ID_COLUMN_NAME || name == DATA_SCHEMA_TSID_COLUMN_NAME
|
||||
}
|
||||
|
||||
/// Returns true if it's metric engine
|
||||
pub fn is_metric_engine(name: &str) -> bool {
|
||||
name == METRIC_ENGINE_NAME
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user