Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deny writing unsupported dates in ClickHouse #10672

Merged
merged 1 commit into from
Jan 19, 2022

Conversation

ebyhr
Copy link
Member

@ebyhr ebyhr commented Jan 19, 2022

Fixes #10055

@cla-bot cla-bot bot added the cla-signed label Jan 19, 2022
{
// Deny unsupported dates eagerly to prevent unexpected results. ClickHouse stores '1970-01-01' when the date is out of supported range.
if (value < MIN_SUPPORTED_DATE_EPOCH || value > MAX_SUPPORTED_DATE_EPOCH) {
throw new TrinoException(INVALID_ARGUMENTS, format("Epoch must be between %s and %s: %s", MIN_SUPPORTED_DATE_EPOCH, MAX_SUPPORTED_DATE_EPOCH, value));
Copy link
Member

@electrum electrum Jan 19, 2022

Choose a reason for hiding this comment

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

I think it makes more sense to say "Date must be between ...", since the error is referring to the input value, not the range or reference period. Per Wikipedia:

In chronology and periodization, an epoch or reference epoch is an instant in time chosen as the origin of a particular calendar era. The "epoch" serves as a reference point from which time is measured.

try (TestTable table = new TestTable(getQueryRunner()::execute, "test_unsupported_date", "(dt date)")) {
assertQueryFails(
format("INSERT INTO %s VALUES (DATE '1969-12-31')", table.getName()),
"Epoch must be between 0 and 49710: -1");
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to format these as dates, since that is what the user interacts with. How Clickhouse stores dates internally shouldn't matter to the Trino user.

Date must be between 1970-01-01 and 2106-02-07: 1969-12-31

Copy link
Member

@electrum electrum left a comment

Choose a reason for hiding this comment

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

Minor comments about the error message, otherwise looks good

@ebyhr ebyhr force-pushed the ebi/clickhouse-deny-unsupported-dates branch from 97b1025 to 33b82ee Compare January 19, 2022 02:27
@ebyhr ebyhr merged commit 3ff7bfb into trinodb:master Jan 19, 2022
@ebyhr ebyhr deleted the ebi/clickhouse-deny-unsupported-dates branch January 19, 2022 05:17
@github-actions github-actions bot added this to the 369 milestone Jan 19, 2022
tangjiangling added a commit to tangjiangling/trino that referenced this pull request Aug 26, 2022
The TODO was addressed in PR trinodb#10672.
ebyhr pushed a commit that referenced this pull request Aug 26, 2022
The TODO was addressed in PR #10672.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

ClickHouse DATE type stores incorrect result when the value is out of range
2 participants