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

Method getTableStructureAndFormatFromFileImpl

src/Storages/StorageFile.cpp:1072–1118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1070}
1071
1072std::pair<ColumnsDescription, String> StorageFile::getTableStructureAndFormatFromFileImpl(
1073 std::optional<String> format,
1074 const std::vector<String> & paths,
1075 const String & compression_method,
1076 const std::optional<FormatSettings> & format_settings,
1077 const ContextPtr & context,
1078 const std::optional<ArchiveInfo> & archive_info)
1079{
1080 if (format == "Distributed")
1081 {
1082 if (paths.empty())
1083 throw Exception(ErrorCodes::INCORRECT_FILE_NAME, "Cannot get table structure from file, because no files match specified name");
1084
1085 return {ColumnsDescription(DistributedAsyncInsertSource(paths[0]).getOutputs().front().getHeader().getNamesAndTypesList()), *format};
1086 }
1087
1088 if (((archive_info && archive_info->paths_to_archives.empty()) || (!archive_info && paths.empty()))
1089 && (!format || !FormatFactory::instance().checkIfFormatHasExternalSchemaReader(*format)))
1090 {
1091 if (format)
1092 throw Exception(
1093 ErrorCodes::CANNOT_EXTRACT_TABLE_STRUCTURE,
1094 "The table structure cannot be extracted from a {} format file, because there are no files with provided path. "
1095 "You can specify table structure manually", *format);
1096
1097 throw Exception(
1098 ErrorCodes::CANNOT_EXTRACT_TABLE_STRUCTURE,
1099 "The data format cannot be detected by the contents of the files, because there are no files with provided path. "
1100 "You can specify the format manually");
1101
1102 }
1103
1104 if (archive_info)
1105 {
1106 ReadBufferFromArchiveIterator read_buffer_iterator(*archive_info, format, format_settings, context);
1107 if (format)
1108 return {readSchemaFromFormat(*format, format_settings, read_buffer_iterator, context), *format};
1109
1110 return detectFormatAndReadSchema(format_settings, read_buffer_iterator, context);
1111 }
1112
1113 ReadBufferFromFileIterator read_buffer_iterator(paths, format, compression_method, format_settings, context);
1114 if (format)
1115 return {readSchemaFromFormat(*format, format_settings, read_buffer_iterator, context), *format};
1116
1117 return detectFormatAndReadSchema(format_settings, read_buffer_iterator, context);
1118}
1119
1120ColumnsDescription StorageFile::getTableStructureFromFile(
1121 const DB::String & format,

Callers

nothing calls this directly

Calls 10

readSchemaFromFormatFunction · 0.85
ColumnsDescriptionClass · 0.70
ExceptionClass · 0.50
emptyMethod · 0.45
getNamesAndTypesListMethod · 0.45
getHeaderMethod · 0.45
frontMethod · 0.45

Tested by

no test coverage detected