Skip to main content

query/sql/
show_create_table.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Implementation of `SHOW CREATE TABLE` statement.
16
17use std::collections::HashMap;
18
19use arrow_schema::extension::ExtensionType;
20use common_meta::SchemaOptions;
21use datatypes::extension::json::{Json2ExtensionType, parse_legacy_json2_settings};
22use datatypes::schema::{
23    COLUMN_FULLTEXT_OPT_KEY_ANALYZER, COLUMN_FULLTEXT_OPT_KEY_BACKEND,
24    COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE, COLUMN_FULLTEXT_OPT_KEY_FALSE_POSITIVE_RATE,
25    COLUMN_FULLTEXT_OPT_KEY_GRANULARITY, COLUMN_SKIPPING_INDEX_OPT_KEY_FALSE_POSITIVE_RATE,
26    COLUMN_SKIPPING_INDEX_OPT_KEY_GRANULARITY, COLUMN_SKIPPING_INDEX_OPT_KEY_TYPE, COMMENT_KEY,
27    ColumnDefaultConstraint, ColumnSchema, FulltextBackend, SchemaRef,
28};
29use datatypes::types::JsonFormat;
30use snafu::ResultExt;
31use sql::ast::{ColumnDef, ColumnOption, ColumnOptionDef, DataType, Expr, Ident, ObjectName};
32use sql::dialect::GreptimeDbDialect;
33use sql::parser::ParserContext;
34use sql::statements::create::{Column, ColumnExtensions, CreateTable, TableConstraint};
35use sql::statements::{self, OptionMap, concrete_data_type_to_sql_data_type};
36use store_api::metric_engine_consts::{
37    LOGICAL_TABLE_METADATA_KEY, is_metric_engine, is_metric_engine_internal_column,
38};
39use table::metadata::{TableInfoRef, TableMeta};
40use table::requests::{
41    COMMENT_KEY as TABLE_COMMENT_KEY, FILE_TABLE_META_KEY, RELATIONAL_CONNECTION_KEY,
42    RELATIONAL_META_KEY, RELATIONAL_REMOTE_TABLE_KEY, RelationalOptions, SKIP_WAL_KEY, TTL_KEY,
43    WRITE_BUFFER_SIZE_KEY,
44};
45
46use crate::error::{
47    ConvertSqlTypeSnafu, ConvertSqlValueSnafu, GetFulltextOptionsSnafu,
48    GetSkippingIndexOptionsSnafu, Result, SqlSnafu,
49};
50
51fn is_metric_logical_table(table_meta: &TableMeta) -> bool {
52    is_metric_engine(&table_meta.engine)
53        && table_meta
54            .options
55            .extra_options
56            .contains_key(LOGICAL_TABLE_METADATA_KEY)
57}
58
59/// Generates CREATE TABLE options from given table metadata and schema-level options.
60fn create_sql_options(table_meta: &TableMeta, schema_options: Option<SchemaOptions>) -> OptionMap {
61    let table_opts = &table_meta.options;
62    let logical_metric = is_metric_logical_table(table_meta);
63    let mut options = OptionMap::default();
64    if let Some(write_buffer_size) = table_opts.write_buffer_size {
65        options.insert(
66            WRITE_BUFFER_SIZE_KEY.to_string(),
67            write_buffer_size.to_string(),
68        );
69    }
70    // Logical metric tables do not store retention. Omit a retention TTL,
71    // including the database TTL fallback, so exported DDL can be replayed.
72    // Keep an explicit `ttl=instant`, which selects flow-only ingestion.
73    if let Some(ttl) = table_opts.ttl {
74        if !logical_metric || ttl.is_instant() {
75            options.insert(TTL_KEY.to_string(), ttl.to_string());
76        }
77    } else if !logical_metric
78        && let Some(database_ttl) = schema_options
79            .as_ref()
80            .and_then(|o| o.ttl)
81            .map(|ttl| ttl.to_string())
82    {
83        options.insert(TTL_KEY.to_string(), database_ttl);
84    }
85    for (k, v) in table_opts
86        .extra_options
87        .iter()
88        .filter(|(k, _)| k != &FILE_TABLE_META_KEY && k != &RELATIONAL_META_KEY)
89    {
90        options.insert(k.clone(), v.clone());
91    }
92    if let Some(encoded) = table_opts.extra_options.get(RELATIONAL_META_KEY)
93        && let Ok(opts) = serde_json::from_str::<RelationalOptions>(encoded)
94    {
95        options.insert(RELATIONAL_CONNECTION_KEY.to_string(), opts.connection);
96        options.insert(RELATIONAL_REMOTE_TABLE_KEY.to_string(), opts.remote_table);
97    }
98    if table_opts.skip_wal {
99        options.insert(SKIP_WAL_KEY.to_string(), true.to_string());
100    }
101    options
102}
103
104#[inline]
105fn column_option_def(option: ColumnOption) -> ColumnOptionDef {
106    ColumnOptionDef { name: None, option }
107}
108
109fn create_column(column_schema: &ColumnSchema, quote_style: char) -> Result<Column> {
110    let name = &column_schema.name;
111    let mut options = Vec::with_capacity(2);
112    let mut extensions = ColumnExtensions::default();
113
114    if column_schema.is_nullable() {
115        options.push(column_option_def(ColumnOption::Null));
116    } else {
117        options.push(column_option_def(ColumnOption::NotNull));
118    }
119
120    if let Some(c) = column_schema.default_constraint() {
121        let expr = match c {
122            ColumnDefaultConstraint::Value(v) => Expr::Value(
123                statements::value_to_sql_value(v)
124                    .with_context(|_| ConvertSqlValueSnafu { value: v.clone() })?
125                    .into(),
126            ),
127            ColumnDefaultConstraint::Function(expr) => {
128                ParserContext::parse_function(expr, &GreptimeDbDialect {}).context(SqlSnafu)?
129            }
130        };
131
132        options.push(column_option_def(ColumnOption::Default(expr)));
133    }
134
135    if let Some(c) = column_schema.metadata().get(COMMENT_KEY) {
136        options.push(column_option_def(ColumnOption::Comment(c.clone())));
137    }
138
139    if let Some(opt) = column_schema
140        .fulltext_options()
141        .context(GetFulltextOptionsSnafu)?
142        && opt.enable
143    {
144        let mut map = HashMap::from([
145            (
146                COLUMN_FULLTEXT_OPT_KEY_ANALYZER.to_string(),
147                opt.analyzer.to_string(),
148            ),
149            (
150                COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE.to_string(),
151                opt.case_sensitive.to_string(),
152            ),
153            (
154                COLUMN_FULLTEXT_OPT_KEY_BACKEND.to_string(),
155                opt.backend.to_string(),
156            ),
157        ]);
158        if opt.backend == FulltextBackend::Bloom {
159            map.insert(
160                COLUMN_FULLTEXT_OPT_KEY_GRANULARITY.to_string(),
161                opt.granularity.to_string(),
162            );
163            map.insert(
164                COLUMN_FULLTEXT_OPT_KEY_FALSE_POSITIVE_RATE.to_string(),
165                opt.false_positive_rate().to_string(),
166            );
167        }
168        extensions.fulltext_index_options = Some(map.into());
169    }
170
171    if let Some(opt) = column_schema
172        .skipping_index_options()
173        .context(GetSkippingIndexOptionsSnafu)?
174    {
175        let map = HashMap::from([
176            (
177                COLUMN_SKIPPING_INDEX_OPT_KEY_GRANULARITY.to_string(),
178                opt.granularity.to_string(),
179            ),
180            (
181                COLUMN_SKIPPING_INDEX_OPT_KEY_FALSE_POSITIVE_RATE.to_string(),
182                opt.false_positive_rate().to_string(),
183            ),
184            (
185                COLUMN_SKIPPING_INDEX_OPT_KEY_TYPE.to_string(),
186                opt.index_type.to_string(),
187            ),
188        ]);
189        extensions.skipping_index_options = Some(map.into());
190    }
191
192    if column_schema.is_inverted_indexed() {
193        extensions.inverted_index_options = Some(HashMap::new().into());
194    }
195
196    if let Some(opt) = column_schema.compression_options()? {
197        extensions.compression_options = Some(opt.to_options_map().into());
198    }
199
200    let mut data_type = concrete_data_type_to_sql_data_type(&column_schema.data_type)
201        .with_context(|_| ConvertSqlTypeSnafu {
202            datatype: column_schema.data_type.clone(),
203        })?;
204
205    if matches!(
206        &column_schema.data_type,
207        datatypes::data_type::ConcreteDataType::Json(json_type)
208            if matches!(json_type.format, JsonFormat::Json2(_))
209    ) {
210        data_type = DataType::Custom(ObjectName::from(vec![Ident::new("JSON2")]), vec![]);
211    }
212
213    let settings = if let Some(extension) = column_schema.extension_type::<Json2ExtensionType>()? {
214        Some(extension.metadata().json_settings().clone())
215    } else {
216        parse_legacy_json2_settings(column_schema.metadata())?
217    };
218    if let Some(settings) = settings {
219        extensions.set_json_settings(settings).context(SqlSnafu)?;
220    }
221
222    Ok(Column {
223        column_def: ColumnDef {
224            name: Ident::with_quote(quote_style, name),
225            data_type,
226            options,
227        },
228        extensions,
229    })
230}
231
232/// Returns the primary key columns for `SHOW CREATE TABLE` statement.
233///
234/// For metric engine, it will only return the primary key columns that are not internal columns.
235fn primary_key_columns_for_show_create<'a>(
236    table_meta: &'a TableMeta,
237    engine: &str,
238) -> Vec<&'a String> {
239    let is_metric_engine = is_metric_engine(engine);
240    if is_metric_engine {
241        table_meta
242            .row_key_column_names()
243            .filter(|name| !is_metric_engine_internal_column(name))
244            .collect()
245    } else {
246        table_meta.row_key_column_names().collect()
247    }
248}
249
250fn create_table_constraints(
251    engine: &str,
252    schema: &SchemaRef,
253    table_meta: &TableMeta,
254    quote_style: char,
255) -> Vec<TableConstraint> {
256    let mut constraints = Vec::with_capacity(2);
257    if let Some(timestamp_column) = schema.timestamp_column() {
258        let column_name = &timestamp_column.name;
259        constraints.push(TableConstraint::TimeIndex {
260            column: Ident::with_quote(quote_style, column_name),
261        });
262    }
263    if !table_meta.primary_key_indices.is_empty() {
264        let columns = primary_key_columns_for_show_create(table_meta, engine)
265            .into_iter()
266            .map(|name| Ident::with_quote(quote_style, name))
267            .collect();
268        constraints.push(TableConstraint::PrimaryKey { columns });
269    }
270
271    constraints
272}
273
274/// Create a CreateTable statement from table info.
275pub fn create_table_stmt(
276    table_info: &TableInfoRef,
277    schema_options: Option<SchemaOptions>,
278    quote_style: char,
279) -> Result<CreateTable> {
280    let table_meta = &table_info.meta;
281    let table_name = &table_info.name;
282    let schema = &table_info.meta.schema;
283    let is_metric_engine = is_metric_engine(&table_meta.engine);
284    let columns = schema
285        .column_schemas()
286        .iter()
287        .filter_map(|c| {
288            if is_metric_engine && is_metric_engine_internal_column(&c.name) {
289                None
290            } else {
291                Some(create_column(c, quote_style))
292            }
293        })
294        .collect::<Result<Vec<_>>>()?;
295
296    let constraints = create_table_constraints(&table_meta.engine, schema, table_meta, quote_style);
297
298    let mut options = create_sql_options(table_meta, schema_options);
299    if let Some(comment) = &table_info.desc
300        && options.get(TABLE_COMMENT_KEY).is_none()
301    {
302        options.insert(format!("'{TABLE_COMMENT_KEY}'"), comment.clone());
303    }
304
305    Ok(CreateTable {
306        if_not_exists: true,
307        table_id: table_info.ident.table_id,
308        name: ObjectName::from(vec![Ident::with_quote(quote_style, table_name)]),
309        columns,
310        engine: table_meta.engine.clone(),
311        constraints,
312        options,
313        partitions: None,
314    })
315}
316
317#[cfg(test)]
318mod tests {
319    use std::sync::Arc;
320    use std::time::Duration;
321
322    use common_time::timestamp::TimeUnit;
323    use datatypes::extension::json::JsonExtensionType;
324    use datatypes::prelude::ConcreteDataType;
325    use datatypes::schema::{FulltextOptions, Schema, SchemaRef, SkippingIndexOptions};
326    use table::metadata::*;
327    use table::requests::{
328        FILE_TABLE_FORMAT_KEY, FILE_TABLE_LOCATION_KEY, FILE_TABLE_META_KEY,
329        RELATIONAL_CONNECTION_KEY, RELATIONAL_REMOTE_TABLE_KEY, TableOptions,
330    };
331
332    use super::*;
333
334    #[test]
335    fn test_show_create_table_sql() {
336        let schema = vec![
337            ColumnSchema::new("id", ConcreteDataType::uint32_datatype(), true)
338                .with_skipping_options(SkippingIndexOptions {
339                    granularity: 4096,
340                    ..Default::default()
341                })
342                .unwrap(),
343            ColumnSchema::new("host", ConcreteDataType::string_datatype(), true)
344                .with_inverted_index(true),
345            ColumnSchema::new("cpu", ConcreteDataType::float64_datatype(), true),
346            ColumnSchema::new("disk", ConcreteDataType::float32_datatype(), true),
347            ColumnSchema::new("msg", ConcreteDataType::string_datatype(), true)
348                .with_fulltext_options(FulltextOptions {
349                    enable: true,
350                    ..Default::default()
351                })
352                .unwrap(),
353            ColumnSchema::new("embedding", ConcreteDataType::vector_datatype(4), true),
354            ColumnSchema::new(
355                "ts",
356                ConcreteDataType::timestamp_datatype(TimeUnit::Millisecond),
357                false,
358            )
359            .with_default_constraint(Some(ColumnDefaultConstraint::Function(String::from(
360                "current_timestamp()",
361            ))))
362            .unwrap()
363            .with_time_index(true),
364        ];
365
366        let table_schema = SchemaRef::new(Schema::new(schema));
367        let table_name = "system_metrics";
368        let schema_name = "public".to_string();
369        let catalog_name = "greptime".to_string();
370
371        let mut options = table::requests::TableOptions {
372            ttl: Some(Duration::from_secs(30).into()),
373            skip_wal: true,
374            ..Default::default()
375        };
376
377        let _ = options
378            .extra_options
379            .insert("compaction.type".to_string(), "twcs".to_string());
380
381        let meta = TableMetaBuilder::empty()
382            .schema(table_schema)
383            .primary_key_indices(vec![0, 1])
384            .value_indices(vec![2, 3])
385            .engine("mito".to_string())
386            .next_column_id(0)
387            .options(options)
388            .created_on(Default::default())
389            .build()
390            .unwrap();
391
392        let info = Arc::new(
393            TableInfoBuilder::default()
394                .table_id(1024)
395                .table_version(0 as TableVersion)
396                .name(table_name)
397                .schema_name(schema_name)
398                .catalog_name(catalog_name)
399                .desc(None)
400                .table_type(TableType::Base)
401                .meta(meta)
402                .build()
403                .unwrap(),
404        );
405
406        let stmt = create_table_stmt(&info, None, '"').unwrap();
407
408        let sql = format!("\n{}", stmt);
409        assert_eq!(
410            r#"
411CREATE TABLE IF NOT EXISTS "system_metrics" (
412  "id" INT UNSIGNED NULL SKIPPING INDEX WITH(false_positive_rate = '0.01', granularity = '4096', type = 'BLOOM'),
413  "host" STRING NULL INVERTED INDEX,
414  "cpu" DOUBLE NULL,
415  "disk" FLOAT NULL,
416  "msg" STRING NULL FULLTEXT INDEX WITH(analyzer = 'English', backend = 'bloom', case_sensitive = 'false', false_positive_rate = '0.01', granularity = '10240'),
417  "embedding" VECTOR(4) NULL,
418  "ts" TIMESTAMP(3) NOT NULL DEFAULT current_timestamp(),
419  TIME INDEX ("ts"),
420  PRIMARY KEY ("id", "host")
421)
422ENGINE=mito
423WITH(
424  'compaction.type' = 'twcs',
425  skip_wal = 'true',
426  ttl = '30s'
427)"#,
428            sql
429        );
430
431        let mut table_meta = info.meta.clone();
432        table_meta.options.skip_wal = false;
433        table_meta
434            .options
435            .extra_options
436            .insert(SKIP_WAL_KEY.to_string(), false.to_string());
437        assert_eq!(
438            Some("false"),
439            create_sql_options(&table_meta, None).get(SKIP_WAL_KEY)
440        );
441
442        let mut schema_options = SchemaOptions::default();
443        schema_options
444            .extra_options
445            .insert(SKIP_WAL_KEY.to_string(), true.to_string());
446        assert_eq!(
447            Some("false"),
448            create_sql_options(&table_meta, Some(schema_options)).get(SKIP_WAL_KEY)
449        );
450    }
451
452    #[test]
453    fn test_show_create_legacy_json_with_json_extension() {
454        let mut json_column = ColumnSchema::new("j", ConcreteDataType::json_datatype(), true);
455        json_column.with_extension_type(&JsonExtensionType);
456
457        let table_schema = SchemaRef::new(Schema::new(vec![
458            json_column,
459            ColumnSchema::new(
460                "ts",
461                ConcreteDataType::timestamp_datatype(TimeUnit::Millisecond),
462                false,
463            )
464            .with_time_index(true),
465        ]));
466        let table_name = "legacy_json";
467        let meta = TableMetaBuilder::empty()
468            .schema(table_schema)
469            .primary_key_indices(vec![])
470            .value_indices(vec![0])
471            .engine("mito".to_string())
472            .next_column_id(0)
473            .options(Default::default())
474            .created_on(Default::default())
475            .build()
476            .unwrap();
477
478        let info = Arc::new(
479            TableInfoBuilder::default()
480                .table_id(1024)
481                .table_version(0 as TableVersion)
482                .name(table_name)
483                .schema_name("public")
484                .catalog_name("greptime")
485                .desc(None)
486                .table_type(TableType::Base)
487                .meta(meta)
488                .build()
489                .unwrap(),
490        );
491
492        let stmt = create_table_stmt(&info, None, '"').unwrap();
493        let sql = format!("\n{}", stmt);
494        assert_eq!(
495            r#"
496CREATE TABLE IF NOT EXISTS "legacy_json" (
497  "j" JSON NULL,
498  "ts" TIMESTAMP(3) NOT NULL,
499  TIME INDEX ("ts")
500)
501ENGINE=mito
502"#,
503            sql
504        );
505    }
506
507    #[test]
508    fn test_show_create_external_table_sql() {
509        let schema = vec![
510            ColumnSchema::new("host", ConcreteDataType::string_datatype(), true),
511            ColumnSchema::new("cpu", ConcreteDataType::float64_datatype(), true),
512        ];
513        let table_schema = SchemaRef::new(Schema::new(schema));
514        let table_name = "system_metrics";
515        let schema_name = "public".to_string();
516        let catalog_name = "greptime".to_string();
517        let mut options: TableOptions = Default::default();
518        let _ = options
519            .extra_options
520            .insert(FILE_TABLE_LOCATION_KEY.to_string(), "foo.csv".to_string());
521        let _ = options.extra_options.insert(
522            FILE_TABLE_META_KEY.to_string(),
523            "{{\"files\":[\"foo.csv\"]}}".to_string(),
524        );
525        let _ = options
526            .extra_options
527            .insert(FILE_TABLE_FORMAT_KEY.to_string(), "csv".to_string());
528        let meta = TableMetaBuilder::empty()
529            .schema(table_schema)
530            .primary_key_indices(vec![])
531            .engine("file".to_string())
532            .next_column_id(0)
533            .options(options)
534            .created_on(Default::default())
535            .build()
536            .unwrap();
537
538        let info = Arc::new(
539            TableInfoBuilder::default()
540                .table_id(1024)
541                .table_version(0 as TableVersion)
542                .name(table_name)
543                .schema_name(schema_name)
544                .catalog_name(catalog_name)
545                .desc(None)
546                .table_type(TableType::Base)
547                .meta(meta)
548                .build()
549                .unwrap(),
550        );
551
552        let stmt = create_table_stmt(&info, None, '"').unwrap();
553
554        let sql = format!("\n{}", stmt);
555        assert_eq!(
556            r#"
557CREATE EXTERNAL TABLE IF NOT EXISTS "system_metrics" (
558  "host" STRING NULL,
559  "cpu" DOUBLE NULL,
560
561)
562ENGINE=file
563WITH(
564  format = 'csv',
565  location = 'foo.csv'
566)"#,
567            sql
568        );
569    }
570
571    #[test]
572    fn test_show_create_table_redacts_relational_meta() {
573        let table_schema = SchemaRef::new(Schema::new(vec![]));
574        let mut options: TableOptions = Default::default();
575        let _ = options.extra_options.insert(
576            RELATIONAL_META_KEY.to_string(),
577            "{\"connection\":\"mysql://user:secret@127.0.0.1:3306/db\",\"remote_table\":\"sample\"}"
578                .to_string(),
579        );
580        let _ = options
581            .extra_options
582            .insert(FILE_TABLE_LOCATION_KEY.to_string(), "foo.csv".to_string());
583        let meta = TableMetaBuilder::empty()
584            .schema(table_schema)
585            .primary_key_indices(vec![])
586            .engine("relational".to_string())
587            .next_column_id(0)
588            .options(options)
589            .created_on(Default::default())
590            .build()
591            .unwrap();
592
593        let opts = create_sql_options(&meta, None);
594        let str_map = opts.to_str_map();
595        assert!(!str_map.contains_key(RELATIONAL_META_KEY));
596        assert!(str_map.contains_key(FILE_TABLE_LOCATION_KEY));
597        assert!(str_map.contains_key(RELATIONAL_CONNECTION_KEY));
598        assert_eq!(str_map.get(RELATIONAL_REMOTE_TABLE_KEY), Some(&"sample"));
599    }
600
601    #[test]
602    fn test_show_create_external_relational_table_sql() {
603        let table_schema = SchemaRef::new(Schema::new(vec![]));
604        let table_name = "system_metrics";
605        let mut options: TableOptions = Default::default();
606        let _ = options.extra_options.insert(
607            RELATIONAL_META_KEY.to_string(),
608            "{\"connection\":\"mysql://user:secret@127.0.0.1:3306/db\",\"remote_table\":\"sample\"}"
609                .to_string(),
610        );
611        let meta = TableMetaBuilder::empty()
612            .schema(table_schema)
613            .primary_key_indices(vec![])
614            .engine("relational".to_string())
615            .next_column_id(0)
616            .options(options)
617            .created_on(Default::default())
618            .build()
619            .unwrap();
620
621        let info = Arc::new(
622            TableInfoBuilder::default()
623                .table_id(1024)
624                .table_version(0 as TableVersion)
625                .name(table_name)
626                .schema_name("public".to_string())
627                .catalog_name("greptime".to_string())
628                .desc(None)
629                .table_type(TableType::Base)
630                .meta(meta)
631                .build()
632                .unwrap(),
633        );
634
635        let stmt = create_table_stmt(&info, None, '"').unwrap();
636        let sql = format!("{stmt}");
637        assert!(sql.contains("CREATE EXTERNAL TABLE"));
638        assert!(sql.contains("ENGINE=relational"));
639        assert!(sql.contains("connection = '******'"));
640        assert!(sql.contains("remote_table = 'sample'"));
641        assert!(!sql.contains("secret"));
642    }
643
644    #[test]
645    fn test_show_create_omits_stored_retention_ttl_on_logical_table() {
646        use store_api::metric_engine_consts::{LOGICAL_TABLE_METADATA_KEY, METRIC_ENGINE_NAME};
647
648        // Logical tables created before retention was moved to the physical
649        // table still carry it in their metadata.
650        let schema = SchemaRef::new(Schema::new(vec![
651            ColumnSchema::new(
652                "ts",
653                ConcreteDataType::timestamp_datatype(TimeUnit::Millisecond),
654                false,
655            )
656            .with_time_index(true),
657        ]));
658        let mut options = TableOptions {
659            ttl: Some(Duration::from_secs(86_400).into()),
660            ..Default::default()
661        };
662        options
663            .extra_options
664            .insert(LOGICAL_TABLE_METADATA_KEY.to_string(), "phy".to_string());
665        let meta = TableMetaBuilder::empty()
666            .schema(schema)
667            .primary_key_indices(vec![])
668            .engine(METRIC_ENGINE_NAME.to_string())
669            .next_column_id(1)
670            .options(options)
671            .created_on(Default::default())
672            .build()
673            .unwrap();
674
675        let options = create_sql_options(&meta, None);
676        assert!(options.get(TTL_KEY).is_none());
677    }
678}