MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / getInitialCreateTableQuery

Method getInitialCreateTableQuery

programs/local/LocalServer.cpp:923–972  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

921
922
923std::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
975namespace

Callers

nothing calls this directly

Calls 8

toContentEncodingNameFunction · 0.85
backQuoteIfNeedFunction · 0.85
backQuoteFunction · 0.85
quoteStringFunction · 0.50
formatFunction · 0.50
hasMethod · 0.45
emptyMethod · 0.45
getStringMethod · 0.45

Tested by

no test coverage detected