-
Notifications
You must be signed in to change notification settings - Fork 55
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
Specify timezone for DateTime / DateTime64 #349
Comments
This is related to the
|
@aadant, I'm trying to solve this. I think that would be better if it didn't solve on a column data type level, but on INSERT INTO table(`date_column`) VALUES (toDateTime64('2023-04-29 06:36:28.46277', 6, 'UTC')) Or always use
So, it would be nice if |
@IlyaTsoi sure if
we need this override. Currently the sink-connector casts all DateTimes to UTC and it is influenced by UTC -> UTC works Ideally we need to override at the column level (overrides are not implemented yet, except at the global level) |
Actually the difficulty is that DateTime In MySQL is like String representing Date and Time, while DateTime* in CH behave like MySQL Timestamp. In addition and unlike MySQL, CH can stick the TZ at the column level. |
Right, but it uses TZ column metadata when calculates inserted data. When you execute CREATE TABLE test_datetime (`id` Int8, `value` DateTime64(6, 'Europe/Moscow')) ENGINE = MergeTree ORDER BY value;
INSERT INTO test_datetime(id, value)
VALUES
(1,1546300800000000) -- will be inserted as UTC
,(2,'2019-01-01 00:00:00'); -- will be recalculated considering TZ metadata column value SELECT
id
,value AS `as stored`
,toTimezone(value, 'Europe/Paris') AS `to 'Europe/Paris' TZ`
,toString(value) AS `affected by column TZ metadata`
FROM test_datetime
ORDER BY id;
This is from docs:
And now there is a problem, when a inserted data in |
@IlyaTsoi I agree with what you say. In the general case, we should be able to migrate from a MySQL server with the same time zone without issue. Suppose the MySQL database stores DateTimes from a different TZ (like UTC in a America/Chicago database), how do you migrate them accurately ? The MySQL database could also contain DateTimes from different TZ in which case you need an "override" per database / table / column basis. What I propose here is an optional variable, by default the sink-connector will assume that the timezone is the target CH server timezone. This is an attempt to override it globally before it is possible to override it more granularly. |
@aadant OK, I did catch the main idea. I just want that all |
@aadant, @subkanthi look,please here. I have implemented the similar behavior. Long story short, I added a string config parameter |
@IlyaTsoi I reviewed the code, looks good to me for DateTime (up to second) but you should also support For MySQL @subkanthi I noticed this problem with current |
@IlyaTsoi : did you try to replicate the |
@aadant, of course, I haven’t tested it enough and not for all cases. I added a small unit test and it shows the expected result. I ran it for different configuration values of ch-server-TZ and connection-TZ. Additionally, I migrated a real 10G dataset from MSSQL to Clickhouse without any errors. Sorry, I didn't catch what do you mean by, for example, replication from UTC to non-UTC? I do nothing on Clickhouse side, only tell it to consider incoming data like one with TZ offset. Except |
@IlyaTsoi : I created #374 and started to review there. It looks promising as it solved my particular case. To test this, we have a data_types schema that @subkanthi can test with different TZ (UTC to UTC, America/Chicago to America/Chicago) |
@IlyaTsoi , there is a Integration test here - https://github.com/Altinity/clickhouse-sink-connector/blob/develop/sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/ClickHouseDebeziumEmbeddedDDLCreateTableIT.java , we can extend this by setting the |
Questions: |
Yes |
The issue was manually verified by the Altinity QA team and marked as Build used for testing: We've verified that modifying the value of the The timezones used for testing were taken from the ClickHouse |
Specify the default timezone for the CH server :
This setting would control the timezone for DateTime* data types :
The text was updated successfully, but these errors were encountered: