| 1891 | } |
| 1892 | |
| 1893 | LogicalType LogicalTypeUtils::combineTypes(const LogicalType& lft, |
| 1894 | const LogicalType& rit) { // always succeeds |
| 1895 | if (lft.getLogicalTypeID() == LogicalTypeID::STRING || |
| 1896 | rit.getLogicalTypeID() == LogicalTypeID::STRING) { |
| 1897 | return LogicalType::STRING(); |
| 1898 | } |
| 1899 | if (isSemanticallyNested(lft.getLogicalTypeID()) && |
| 1900 | isSemanticallyNested(rit.getLogicalTypeID())) {} |
| 1901 | if (lft.getLogicalTypeID() == rit.getLogicalTypeID() && |
| 1902 | lft.getLogicalTypeID() == LogicalTypeID::STRUCT) { |
| 1903 | std::vector<StructField> resultingFields; |
| 1904 | for (const auto& i : StructType::getFields(lft)) { |
| 1905 | auto name = i.getName(); |
| 1906 | if (StructType::hasField(rit, name)) { |
| 1907 | resultingFields.emplace_back(name, |
| 1908 | combineTypes(i.getType(), StructType::getFieldType(rit, name))); |
| 1909 | } else { |
| 1910 | resultingFields.push_back(i.copy()); |
| 1911 | } |
| 1912 | } |
| 1913 | for (const auto& i : StructType::getFields(rit)) { |
| 1914 | auto name = i.getName(); |
| 1915 | if (!StructType::hasField(lft, name)) { |
| 1916 | resultingFields.push_back(i.copy()); |
| 1917 | } |
| 1918 | } |
| 1919 | return LogicalType::STRUCT(std::move(resultingFields)); |
| 1920 | } |
| 1921 | if (lft.getLogicalTypeID() == rit.getLogicalTypeID() && |
| 1922 | lft.getLogicalTypeID() == LogicalTypeID::LIST) { |
| 1923 | const auto& lftChild = ListType::getChildType(lft); |
| 1924 | const auto& ritChild = ListType::getChildType(rit); |
| 1925 | return LogicalType::LIST(combineTypes(lftChild, ritChild)); |
| 1926 | } |
| 1927 | if (lft.getLogicalTypeID() == rit.getLogicalTypeID() && |
| 1928 | lft.getLogicalTypeID() == LogicalTypeID::MAP) { |
| 1929 | const auto& lftKey = MapType::getKeyType(lft); |
| 1930 | const auto& lftValue = MapType::getValueType(lft); |
| 1931 | const auto& ritKey = MapType::getKeyType(rit); |
| 1932 | const auto& ritValue = MapType::getValueType(rit); |
| 1933 | return LogicalType::MAP(combineTypes(lftKey, ritKey), combineTypes(lftValue, ritValue)); |
| 1934 | } |
| 1935 | common::LogicalType result; |
| 1936 | if (!tryGetMaxLogicalType(lft, rit, result)) { |
| 1937 | return LogicalType::STRING(); |
| 1938 | } |
| 1939 | return result; |
| 1940 | } |
| 1941 | |
| 1942 | LogicalType LogicalTypeUtils::combineTypes(const std::vector<LogicalType>& types) { |
| 1943 | if (types.empty()) { |
nothing calls this directly
no test coverage detected