| 892 | |
| 893 | template <typename LeftNamesAndTypes, typename RightNamesAndTypes> |
| 894 | void TableJoin::inferJoinKeyCommonType(const LeftNamesAndTypes & left, const RightNamesAndTypes & right, bool allow_right, bool require_strict_keys_match) |
| 895 | { |
| 896 | if (!left_type_map.empty() || !right_type_map.empty()) |
| 897 | return; |
| 898 | |
| 899 | NameToTypeMap left_types; |
| 900 | for (const auto & col : left) |
| 901 | left_types[col.name] = col.type; |
| 902 | |
| 903 | NameToTypeMap right_types; |
| 904 | for (const auto & col : right) |
| 905 | right_types[renamedRightColumnName(col.name)] = col.type; |
| 906 | |
| 907 | if (strictness() == JoinStrictness::Asof) |
| 908 | { |
| 909 | if (clauses.size() != 1) |
| 910 | throw DB::Exception(ErrorCodes::NOT_IMPLEMENTED, "ASOF join over multiple keys is not supported"); |
| 911 | } |
| 912 | |
| 913 | forAllKeys(clauses, [&](const auto & left_key_name, const auto & right_key_name) |
| 914 | { |
| 915 | auto ltypeit = left_types.find(left_key_name); |
| 916 | auto rtypeit = right_types.find(right_key_name); |
| 917 | if (ltypeit == left_types.end() || rtypeit == right_types.end()) |
| 918 | { |
| 919 | /// Name mismatch, give up |
| 920 | left_type_map.clear(); |
| 921 | right_type_map.clear(); |
| 922 | return false; |
| 923 | } |
| 924 | const auto & ltype = ltypeit->second; |
| 925 | const auto & rtype = rtypeit->second; |
| 926 | |
| 927 | if (!allow_dynamic_type_in_join_keys) |
| 928 | { |
| 929 | bool is_left_key_dynamic = hasDynamicType(ltype); |
| 930 | bool is_right_key_dynamic = hasDynamicType(rtype); |
| 931 | |
| 932 | if (is_left_key_dynamic || is_right_key_dynamic) |
| 933 | { |
| 934 | throw DB::Exception( |
| 935 | ErrorCodes::ILLEGAL_COLUMN, |
| 936 | "JOIN on keys with Dynamic type is not supported: key {} has type {}. In order to use this key in JOIN you should cast it to any other type", |
| 937 | is_left_key_dynamic ? left_key_name : right_key_name, |
| 938 | is_left_key_dynamic ? ltype->getName() : rtype->getName()); |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | bool type_equals = require_strict_keys_match ? ltype->equals(*rtype) : JoinCommon::typesEqualUpToNullability(ltype, rtype); |
| 943 | if (type_equals) |
| 944 | return true; |
| 945 | |
| 946 | DataTypePtr common_type; |
| 947 | try |
| 948 | { |
| 949 | /// TODO(vdimir): use getMostSubtype if possible |
| 950 | common_type = DB::getLeastSupertype(DataTypes{ltype, rtype}); |
| 951 | } |
nothing calls this directly
no test coverage detected