Check if two schemas match.
168804 {
168805 D_ASSERT(sniffer_result.names.size() == sniffer_result.return_types.size());
168806 bool match = true;
168807 unordered_map<string, TypeIdxPair> current_schema;
168808
168809 for (
idx_t i = 0; i < sniffer_result.names.size(); i++) {
168810
168811 current_schema[sniffer_result.names[i]] = {sniffer_result.return_types[i], i};
168812 }
168813 if (is_minimal_sniffer) {
168814 auto min_sniffer = static_cast<AdaptiveSnifferResult &>(sniffer_result);
168815 if (!min_sniffer.more_than_one_row) {
168816 bool min_sniff_match = true;
168817
168818 for (auto &column : columns) {
168819 if (current_schema.find(column.name) == current_schema.end()) {
168820 min_sniff_match = false;
168821 break;
168822 }
168823 }
168824 if (min_sniff_match) {
168825 return true;
168826 }
168827
168828 min_sniff_match = true;
168829 if (sniffer_result.return_types.size() == columns.size()) {
168830 idx_t return_type_idx = 0;
168831 for (auto &column : columns) {
168832 if (column.type != sniffer_result.return_types[return_type_idx++]) {
168833 min_sniff_match = false;
168834 break;
168835 }
168836 }
168837 } else {
168838 min_sniff_match = false;
168839 }
168840 if (min_sniff_match) {
168841
168842 idx_t sniff_name_idx = 0;
168843 for (auto &column : columns) {
168844 sniffer_result.names[sniff_name_idx++] = column.name;
168845 }
168846 return true;
168847 }
168848 }
168849
168850 }
168851
168852
168853
168854
168855 std::ostringstream error;
168856 error << "Schema mismatch between globbed files."
168857 << "\n";
168858 error << "Main file schema: " << file_path << "\n";
168859 error << "Current file: " << cur_file_path << "\n";
168860
168861 for (auto &column : columns) {
168862 if (current_schema.find(column.name) == current_schema.end()) {
168863 error << "Column with name: \"" << column.name << "\" is missing"
168864 << "\n";
168865 match = false;
168866 } else {
168867 if (!
CanWeCastIt(current_schema[column.name].type.id(), column.type.id())) {
168868 error << "Column with name: \"" << column.name
168869 << "\" is expected to have type: " << column.type.ToString();
168870 error << " But has type: " << current_schema[column.name].type.ToString() << "\n";
168871 match = false;
168872 }
168873 }
168874 }
168875
168876
168877 error << "Potential Fixes "
168878 << "\n";
168879 error << "* Consider setting union_by_name=true."
168880 << "\n";
168881 error << "* Consider setting files_to_sniff to a higher value (e.g., files_to_sniff = -1)"
168882 << "\n";
168883 if (!match) {
168884 error_message = error.str();
168885 }
168886 return match;
168887}