| 30 | |
| 31 | |
| 32 | String InterpreterShowColumnsQuery::getRewrittenQuery() |
| 33 | { |
| 34 | const auto & query = query_ptr->as<ASTShowColumnsQuery &>(); |
| 35 | |
| 36 | ClientInfo::Interface client_interface = getContext()->getClientInfo().interface; |
| 37 | const bool use_mysql_types = (client_interface == ClientInfo::Interface::MYSQL); // connection made through MySQL wire protocol |
| 38 | |
| 39 | const auto & settings = getContext()->getSettingsRef(); |
| 40 | const bool remap_string_as_text = settings[Setting::mysql_map_string_to_text_in_show_columns]; |
| 41 | const bool remap_fixed_string_as_text = settings[Setting::mysql_map_fixed_string_to_text_in_show_columns]; |
| 42 | |
| 43 | WriteBufferFromOwnString buf_database; |
| 44 | String resolved_database = getContext()->resolveDatabase(query.database); |
| 45 | String database = escapeString(resolved_database); |
| 46 | String table = escapeString(query.table); |
| 47 | |
| 48 | String rewritten_query; |
| 49 | if (use_mysql_types) |
| 50 | { |
| 51 | /// Cheapskate SQL-based mapping from native types to MySQL types, see https://dev.mysql.com/doc/refman/8.0/en/data-types.html |
| 52 | /// Known issues: |
| 53 | /// - Enums are translated to TEXT |
| 54 | rewritten_query += fmt::format( |
| 55 | R"( |
| 56 | WITH map( |
| 57 | 'Int8', 'TINYINT', |
| 58 | 'Int16', 'SMALLINT', |
| 59 | 'Int32', 'INTEGER', |
| 60 | 'Int64', 'BIGINT', |
| 61 | 'UInt8', 'TINYINT UNSIGNED', |
| 62 | 'UInt16', 'SMALLINT UNSIGNED', |
| 63 | 'UInt32', 'INTEGER UNSIGNED', |
| 64 | 'UInt64', 'BIGINT UNSIGNED', |
| 65 | 'Float32', 'FLOAT', |
| 66 | 'Float64', 'DOUBLE', |
| 67 | 'UUID', 'CHAR', |
| 68 | 'Bool', 'TINYINT', |
| 69 | 'Date', 'DATE', |
| 70 | 'Date32', 'DATE', |
| 71 | 'DateTime', 'DATETIME', |
| 72 | 'DateTime64', 'DATETIME', |
| 73 | 'Map', 'JSON', |
| 74 | 'Tuple', 'JSON', |
| 75 | 'Object', 'JSON', |
| 76 | 'JSON', 'JSON', |
| 77 | 'String', '{}', |
| 78 | 'FixedString', '{}') AS native_to_mysql_mapping, |
| 79 | )", |
| 80 | remap_string_as_text ? "TEXT" : "BLOB", |
| 81 | remap_fixed_string_as_text ? "TEXT" : "BLOB"); |
| 82 | |
| 83 | rewritten_query += R"( |
| 84 | splitByRegexp('\(|\)', type_) AS split, |
| 85 | multiIf(startsWith(type_, 'LowCardinality(Nullable'), split[3], |
| 86 | startsWith(type_, 'LowCardinality'), split[2], |
| 87 | startsWith(type_, 'Nullable'), split[2], |
| 88 | split[1]) AS inner_type, |
| 89 | if (length(split) > 1, splitByString(', ', split[2]), []) AS decimal_scale_and_precision, |
nothing calls this directly
no test coverage detected