Time: on .NET 6 and 8, the HTTP binary insert stores a TimeSpan of more than int.MaxValue seconds as -999:59:59
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
Direzione di ricerca
Inizia da ClickHouse.Driver/Types/TimeType.cs, soprattutto da Write, WriteValue e WriteSeconds; confronta il comportamento di conversione e di limitazione descritto per .NET 6 e 8 con i test esistenti per i valori di TimeSpan. Aggiungi test per un valore oltre l’intervallo di int su entrambi i percorsi di scrittura, incluso il caso di 700000 ore. Il lavoro è completo quando i valori positivi vengono limitati in modo coerente a 999:59:59 nei runtime interessati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
On .NET 6 and .NET 8 (x64), the HTTP binary insert stores a positive TimeSpan of more than int.MaxValue seconds (about 596,523 hours) in a Time column as -999:59:59, and reports success. The docs (docs/http.mdx, type table) say that Time values are clamped to ±999:59:59. On .NET 9 and later the same values are stored as 999:59:59, which is correct.
Affected: InsertBinaryAsync with object[] rows and with POCOs. Not affected: Time64 columns and the TCP client (it rejects the value with ArgumentOutOfRangeException). A long, decimal or BigInteger value for Time is rejected with an exception on all runtimes.
The same defect was reported for clickhouse-java in https://github.com/ClickHouse/clickhouse-java/issues/3543.
Root cause: TimeType converts the TimeSpan with (int)Math.Round(ts.TotalSeconds) (ClickHouse.Driver/Types/TimeType.cs:53 for Write, :39 for WriteValue) before the clamp in WriteSeconds (TimeType.cs:44). A double to int conversion of a value outside the int range gives int.MinValue on .NET 6 and 8 for x86/x64 (the clamp then gives -999:59:59), and saturates to int.MaxValue on .NET 9 and later.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related: open PR #771 (for #767) changes these lines to long seconds, which also removes this defect. It has no test for a value outside the int range.
Steps to reproduce
- Build the code example for
net6.0ornet8.0, and run it on the .NET 6 or .NET 8 runtime. (A self-contained publish,dotnet publish -f net8.0 -r linux-x64 --self-contained, brings that runtime.) - Run the same program on
net10.0, and compare the output.
Expected behaviour
Each row is stored as 999:59:59, on every runtime. The server stores this for the same number of seconds in text:
INSERT INTO time_narrow VALUES (1, 2520000000) -- 999:59:59, toInt32 = 3599999
INSERT INTO time_narrow FORMAT JSONEachRow {"id":2,"t":2520000000} -- 999:59:59, toInt32 = 3599999
Code example
using ClickHouse.Driver;
using var client = new ClickHouseClient("Host=clickhouse;Port=8123;Username=default");
await client.ExecuteNonQueryAsync("CREATE OR REPLACE TABLE time_narrow (id Int32, t Time) ENGINE = Memory");
var values = new[] { TimeSpan.FromHours(10_000), TimeSpan.FromSeconds(2_147_483_648), TimeSpan.FromSeconds(4_294_967_301), TimeSpan.MaxValue };
for (var i = 0; i < values.Length; i++)
await client.InsertBinaryAsync("time_narrow", new[] { "id", "t" }, new[] { new object[] { i + 1, values[i] } }); // no exception
client.RegisterBinaryInsertType<Row>();
await client.InsertBinaryAsync("time_narrow", new[] { new Row { id = 5, t = TimeSpan.FromSeconds(4_294_967_301) } });
Console.WriteLine(System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);
using var r = await client.ExecuteReaderAsync("SELECT id, toString(t) FROM time_narrow ORDER BY id");
while (r.Read()) Console.WriteLine($"{r.GetValue(0)} {r.GetValue(1)}");
public class Row { public int id { get; set; } public TimeSpan t { get; set; } }
Error log
No exception. Output (row 1 is 10,000 hours, inside the int range):
.NET 8.0.34 .NET 6.0.36 .NET 10.0.15
1 999:59:59 1 999:59:59 1 999:59:59
2 -999:59:59 2 -999:59:59 2 999:59:59
3 -999:59:59 3 -999:59:59 3 999:59:59
4 -999:59:59 4 -999:59:59 4 999:59:59
5 -999:59:59 5 -999:59:59 5 999:59:59
A unit test of TimeType.Write and WriteValue with TimeSpan.FromHours(700000) fails on net6.0 and net8.0 (Expected: 3599999, But was: -3599999) and passes on net9.0 and net10.0.
Configuration
Environment
- Client version:
mainat c58178ed - Language version: C# (SDK 11.0)
- .NET version: 6.0.36 and 8.0.34 (affected), 9.0 and 10.0.15 (not affected)
- OS: Linux x64
ClickHouse server
- ClickHouse Server version: 26.11.7.10
CREATE TABLEstatements for tables involved:CREATE TABLE time_narrow (id Int32, t Time) ENGINE = Memory
Classification: impact: Data integrity · area: Data types & formats (Time, RowBinary)
Found by automated analysis (Polyglot AI) while checking clickhouse-java#3543 against the other client repos. Verified against a live server.
- Lingua principale
- C#
- Stelle
- 102
- Fork
- 31
- Merge medio
- 2g 13h
- PR unite (30g)
- 40
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ClickHouse/clickhouse-cs
-
bug documentation queries
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ClickHouse/clickhouse-cs#815 ·
I maintainer di solito rispondono entro 1 giorno
-
bug data-types native-format
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ClickHouse/clickhouse-cs#813 ·
I maintainer di solito rispondono entro 1 giorno
-
bug data-types documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
ClickHouse/clickhouse-cs#811 ·
I maintainer di solito rispondono entro 1 giorno
-
bug data-types
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ClickHouse/clickhouse-cs#806 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug data-types
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ClickHouse/clickhouse-cs#804 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ClickHouse/clickhouse-cs
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
XML grammar: only the closing --> of a comment gets the scope comment.block.xmlForse già presa @alexeyfala l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
danipen/TextMateSharp#145 · 2 commenti ·
-
good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
Klyroo/klyroo-dashboard#12 ·
I maintainer di solito rispondono entro 1 giorno
-
CONTRIBUTING rules Node out in step 0, then tells client-side contributors to run node --test, which is what CI gates onForse già presa @yadavraj2001 l’ha presa oggi. Apertadocumentation good first issue
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
juandresrodca/AdminForge#73 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[辞書] VIVANTAperta要トリアージ 辞書
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno