| 879 | |
| 880 | template <typename LogElement> |
| 881 | ASTPtr SystemLog<LogElement>::getCreateTableQuery() |
| 882 | { |
| 883 | auto create = make_intrusive<ASTCreateQuery>(); |
| 884 | |
| 885 | create->setDatabase(table_id.database_name); |
| 886 | create->setTable(table_id.table_name); |
| 887 | |
| 888 | auto new_columns_list = make_intrusive<ASTColumns>(); |
| 889 | auto ordinary_columns = LogElement::getColumnsDescription(); |
| 890 | auto alias_columns = LogElement::getNamesAndAliases(); |
| 891 | /// S3-backed engines do not support alias columns; `shouldSkipAliasColumns` returns |
| 892 | /// `true` for `SharedSystemLogFlushPolicy` and for `DefaultSystemLogFlushPolicy` when |
| 893 | /// `default_system_log_flush_policy.skip_alias_columns` is set to `true` in config. |
| 894 | if (!flush_policy->shouldSkipAliasColumns()) |
| 895 | ordinary_columns.setAliases(alias_columns); |
| 896 | |
| 897 | new_columns_list->set(new_columns_list->columns, InterpreterCreateQuery::formatColumns(ordinary_columns)); |
| 898 | |
| 899 | ParserStorageWithComment storage_parser; |
| 900 | |
| 901 | ASTPtr storage_with_comment_ast = parseQuery( |
| 902 | storage_parser, storage_def.data(), storage_def.data() + storage_def.size(), |
| 903 | "Storage to create table for " + LogElement::name(), 0, DBMS_DEFAULT_MAX_PARSER_DEPTH, DBMS_DEFAULT_MAX_PARSER_BACKTRACKS); |
| 904 | |
| 905 | StorageWithComment & storage_with_comment = storage_with_comment_ast->as<StorageWithComment &>(); |
| 906 | |
| 907 | /// The default engine string wraps `PARTITION BY` / `ORDER BY` / `PRIMARY KEY` / |
| 908 | /// `SAMPLE BY` arguments in artificial parentheses so the parser accepts both |
| 909 | /// single-expression and tuple forms. Clear the `parenthesized` flag so the formatter |
| 910 | /// does not emit those artificial wrapping parens in `system.tables.engine_full`. |
| 911 | if (auto * storage = storage_with_comment.storage->as<ASTStorage>()) |
| 912 | { |
| 913 | if (storage->partition_by) |
| 914 | storage->partition_by->setParenthesized(false); |
| 915 | if (storage->order_by) |
| 916 | storage->order_by->setParenthesized(false); |
| 917 | if (storage->primary_key) |
| 918 | storage->primary_key->setParenthesized(false); |
| 919 | if (storage->sample_by) |
| 920 | storage->sample_by->setParenthesized(false); |
| 921 | } |
| 922 | |
| 923 | create->set(create->storage, storage_with_comment.storage); |
| 924 | create->set(create->comment, storage_with_comment.comment); |
| 925 | |
| 926 | const auto & engine = create->storage->engine->as<ASTFunction &>(); |
| 927 | |
| 928 | /// Add secondary indexes (minmax on time columns) for MergeTree engines only, |
| 929 | /// since other engines (e.g. Null) do not support skipping indices. |
| 930 | if (endsWith(engine.name, "MergeTree")) |
| 931 | { |
| 932 | auto indices = make_intrusive<ASTExpressionList>(); |
| 933 | |
| 934 | auto add_index = [&](const char * definition) |
| 935 | { |
| 936 | ParserIndexDeclaration parser; |
| 937 | ASTPtr ast = parseQuery(parser, definition, definition + strlen(definition), |
| 938 | "index declaration for " + LogElement::name(), 0, DBMS_DEFAULT_MAX_PARSER_DEPTH, DBMS_DEFAULT_MAX_PARSER_BACKTRACKS); |
no test coverage detected