ClickHouse / ClickHouse/clickhouse-cpp

Strange behavior with dateTime

Aperta
#398 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
documentation enhancement
Lingua principale
C
Stelle
382
Fork
209
Merge medio
1g 22h
PR unite (30g)
13

Descrizione

I modified example

```
inline void DateTime64Example(Client& client) {
Block b;

/// Create a table.
client.Execute("CREATE TABLE IF NOT EXISTS test_datetime64 (dt64 DateTime64(6) primary key)");

std::cerr << std::endl;
{
Query query("insert into test_datetime64 values('2024-10-10 11:00:00')");
client.Execute(query);
}
{
Query query("insert into test_datetime64 FORMAT TSV \n2024-10-10 11:01:00");
client.Execute(query);
}
auto d = std::make_shared(6);
std::time_t tt = std::time(nullptr);
std::cerr << "inserted local time: " << std::asctime(std::localtime(&tt));
std::cerr << "inserted utc: " << std::asctime(std::gmtime(&tt));
d->Append(tt * (int64_t)1000000 + 123456);

b.AppendColumn("dt64", d);
client.Insert("test_datetime64", b);

client.Select("SELECT dt64 FROM test_datetime64 format tsv", [](const Block& block)
{
for (size_t c = 0; c < block.GetRowCount(); ++c) {
auto col = block[0]->As();
uint64_t t = col->As()->At(c);

std::time_t ct = t / 1000000;
uint64_t us = t % 1000000;
std::cerr << "selected local time: " << std::asctime(std::localtime(&ct));
std::cerr << "selected utc time: " << std::asctime(std::gmtime(&ct));
std::cerr << "us: " << us << std::endl;
}
}
);

/// Delete table.
// client.Execute("DROP TEMPORARY TABLE test_datetime64");
}
```

The server was run with time zone Asia/Tokyo.
The test program I run twice in two different time zones Europe/Paris Europe/Moscow and has the results of insert:

selected local time: Thu Oct 10 05:00:00 2024
selected utc time: Thu Oct 10 02:00:00 2024
us: 0
selected local time: Thu Oct 10 05:00:00 2024
selected utc time: Thu Oct 10 02:00:00 2024
us: 0
selected local time: Thu Oct 10 05:01:00 2024
selected utc time: Thu Oct 10 02:01:00 2024
us: 0
selected local time: Thu Oct 10 05:01:00 2024
selected utc time: Thu Oct 10 02:01:00 2024
us: 0
selected local time: Thu Oct 10 11:32:57 2024
selected utc time: Thu Oct 10 08:32:57 2024
us: 123456
selected local time: Thu Oct 10 11:33:09 2024
selected utc time: Thu Oct 10 08:33:09 2024
us: 123456
I see that text query (value or TSV format) inserted data in server time zone.
Data that inserted via Client.Insert() has utc time zone. Time zone of text insert and time zone of binary insert is different!
I need unification of time working.

Also will be very good if I can insert data in client local time zone. I did not found way to insert time in client time zone in text formats.

There is output of the client:
SELECT *
FROM test_datetime64

Query id: 560fd02a-cb6c-4303-8947-2c9727cd1793

┌───────────────────────dt64─┐
1. │ 2024-10-10 17:33:09.123456 │
└────────────────────────────┘
┌───────────────────────dt64─┐
2. │ 2024-10-10 11:00:00.000000 │
3. │ 2024-10-10 11:00:00.000000 │
4. │ 2024-10-10 11:01:00.000000 │
5. │ 2024-10-10 11:01:00.000000 │
6. │ 2024-10-10 17:32:57.123456 │
└────────────────────────────┘

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia con il codice DateTime64Example nell’issue e riproduci gli inserimenti con il server in Asia/Tokyo e client in Europe/Paris e Europe/Moscow. Confronta gli inserimenti di testo/TSV con Client.Insert(), quindi traccia la gestione del fuso orario di DateTime64. Il lavoro è completato quando i percorsi di inserimento hanno un comportamento del fuso orario documentato e coerente e l’opzione locale del client richiesta è gestita.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp
Ambito
databases
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.