Merge pull request #72659 from ClickHouse/imp-safeget

Safer Field::safeGet?
This commit is contained in:
Yakov Olkhovskiy 2024-12-03 07:28:55 +00:00 committed by GitHub
commit 46f5f79ab5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 5 deletions

View File

@ -479,12 +479,20 @@ public:
return true;
}
template <typename T> auto & safeGet() const
template <typename T> const auto & safeGet() const &
{
return const_cast<Field *>(this)->safeGet<T>();
}
template <typename T> auto safeGet() const &&
{
return std::move(const_cast<Field *>(this)->safeGet<T>());
}
template <typename T> auto & safeGet();
template <typename T> auto & safeGet() &;
template <typename T> auto safeGet() &&
{
return std::move(safeGet<T>());
}
bool operator< (const Field & rhs) const
{
@ -880,7 +888,7 @@ constexpr bool isInt64OrUInt64orBoolFieldType(Field::Types::Which t)
}
template <typename T>
auto & Field::safeGet()
auto & Field::safeGet() &
{
const Types::Which target = TypeToEnum<NearestFieldType<std::decay_t<T>>>::value;

View File

@ -398,8 +398,8 @@ ASTPtr parseAdditionalFilterConditionForTable(
for (const auto & additional_filter : additional_table_filters)
{
const auto & tuple = additional_filter.safeGet<const Tuple &>();
auto & table = tuple.at(0).safeGet<String>();
auto & filter = tuple.at(1).safeGet<String>();
const auto & table = tuple.at(0).safeGet<String>();
const auto & filter = tuple.at(1).safeGet<String>();
if (table == target.alias ||
(table == target.table && context.getCurrentDatabase() == target.database) ||