MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / combineTypes

Method combineTypes

src/common/types/types.cpp:1893–1940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1891}
1892
1893LogicalType 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
1942LogicalType LogicalTypeUtils::combineTypes(const std::vector<LogicalType>& types) {
1943 if (types.empty()) {

Callers

nothing calls this directly

Calls 11

isSemanticallyNestedFunction · 0.85
getChildTypeFunction · 0.85
getKeyTypeFunction · 0.85
getLogicalTypeIDMethod · 0.80
emplace_backMethod · 0.80
getNameMethod · 0.45
getTypeMethod · 0.45
push_backMethod · 0.45
copyMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected