Skip to content

Commit

Permalink
Merge pull request ClickHouse#69792 from ClickHouse/backport/24.3/69745
Browse files Browse the repository at this point in the history
Backport ClickHouse#69745 to 24.3: use `tryConvertFieldToType` in `getHyperrectangleForRowGroup`
  • Loading branch information
antonio2368 authored Oct 8, 2024
2 parents 6241ea0 + 950de9b commit 7cb5dff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Interpreters/convertFieldToType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,17 @@ Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const ID

}

Field tryConvertFieldToType(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint)
{
/// TODO: implement proper tryConvertFieldToType without try/catch by adding template flag to convertFieldToTypeImpl to not throw an exception.
try
{
return convertFieldToType(from_value, to_type, from_type_hint);
} catch (...)
{
return {};
}
}

Field convertFieldToType(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Interpreters/convertFieldToType.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class IDataType;
*/
Field convertFieldToType(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint = nullptr);

/// Same as convertFieldToType but returns empty Field in case of an exception.
Field tryConvertFieldToType(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint = nullptr);

/// Does the same, but throws ARGUMENT_OUT_OF_BOUND if value does not fall into the range.
Field convertFieldToTypeOrThrow(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint = nullptr);

Expand Down
4 changes: 2 additions & 2 deletions src/Processors/Formats/Impl/ParquetBlockInputFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ static std::vector<Range> getHyperrectangleForRowGroup(const parquet::FileMetaDa
/// Allow conversion in some simple cases, otherwise ignore the min/max values.
auto min_type = min.getType();
auto max_type = max.getType();
min = convertFieldToType(min, *type);
max = convertFieldToType(max, *type);
min = tryConvertFieldToType(min, *type);
max = tryConvertFieldToType(max, *type);
auto ok_cast = [&](Field::Types::Which from, Field::Types::Which to) -> bool
{
if (from == to)
Expand Down

0 comments on commit 7cb5dff

Please sign in to comment.