Skip to content

Parquet: write Date/DateTime as date/datetime-like types instead of plain numbers - #70950

Merged
alexey-milovidov merged 9 commits into
masterfrom
dating
Dec 25, 2024
Merged

alexey-milovidov merged 9 commits into
masterfrom
dating

Conversation

@al13n321

@al13n321 al13n321 commented Oct 23, 2024 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Backward Incompatible Change

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

Parquet output format converts Date and DateTime columns to date/time types supported by Parquet, instead of writing them as raw numbers. DateTime becomes DateTime64(3) (was: UInt32); setting output_format_parquet_datetime_as_uint32 brings back the old behavior. Date becomes Date32 (was: UInt16).


Closes #59522

  • Write Date as Date32 instead of UInt16. This seems clearly better and minor enough, so not adding a compatibility setting.
  • Write DateTime as DateTime64(3) instead of UInt32. Setting output_format_parquet_datetime_as_uint32 brings back the old behavior.

All other date/time-like clickhouse types were already handled well:

  • Date32 - passed through, parquet has 32-bit signed date type.
  • DateTime64(n) - converted to ms/us/ns (the only units supported by parquet).

Example:

insert into function file('t.parquet') select '2024-10-22'::Date32 as d32, '2024-10-22'::Date as d, '2024-10-22 19:41:12'::DateTime as dt, '2024-10-22 19:41:12'::DateTime64(0) as s, '2024-10-22 19:41:12.123'::DateTime64(3) as ms, '2024-10-22 19:41:12.123456'::DateTime64(6) a
s us, '2024-10-22 19:41:12.123456789'::DateTime64(9) as ns

Before:

:) desc file('t.parquet')

DESCRIBE TABLE file('t.parquet')

Query id: 6f64ce06-b8e0-473a-92f9-ee458ac0f76c

   ┌─name─┬─type───────────────────────────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┐
1. │ d32  │ Nullable(Date32)               │              │                    │         │                  │                │
2. │ d    │ Nullable(UInt16)               │              │                    │         │                  │                │
3. │ dt   │ Nullable(UInt32)               │              │                    │         │                  │                │
4. │ s    │ Nullable(DateTime64(3, 'UTC')) │              │                    │         │                  │                │
5. │ ms   │ Nullable(DateTime64(3, 'UTC')) │              │                    │         │                  │                │
6. │ us   │ Nullable(DateTime64(6, 'UTC')) │              │                    │         │                  │                │
7. │ ns   │ Nullable(DateTime64(9, 'UTC')) │              │                    │         │                  │                │
   └──────┴────────────────────────────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┘

7 rows in set. Elapsed: 0.004 sec.

:) select * from file('t.parquet')

SELECT *
FROM file('t.parquet')

Query id: 403fa667-51af-4097-90f4-9d7c23c3d752

   ┌────────d32─┬─────d─┬─────────dt─┬───────────────────────s─┬──────────────────────ms─┬─────────────────────────us─┬────────────────────────────ns─┐
1. │ 2024-10-22 │ 20018 │ 1729626072 │ 2024-10-22 19:41:12.000 │ 2024-10-22 19:41:12.123 │ 2024-10-22 19:41:12.123456 │ 2024-10-22 19:41:12.123456789 │
   └────────────┴───────┴────────────┴─────────────────────────┴─────────────────────────┴────────────────────────────┴───────────────────────────────┘

1 row in set. Elapsed: 0.007 sec.

After:

:) desc file('t.parquet')

DESCRIBE TABLE file('t.parquet')

Query id: 108ebc6f-edc0-4851-88f8-91485879170d

   ┌─name─┬─type───────────────────────────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┐
1. │ d32  │ Nullable(Date32)               │              │                    │         │                  │                │
2. │ d    │ Nullable(Date32)               │              │                    │         │                  │                │
3. │ dt   │ Nullable(DateTime64(3, 'UTC')) │              │                    │         │                  │                │
4. │ s    │ Nullable(DateTime64(3, 'UTC')) │              │                    │         │                  │                │
5. │ ms   │ Nullable(DateTime64(3, 'UTC')) │              │                    │         │                  │                │
6. │ us   │ Nullable(DateTime64(6, 'UTC')) │              │                    │         │                  │                │
7. │ ns   │ Nullable(DateTime64(9, 'UTC')) │              │                    │         │                  │                │
   └──────┴────────────────────────────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┘

7 rows in set. Elapsed: 0.001 sec.

:) select * from file('t.parquet')

SELECT *
FROM file('t.parquet')

Query id: f52dc824-3da3-40a6-a9a9-46d36477deb8

   ┌────────d32─┬──────────d─┬──────────────────────dt─┬───────────────────────s─┬──────────────────────ms─┬─────────────────────────us─┬────────────────────────────ns─┐
1. │ 2024-10-22 │ 2024-10-22 │ 2024-10-22 19:41:12.000 │ 2024-10-22 19:41:12.000 │ 2024-10-22 19:41:12.123 │ 2024-10-22 19:41:12.123456 │ 2024-10-22 19:41:12.123456789 │
   └────────────┴────────────┴─────────────────────────┴─────────────────────────┴─────────────────────────┴────────────────────────────┴───────────────────────────────┘

1 row in set. Elapsed: 0.004 sec.

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backward-incompatible Pull request with backwards incompatible changes label Oct 23, 2024
@robot-clickhouse-ci-2

robot-clickhouse-ci-2 commented Oct 23, 2024 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit 2e8ed37 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
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ 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. Integration 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
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ 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
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

@alexey-milovidov alexey-milovidov self-assigned this Oct 24, 2024
@alexey-milovidov

Copy link
Copy Markdown
Member

Tests have to be updated.

@al13n321

al13n321 commented Dec 4, 2024

Copy link
Copy Markdown
Contributor Author

00900_long_parquet caught a quirk with timezones:

  • if you write a DateTime/DateTime64 to parquet file, it's read back as DateTime64(..., 'UTC') - always in UTC (because there's nowhere in parquet file to store timezone information),
  • if you read it with explicit schema saying the column should be e.g. DateTime (i.e. session timezone), the reader will do an implicit conversion DateTime64(..., 'UTC') -> DateTime, and everything is correct,
  • but if you read it with explicit schema saying the column should be Date, the implicit conversion DateTime64(..., 'UTC') -> Date will use UTC timezone. In contrast, if you skip the parquet file and do the DateTime -> Date conversion directly it'll use the session timezone. So passing the data through a parquet file changes the result in this case.

I can't think of any way to improve this. Leaving the quirk as is, changing the test to use explicit 'UTC' in all DateTime/DateTime64 types. I think we should just generally recommend against reading Parquet files with explicit schema that's substantially different from what's in the file, to avoid weird implicit casts like this.

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

Labels

pr-backward-incompatible Pull request with backwards incompatible changes pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change the defaults of Parquet output

5 participants