Skip to content

Improve parsing DateTime64 from timestamp represented as string#55146

Merged
hanfei1991 merged 5 commits intoClickHouse:masterfrom
zvonand:zvonand-parsing-dt64-fix
Oct 25, 2023
Merged

Improve parsing DateTime64 from timestamp represented as string#55146
hanfei1991 merged 5 commits intoClickHouse:masterfrom
zvonand:zvonand-parsing-dt64-fix

Conversation

@zvonand
Copy link
Copy Markdown
Contributor

@zvonand zvonand commented Sep 29, 2023

Fix parsing of DateTime64 according to #51753 (like for DateTime) and allow to parse DateTime64 from short strings in unambiguous cases (for negative timestamps and timestamps with non-zero fractional part).
Closes #51753

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Allow to parse negative DateTime64 and DateTime with fractional part from short strings

@zvonand zvonand changed the title Zvonand parsing dt64 fix Improve parsing DateTime64 from string containing a timestamp Sep 29, 2023
@zvonand zvonand changed the title Improve parsing DateTime64 from string containing a timestamp Improve parsing DateTime64 from timestamp represented as string Sep 29, 2023
@zvonand zvonand marked this pull request as ready for review September 30, 2023 07:29
@hanfei1991 hanfei1991 self-assigned this Oct 3, 2023
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-improvement Pull request with some product improvements label Oct 3, 2023
@robot-clickhouse-ci-2
Copy link
Copy Markdown
Contributor

robot-clickhouse-ci-2 commented Oct 3, 2023

This is an automated comment for commit 22cab68 with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker image for serversThe check to build and optionally push the mentioned image to docker hub✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Mergeable CheckChecks if all other necessary checks are successful✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Push to DockerhubThe check for building and pushing the CI related docker images to docker hub✅ success
SQLTestThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool✅ success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style CheckRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success
Check nameDescriptionStatus
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 7, 2023
@zvonand

This comment was marked as resolved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why this place does does not check that s has enough data? And I don't see any check upper on the stack...
And this is actually the reason why 01179_insert_values_semicolon "works", since it assumes that it has 19 bytes (date_time_broken_down_length), while it definitely not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local :) INSERT INTO test_01179 values ('2020-01-01 0'); ('0')
Ok.

local :) INSERT INTO test_01179 values ('2020-01-01 0'); (' ')
Ok.

local :) INSERT INTO test_01179 values ('2020-01-01 0'); ('0 )
Ok.
Exception on client:
Code: 33. DB::Exception: Cannot read data after semicolon: While executing ValuesBlockInputFormat: data for INSERT was parsed from query. (CANNOT_READ_ALL_DATA), Stack trace (when copying this message, always include the lines below):

0. /src/ch/clickhouse/contrib/llvm-project/libcxx/include/exception:134: Poco::Exception::Exception(String const&, int) @ 0x000000001521f5d2 in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
1. /src/ch/clickhouse/src/Common/Exception.cpp:103: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x000000000b8309f7 in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
2. /src/ch/clickhouse/contrib/llvm-project/libcxx/include/string:1499: DB::Exception::Exception<char const (&) [33]>(int, char const (&) [33]) @ 0x0000000006d55cb8 in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
3. /src/ch/clickhouse/src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp:0: DB::ValuesBlockInputFormat::readSuffix() @ 0x00000000124d214d in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
4. /src/ch/clickhouse/src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp:0: DB::ValuesBlockInputFormat::generate() @ 0x00000000124d14ff in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
5. /src/ch/clickhouse/src/Processors/Chunk.h:90: DB::ISource::tryGenerate() @ 0x00000000122e03d8 in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
6. /src/ch/clickhouse/contrib/llvm-project/libcxx/include/optional:344: DB::ISource::work() @ 0x00000000122e0089 in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
7. /src/ch/clickhouse/src/Processors/Executors/ExecutionThreadContext.cpp:0: DB::ExecutionThreadContext::executeTask() @ 0x00000000122f5d8d in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
8. /src/ch/clickhouse/src/Processors/Executors/PipelineExecutor.cpp:273: DB::PipelineExecutor::executeStepImpl(unsigned long, std::atomic<bool>*) @ 0x00000000122eda90 in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
9. /src/ch/clickhouse/src/Processors/Executors/PipelineExecutor.cpp:239: DB::PipelineExecutor::executeImpl(unsigned long, bool) @ 0x00000000122ed11c in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
10. /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:274: DB::PipelineExecutor::execute(unsigned long, bool) @ 0x00000000122ecf02 in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
11. /src/ch/clickhouse/src/Processors/Executors/PullingAsyncPipelineExecutor.cpp:0: void std::__function::__policy_invoker<void ()>::__call_impl<std::__function::__default_alloc_func<ThreadFromGlobalPoolImpl<true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::'lambda'(), void ()>>(std::__function::__policy_storage const*) @ 0x00000000122f8c78 in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
12. /src/ch/clickhouse/base/base/../base/wide_integer_impl.h:809: ThreadPoolImpl<std::thread>::worker(std::__list_iterator<std::thread, void*>) @ 0x000000000b901f42 in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
13. /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:302: void* std::__thread_proxy[abi:v15000]<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void ThreadPoolImpl<std::thread>::scheduleImpl<void>(std::function<void ()>, Priority, std::optional<unsigned long>, bool)::'lambda0'()>>(void*) @ 0x000000000b905dae in /src/ch/clickhouse/.cmake-llvm16/programs/clickhouse
14. ? @ 0x00007ffff7e3a9eb in ?
15. ? @ 0x00007ffff7ebe7cc in ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But to make the last query throw you need to patch PeekableReadBuffer::hasUnreadData() to check that there is no data left

@zvonand zvonand marked this pull request as draft October 12, 2023 12:22
@zvonand zvonand force-pushed the zvonand-parsing-dt64-fix branch from e4641dd to 60b753e Compare October 14, 2023 10:19
@zvonand zvonand marked this pull request as ready for review October 14, 2023 10:27
@zvonand zvonand marked this pull request as draft October 14, 2023 10:28
@zvonand zvonand force-pushed the zvonand-parsing-dt64-fix branch 2 times, most recently from 96f2697 to 05eea5f Compare October 20, 2023 20:26
Allow to parse unambigous short DateTime64
Throw error on invalid DT64 representation (as for DateTime)
@zvonand zvonand force-pushed the zvonand-parsing-dt64-fix branch from 05eea5f to 7d54c1f Compare October 20, 2023 20:28
@zvonand zvonand marked this pull request as ready for review October 20, 2023 20:36
@zvonand zvonand requested a review from azat October 20, 2023 21:50
@zvonand

This comment was marked as outdated.

@zvonand
Copy link
Copy Markdown
Contributor Author

zvonand commented Oct 25, 2023

The only fail is test_delayed_replica_failover -- flaky (#54502)

@hanfei1991 could you please take a look at the PR again? Previous run was spoiled by some mess in protobuf contrib submodule

@hanfei1991 hanfei1991 merged commit b4ab473 into ClickHouse:master Oct 25, 2023
@zvonand zvonand deleted the zvonand-parsing-dt64-fix branch October 25, 2023 10:33
baibaichen added a commit to Kyligence/gluten that referenced this pull request Oct 26, 2023
baibaichen added a commit to Kyligence/gluten that referenced this pull request Oct 26, 2023
baibaichen added a commit to Kyligence/gluten that referenced this pull request Oct 26, 2023
binmahone pushed a commit to apache/gluten that referenced this pull request Oct 26, 2023
* [GLUTEN-1632][CH]Daily Update Clickhouse Version (20231026)

* fix build due to ClickHouse/ClickHouse#50181

* Revert  #1837 since
ClickHouse/ClickHouse#56014.

Fix build due to removing -Wno-shadow-field

* ignore test due to ClickHouse/ClickHouse#55146

* ignore test due to ClickHouse/ClickHouse#55146

---------

Co-authored-by: kyligence-git <[email protected]>
Co-authored-by: Chang Chen <[email protected]>
@UnamedRus
Copy link
Copy Markdown
Contributor

@zvonand
Copy link
Copy Markdown
Contributor Author

zvonand commented May 14, 2024

Looks like regression

It is OK. Previously, CH did not parse this DateTIme64 correctly, and did not throw during parsing, so parsing simply returned zero and CH thought this is a timestamp:
https://fiddle.clickhouse.com/8d84f591-6ae2-40da-ada4-984ad2448f55

In the example above you can see that such comparison is true in 23.9 when it shall not be true. Now it throws an exception, just like for DateTime.

What I dislike about this behavior (23.9 and 23.10) is this part of error message: Cannot parse time component of DateTime 00:0001-0, which looks like it reads something after the end. However, it looks safe :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DateTime64 inconsistent parsing from String

6 participants