Add the optimize_type_ids parameter to control whether optimization is enabled.

This commit is contained in:
chen768959 2023-08-05 17:35:25 +08:00
parent 57d69a10e3
commit 41e8345169
3 changed files with 6 additions and 5 deletions

View File

@ -155,7 +155,7 @@ DataTypePtr FieldToDataType<on_error>::operator() (const Array & x) const
for (const Field & elem : x)
element_types.emplace_back(applyVisitor(*this, elem));
return std::make_shared<DataTypeArray>(getLeastSupertype<on_error>(element_types));
return std::make_shared<DataTypeArray>(getLeastSupertype<on_error>(element_types, true));
}
template <LeastSupertypeOnError on_error>

View File

@ -201,7 +201,7 @@ DataTypePtr getNumericType(const TypeIndexSet & types)
}
template <LeastSupertypeOnError on_error>
DataTypePtr getLeastSupertype(const DataTypes & types)
DataTypePtr getLeastSupertype(const DataTypes & types, bool optimize_type_ids)
{
/// Trivial cases
@ -592,7 +592,8 @@ DataTypePtr getLeastSupertype(const DataTypes & types)
/// For numeric types, the most complicated part.
{
optimizeTypeIds(types, type_ids);
if (optimize_type_ids)
optimizeTypeIds(types, type_ids);
auto numeric_type = getNumericType<on_error>(type_ids);
if (numeric_type)
return numeric_type;
@ -798,7 +799,7 @@ DataTypePtr tryGetLeastSupertype(const TypeIndexSet & types)
return getLeastSupertype<LeastSupertypeOnError::Null>(types);
}
template DataTypePtr getLeastSupertype<LeastSupertypeOnError::Throw>(const DataTypes & types);
template DataTypePtr getLeastSupertype<LeastSupertypeOnError::Throw>(const DataTypes & types, bool optimize_type_ids);
template DataTypePtr getLeastSupertype<LeastSupertypeOnError::Throw>(const TypeIndexSet & types);
}

View File

@ -18,7 +18,7 @@ enum class LeastSupertypeOnError
* Examples: there is no least common supertype for Array(UInt8), Int8.
*/
template <LeastSupertypeOnError on_error = LeastSupertypeOnError::Throw>
DataTypePtr getLeastSupertype(const DataTypes & types);
DataTypePtr getLeastSupertype(const DataTypes & types, bool optimize_type_ids = false);
/// Same as above but return String type instead of throwing exception.
/// All types can be casted to String, because they can be serialized to String.