```
CREATE TABLE tdm__fuzz_23 (`x` UInt256) ENGINE = MergeTree ORDER BY x SETTINGS write_final_mark = 0;
INSERT INTO tdm__fuzz_23 FORMAT Values ...;
SELECT count(x) FROM tdm__fuzz_23 WHERE toDate(x) < toDate(now(), 'Asia/Istanbul') SETTINGS max_rows_to_read = 1;
```

```
2022.10.07 17:35:34.131369 [ 172 ] {db326f69-7905-41b9-a4cc-4a4ce5b53bc2} <Fatal> : Logical error: 'Invalid Field get from type UInt256 to type UInt64'.
2022.10.07 17:36:23.981784 [ 425 ] {} <Fatal> BaseDaemon: ########################################
2022.10.07 17:36:23.982151 [ 425 ] {} <Fatal> BaseDaemon: (version 22.10.1.1, build id: 0488DFF27E207FD5A3386F90BFCBFC48708C3B7A) (from thread 172) (query_id: db326f69-7905-41b9-a4cc-4a4ce5b53bc2) (query: SELECT count(x) FROM tdm__fuzz_23 WHERE toDate(x) < toDate(now(), 'Asia/Istanbul') SETTINGS max_rows_to_read = 1) Received signal Aborted (6)
2022.10.07 17:36:23.982423 [ 425 ] {} <Fatal> BaseDaemon:
2022.10.07 17:36:23.982749 [ 425 ] {} <Fatal> BaseDaemon: Stack trace: 0x7f56a7eef00b 0x7f56a7ece859 0x1f5c6496 0x1f5c6555 0x1f5c6605 0x17454992 0x1745ac86 0x1745455d 0x17463bf1 0x177d61e9 0x1741dc5d 0x27f64082 0x27f650ba 0x27f80004 0x27f63a77 0x27f638b9 0x27f65ac8 0x280eef1f 0x280de049 0x280ed1db 0x280eb525 0x28c58ef5 0x28c578e9 0x28c59b0d 0x28c59cbb 0x28c15935 0x28c3b09f 0x27019151 0x2747220a 0x2746db04 0x2857b638 0x2858b845 0x2cf37d19 0x2cf3855c 0x2d1726d4 0x2d16f59a 0x2d16e37e 0x7f56a80a6609 0x7f56a7fcb133
2022.10.07 17:36:23.983112 [ 425 ] {} <Fatal> BaseDaemon: 4. raise @ 0x7f56a7eef00b in ?
2022.10.07 17:36:23.983318 [ 425 ] {} <Fatal> BaseDaemon: 5. abort @ 0x7f56a7ece859 in ?
2022.10.07 17:36:24.184777 [ 425 ] {} <Fatal> BaseDaemon: 6. /build/build_docker/../src/Common/Exception.cpp:40: DB::abortOnFailedAssertion(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) @ 0x1f5c6496 in /workspace/clickhouse
2022.10.07 17:36:24.310890 [ 425 ] {} <Fatal> BaseDaemon: 7. /build/build_docker/../src/Common/Exception.cpp:63: DB::handle_error_code(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool, std::__1::vector<void*, std::__1::allocator<void*> > const&) @ 0x1f5c6555 in /workspace/clickhouse
2022.10.07 17:36:24.419971 [ 425 ] {} <Fatal> BaseDaemon: 8. /build/build_docker/../src/Common/Exception.cpp:70: DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0x1f5c6605 in /workspace/clickhouse
2022.10.07 17:36:25.625907 [ 425 ] {} <Fatal> BaseDaemon: 9. /build/build_docker/../src/Common/Exception.h:37: DB::Exception::Exception<DB::Field::Types::Which&, DB::Field::Types::Which const&>(int, fmt::v8::basic_format_string<char, fmt::v8::type_identity<DB::Field::Types::Which&>::type, fmt::v8::type_identity<DB::Field::Types::Which const&>::type>, DB::Field::Types::Which&, DB::Field::Types::Which const&) @ 0x17454992 in /workspace/clickhouse
2022.10.07 17:36:26.745563 [ 425 ] {} <Fatal> BaseDaemon: 10. /build/build_docker/../src/Core/Field.h:815: DB::NearestFieldTypeImpl<std::__1::decay<unsigned long>::type, void>::Type& DB::Field::get<unsigned long>() @ 0x1745ac86 in /workspace/clickhouse
2022.10.07 17:36:27.947722 [ 425 ] {} <Fatal> BaseDaemon: 11. /build/build_docker/../src/Core/Field.h:422: auto const& DB::Field::get<unsigned long>() const @ 0x1745455d in /workspace/clickhouse
2022.10.07 17:36:29.152074 [ 425 ] {} <Fatal> BaseDaemon: 12. /build/build_docker/../src/Functions/FunctionsConversion.h:2290: DB::ToDateMonotonicity::get(DB::IDataType const&, DB::Field const&, DB::Field const&) @ 0x17463bf1 in /workspace/clickhouse
2022.10.07 17:36:30.850268 [ 425 ] {} <Fatal> BaseDaemon: 13. /build/build_docker/../src/Functions/FunctionsConversion.h:1826: DB::FunctionConvert<DB::DataTypeDate, DB::NameToDate, DB::ToDateMonotonicity>::getMonotonicityForRange(DB::IDataType const&, DB::Field const&, DB::Field const&) const @ 0x177d61e9 in /workspace/clickhouse
2022.10.07 17:36:30.966316 [ 425 ] {} <Fatal> BaseDaemon: 14. /build/build_docker/../src/Functions/IFunctionAdaptors.h:93: DB::FunctionToFunctionBaseAdaptor::getMonotonicityForRange(DB::IDataType const&, DB::Field const&, DB::Field const&) const @ 0x1741dc5d in /workspace/clickhouse
2022.10.07 17:36:32.219012 [ 425 ] {} <Fatal> BaseDaemon: 15. /build/build_docker/../src/Storages/MergeTree/KeyCondition.cpp:2273: DB::KeyCondition::applyMonotonicFunctionsChainToRange(DB::Range, std::__1::vector<std::__1::shared_ptr<DB::IFunctionBase>, std::__1::allocator<std::__1::shared_ptr<DB::IFunctionBase> > > const&, std::__1::shared_ptr<DB::IDataType const>, bool) @ 0x27f64082 in /workspace/clickhouse
2022.10.07 17:36:33.452662 [ 425 ] {} <Fatal> BaseDaemon: 16. /build/build_docker/../src/Storages/MergeTree/KeyCondition.cpp:2402: DB::KeyCondition::checkInHyperrectangle(std::__1::vector<DB::Range, std::__1::allocator<DB::Range> > const&, std::__1::vector<std::__1::shared_ptr<DB::IDataType const>, std::__1::allocator<std::__1::shared_ptr<DB::IDataType const> > > const&) const @ 0x27f650ba in /workspace/clickhouse
2022.10.07 17:36:35.418933 [ 425 ] {} <Fatal> BaseDaemon: 17. /build/build_docker/../src/Storages/MergeTree/KeyCondition.cpp:2250: DB::KeyCondition::checkInRange(unsigned long, DB::FieldRef const*, DB::FieldRef const*, std::__1::vector<std::__1::shared_ptr<DB::IDataType const>, std::__1::allocator<std::__1::shared_ptr<DB::IDataType const> > > const&, BoolMask) const::$_25::operator()(std::__1::vector<DB::Range, std::__1::allocator<DB::Range> > const&) const @ 0x27f80004 in /workspace/clickhouse
2022.10.07 17:36:37.275192 [ 425 ] {} <Fatal> BaseDaemon: 18. /build/build_docker/../src/Storages/MergeTree/KeyCondition.cpp:2168: BoolMask DB::forAnyHyperrectangle<DB::KeyCondition::checkInRange(unsigned long, DB::FieldRef const*, DB::FieldRef const*, std::__1::vector<std::__1::shared_ptr<DB::IDataType const>, std::__1::allocator<std::__1::shared_ptr<DB::IDataType const> > > const&, BoolMask) const::$_25>(unsigned long, DB::FieldRef const*, DB::FieldRef const*, bool, bool, std::__1::vector<DB::Range, std::__1::allocator<DB::Range> >&, unsigned long, BoolMask, DB::KeyCondition::checkInRange(unsigned long, DB::FieldRef const*, DB::FieldRef const*, std::__1::vector<std::__1::shared_ptr<DB::IDataType const>, std::__1::allocator<std::__1::shared_ptr<DB::IDataType const> > > const&, BoolMask) const::$_25&&) @ 0x27f63a77 in /workspace/clickhouse
2022.10.07 17:36:38.505843 [ 425 ] {} <Fatal> BaseDaemon: 19. /build/build_docker/../src/Storages/MergeTree/KeyCondition.cpp:2247: DB::KeyCondition::checkInRange(unsigned long, DB::FieldRef const*, DB::FieldRef const*, std::__1::vector<std::__1::shared_ptr<DB::IDataType const>, std::__1::allocator<std::__1::shared_ptr<DB::IDataType const> > > const&, BoolMask) const @ 0x27f638b9 in /workspace/clickhouse
2022.10.07 17:36:39.735298 [ 425 ] {} <Fatal> BaseDaemon: 20. /build/build_docker/../src/Storages/MergeTree/KeyCondition.cpp:2498: DB::KeyCondition::mayBeTrueInRange(unsigned long, DB::FieldRef const*, DB::FieldRef const*, std::__1::vector<std::__1::shared_ptr<DB::IDataType const>, std::__1::allocator<std::__1::shared_ptr<DB::IDataType const> > > const&) const @ 0x27f65ac8 in /workspace/clickhouse
2022.10.07 17:36:40.438713 [ 425 ] {} <Fatal> BaseDaemon: 21. /build/build_docker/../src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp:1497: DB::MergeTreeDataSelectExecutor::markRangesFromPKRange(std::__1::shared_ptr<DB::IMergeTreeDataPart const> const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::KeyCondition const&, DB::Settings const&, Poco::Logger*)::$_6::operator()(DB::MarkRange&) const @ 0x280eef1f in /workspace/clickhouse
2022.10.07 17:36:41.099413 [ 425 ] {} <Fatal> BaseDaemon: 22. /build/build_docker/../src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp:1530: DB::MergeTreeDataSelectExecutor::markRangesFromPKRange(std::__1::shared_ptr<DB::IMergeTreeDataPart const> const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::KeyCondition const&, DB::Settings const&, Poco::Logger*) @ 0x280de049 in /workspace/clickhouse
2022.10.07 17:36:41.795236 [ 425 ] {} <Fatal> BaseDaemon: 23. /build/build_docker/../src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp:995: DB::MergeTreeDataSelectExecutor::filterPartsByPrimaryKeyAndSkipIndexes(std::__1::vector<std::__1::shared_ptr<DB::IMergeTreeDataPart const>, std::__1::allocator<std::__1::shared_ptr<DB::IMergeTreeDataPart const> > >&&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const>, DB::SelectQueryInfo const&, std::__1::shared_ptr<DB::Context const> const&, DB::KeyCondition const&, DB::MergeTreeReaderSettings const&, Poco::Logger*, unsigned long, std::__1::vector<DB::ReadFromMergeTree::IndexStat, std::__1::allocator<DB::ReadFromMergeTree::IndexStat> >&, bool)::$_2::operator()(unsigned long) const @ 0x280ed1db in /workspace/clickhouse
2022.10.07 17:36:42.454818 [ 425 ] {} <Fatal> BaseDaemon: 24. /build/build_docker/../src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp:1078: DB::MergeTreeDataSelectExecutor::filterPartsByPrimaryKeyAndSkipIndexes(std::__1::vector<std::__1::shared_ptr<DB::IMergeTreeDataPart const>, std::__1::allocator<std::__1::shared_ptr<DB::IMergeTreeDataPart const> > >&&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const>, DB::SelectQueryInfo const&, std::__1::shared_ptr<DB::Context const> const&, DB::KeyCondition const&, DB::MergeTreeReaderSettings const&, Poco::Logger*, unsigned long, std::__1::vector<DB::ReadFromMergeTree::IndexStat, std::__1::allocator<DB::ReadFromMergeTree::IndexStat> >&, bool) @ 0x280eb525 in /workspace/clickhouse
2022.10.07 17:36:42.990894 [ 425 ] {} <Fatal> BaseDaemon: 25. /build/build_docker/../src/Processors/QueryPlan/ReadFromMergeTree.cpp:971: DB::ReadFromMergeTree::selectRangesToRead(std::__1::vector<std::__1::shared_ptr<DB::IMergeTreeDataPart const>, std::__1::allocator<std::__1::shared_ptr<DB::IMergeTreeDataPart const> > >, std::__1::shared_ptr<DB::PrewhereInfo> const&, DB::ActionDAGNodes const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::SelectQueryInfo const&, std::__1::shared_ptr<DB::Context const>, unsigned int, std::__1::shared_ptr<std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, long> > > >, DB::MergeTreeData const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, bool, Poco::Logger*) @ 0x28c58ef5 in /workspace/clickhouse
2022.10.07 17:36:43.524895 [ 425 ] {} <Fatal> BaseDaemon: 26. /build/build_docker/../src/Processors/QueryPlan/ReadFromMergeTree.cpp:832: DB::ReadFromMergeTree::selectRangesToRead(std::__1::vector<std::__1::shared_ptr<DB::IMergeTreeDataPart const>, std::__1::allocator<std::__1::shared_ptr<DB::IMergeTreeDataPart const> > >) const @ 0x28c578e9 in /workspace/clickhouse
```
: DateTimeTransformImpl<DataTypeFloat64, DataTypeDateTime64, ToDateTime64TransformFloat<DataTypeFloat64, Float64>> {};
/** Conversion of DateTime64 to Date or DateTime: discards fractional part.
 */
template <typename Transform>
struct FromDateTime64Transform
{
    static constexpr auto name = Transform::name;
    const DateTime64::NativeType scale_multiplier = 1;
    FromDateTime64Transform(UInt32 scale) 
        : scale_multiplier(DecimalUtils::scaleMultiplier<DateTime64::NativeType>(scale))
    {}
    auto execute(DateTime64::NativeType dt, const DateLUTImpl & time_zone) const
    {
        const auto c = DecimalUtils::splitWithScaleMultiplier(DateTime64(dt), scale_multiplier);
        return Transform::execute(static_cast<UInt32>(c.whole), time_zone);
    }
};
/** Conversion of DateTime64 to Date or DateTime: discards fractional part.
 */
template <typename Name> struct ConvertImpl<DataTypeDateTime64, DataTypeDate, Name, ConvertDefaultBehaviorTag>
    : DateTimeTransformImpl<DataTypeDateTime64, DataTypeDate, TransformDateTime64<ToDateImpl>> {};
template <typename Name> struct ConvertImpl<DataTypeDateTime64, DataTypeDateTime, Name, ConvertDefaultBehaviorTag>
    : DateTimeTransformImpl<DataTypeDateTime64, DataTypeDateTime, TransformDateTime64<ToDateTimeImpl>> {};
struct ToDateTime64Transform
{
    static constexpr auto name = "toDateTime64";
    const DateTime64::NativeType scale_multiplier = 1;
    ToDateTime64Transform(UInt32 scale = 0) 
        : scale_multiplier(DecimalUtils::scaleMultiplier<DateTime64::NativeType>(scale))
    {}