| 921 | |
| 922 | |
| 923 | std::pair<std::string, std::string> LocalServer::getInitialCreateTableQuery() |
| 924 | { |
| 925 | /// The input data can be specified explicitly with any of the `file`, `structure`, `input-format` command line arguments, |
| 926 | /// or it can be implicitly specified in stdin - then the structure and format is autodetected. |
| 927 | /// But if queries were not specified in the command line, they might me in stdin, and this means that stdin is not input data. |
| 928 | |
| 929 | if (!getClientConfiguration().has("table-structure") |
| 930 | && !getClientConfiguration().has("table-file") |
| 931 | && !getClientConfiguration().has("table-data-format") |
| 932 | && (queries.empty() || !isFileDescriptorSuitableForInput(stdin_fd))) /// In we know that there is data in stdin, we can auto-detect the format. |
| 933 | return {}; |
| 934 | |
| 935 | auto table_name = getClientConfiguration().getString("table-name", "table"); |
| 936 | auto table_structure = getClientConfiguration().getString("table-structure", "auto"); |
| 937 | |
| 938 | String table_file; |
| 939 | String compression = "auto"; |
| 940 | if (!getClientConfiguration().has("table-file") || getClientConfiguration().getString("table-file") == "-") |
| 941 | { |
| 942 | /// Use Unix tools stdin naming convention |
| 943 | table_file = "stdin"; |
| 944 | if (default_input_compression_method != CompressionMethod::None) |
| 945 | compression = toContentEncodingName(default_input_compression_method); |
| 946 | } |
| 947 | else |
| 948 | { |
| 949 | /// Use regular file |
| 950 | auto file_name = getClientConfiguration().getString("table-file"); |
| 951 | table_file = quoteString(file_name); |
| 952 | } |
| 953 | |
| 954 | String data_format; |
| 955 | |
| 956 | if (default_input_format == "auto" && getClientConfiguration().has("table-structure")) |
| 957 | data_format = "TabSeparated"; /// Compatibility with older versions when format inference was not available. |
| 958 | else |
| 959 | data_format = backQuoteIfNeed(default_input_format); |
| 960 | |
| 961 | if (table_structure == "auto") |
| 962 | table_structure = ""; |
| 963 | else |
| 964 | table_structure = "(" + table_structure + ")"; |
| 965 | |
| 966 | return |
| 967 | { |
| 968 | table_name, |
| 969 | fmt::format("CREATE TEMPORARY TABLE {} {} ENGINE = File({}, {}, {});", |
| 970 | backQuote(table_name), table_structure, data_format, table_file, compression) |
| 971 | }; |
| 972 | } |
| 973 | |
| 974 | |
| 975 | namespace |
nothing calls this directly
no test coverage detected