|
4 | 4 | #include <Common/FieldVisitorConvertToNumber.h> |
5 | 5 | #include <Common/logger_useful.h> |
6 | 6 | #include <DataTypes/DataTypesNumber.h> |
| 7 | +#include <Functions/FunctionFactory.h> |
7 | 8 | #include <IO/ReadHelpers.h> |
8 | 9 | #include <IO/WriteHelpers.h> |
9 | 10 | #include <Interpreters/convertFieldToType.h> |
@@ -44,19 +45,14 @@ std::optional<Float64> StatisticsUtils::tryConvertToFloat64(const Field & value, |
44 | 45 | if (!data_type->isValueRepresentedByNumber()) |
45 | 46 | return {}; |
46 | 47 |
|
47 | | - Field value_converted; |
48 | | - if (isInteger(data_type) && !isBool(data_type)) |
49 | | - /// For case val_int32 < 10.5 or val_int32 < '10.5' we should convert 10.5 to Float64. |
50 | | - value_converted = convertFieldToType(value, DataTypeFloat64()); |
51 | | - else |
52 | | - /// We should convert value to the real column data type and then translate it to Float64. |
53 | | - /// For example for expression col_date > '2024-08-07', if we directly convert '2024-08-07' to Float64, we will get null. |
54 | | - value_converted = convertFieldToType(value, *data_type); |
| 48 | + auto column = data_type->createColumn(); |
| 49 | + column->insert(value); |
| 50 | + ColumnsWithTypeAndName arguments({ColumnWithTypeAndName(std::move(column), data_type, "stats_const")}); |
55 | 51 |
|
56 | | - if (value_converted.isNull()) |
57 | | - return {}; |
58 | | - |
59 | | - return applyVisitor(FieldVisitorConvertToNumber<Float64>(), value_converted); |
| 52 | + auto cast_resolver = FunctionFactory::instance().get("toFloat64", nullptr); |
| 53 | + auto cast_function = cast_resolver->build(arguments); |
| 54 | + ColumnPtr result = cast_function->execute(arguments, std::make_shared<DataTypeFloat64>(), 1, false); |
| 55 | + return result->getFloat64(0); |
60 | 56 | } |
61 | 57 |
|
62 | 58 | IStatistics::IStatistics(const SingleStatisticsDescription & stat_) |
|
0 commit comments