Skip to content

Conversation

krvikash
Copy link
Contributor

@krvikash krvikash commented Sep 24, 2025

Description

Validate out of range DateTime value in clickhouse connector

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(X) Release notes are required, with the following suggested text:

## ClickHouse
* Fail queries attempting to write unsupported DateTime values to ClickHouse tables. ({issue}`26703`)

@krvikash krvikash force-pushed the krvikash/clickhouse-datetime-validation branch from c75b5a9 to 4e46e02 Compare September 24, 2025 18:13
@krvikash
Copy link
Contributor Author

Thanks @chenjian2664, Addressed your comments.

return (resultSet, columnIndex) -> {
ZonedDateTime zonedDateTime = resultSet.getObject(columnIndex, ZonedDateTime.class);
return packDateTimeWithZone(zonedDateTime.toInstant().toEpochMilli(), zonedDateTime.getZone().getId());
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should validate the reading as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When an out-of-range value is inserted into a ClickHouse table, ClickHouse stores it incorrectly by mapping it to a value within the supported range.

Example:
1912-01-01 00:00:00 → stored as 1970-01-01 00:00:00
3102-01-01 00:00:00 → stored as 2027-10-17 11:03:28

In Trino, the value that gets read appears to be within the supported range, making it impossible to tell whether 1970-01-01 00:00:00 was originally 1912-01-01 00:00:00 or actually 1970-01-01 00:00:00.

Copy link
Contributor

Choose a reason for hiding this comment

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

3102-01-01 00:00:00 → stored as 2027-10-17 11:03:28

Just curious: If the given date above MAX it's stored not as MAX (2106-02-07 06:28:15) but as 2027-10-17 11:03:28 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have checked with some different values as well and it is inserting different values for those cases.

@krvikash krvikash force-pushed the krvikash/clickhouse-datetime-validation branch from 4e46e02 to c04a715 Compare September 25, 2025 05:59
@krvikash
Copy link
Contributor Author

Thanks @anusudarsan @chenjian2664, AC.

@krvikash krvikash force-pushed the krvikash/clickhouse-datetime-validation branch from c04a715 to 3c5d35e Compare September 25, 2025 06:01
@krvikash krvikash force-pushed the krvikash/clickhouse-datetime-validation branch from 3c5d35e to efc1e3a Compare September 25, 2025 07:31
@krvikash
Copy link
Contributor Author

(rebased with master)

import static io.trino.plugin.clickhouse.TestingClickHouseServer.ALTINITY_DEFAULT_IMAGE;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class TestAltinityClickHouseTypeMapping
Copy link
Contributor

Choose a reason for hiding this comment

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

Test classes should be defined as package-private and final.
Test methods should be defined as package-private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since testUnsupportedPoint is declared public in the base class, it cannot be made package-private in this subclass.

Need refactoring of Base class. I think that can be a follow up.

@krvikash krvikash force-pushed the krvikash/clickhouse-datetime-validation branch from efc1e3a to c41a9f1 Compare September 25, 2025 09:29
return (resultSet, columnIndex) -> {
ZonedDateTime zonedDateTime = resultSet.getObject(columnIndex, ZonedDateTime.class);
return packDateTimeWithZone(zonedDateTime.toInstant().toEpochMilli(), zonedDateTime.getZone().getId());
};
Copy link
Contributor

Choose a reason for hiding this comment

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

3102-01-01 00:00:00 → stored as 2027-10-17 11:03:28

Just curious: If the given date above MAX it's stored not as MAX (2106-02-07 06:28:15) but as 2027-10-17 11:03:28 ?

@raunaqmorarka raunaqmorarka merged commit f44a04e into trinodb:master Sep 26, 2025
19 checks passed
@github-actions github-actions bot added this to the 478 milestone Sep 26, 2025
@krvikash krvikash deleted the krvikash/clickhouse-datetime-validation branch September 26, 2025 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed clickhouse ClickHouse connector
Development

Successfully merging this pull request may close these issues.

7 participants