From 5a20c921f742caa27ac59ffae49024ef0433920e Mon Sep 17 00:00:00 2001 From: denis Date: Mon, 3 Apr 2023 15:52:12 +0600 Subject: [PATCH 1/2] https://github.com/ClickHouse/ClickHouse/issues/37066 https://github.com/ClickHouse/ClickHouse/issues/30113 arrayJoin in case when parameter is array --- src/Octonica.ClickHouseClient/ClickHouseCommand.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Octonica.ClickHouseClient/ClickHouseCommand.cs b/src/Octonica.ClickHouseClient/ClickHouseCommand.cs index 4bef407..2f78db3 100644 --- a/src/Octonica.ClickHouseClient/ClickHouseCommand.cs +++ b/src/Octonica.ClickHouseClient/ClickHouseCommand.cs @@ -903,7 +903,11 @@ private string PrepareCommandText(IClickHouseTypeInfoProvider typeInfoProvider, if (typeSeparatorIdx >= 0) queryStringBuilder.Append("(CAST("); - queryStringBuilder.Append("(SELECT ").Append(parametersTable).Append('.').Append(parameter.Id).Append(" FROM ").Append(parametersTable).Append(')'); + queryStringBuilder.Append("(SELECT ") + .Append(parameter.IsArray ? "arrayJoin(" : "") + .Append(parametersTable).Append('.') + .Append(parameter.Id) + .Append(parameter.IsArray ? ")" : "").Append(" FROM ").Append(parametersTable).Append(')'); if (typeSeparatorIdx >= 0) queryStringBuilder.Append(" AS ").Append(query, offset + typeSeparatorIdx + 1, length - typeSeparatorIdx - 2).Append("))"); From 696daf9cf370596a1116f0d29fe99d0042dd869f Mon Sep 17 00:00:00 2001 From: denis Date: Tue, 6 Jun 2023 14:46:01 +0600 Subject: [PATCH 2/2] DateTime64 in ClickHouse Supported range of values: [1900-01-01 00:00:00, 2299-12-31 23:59:59.99999999] But there is limit not less than 1970 --- .../Types/DateTime64TypeInfo.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Octonica.ClickHouseClient/Types/DateTime64TypeInfo.cs b/src/Octonica.ClickHouseClient/Types/DateTime64TypeInfo.cs index 3c9c17c..6832fce 100644 --- a/src/Octonica.ClickHouseClient/Types/DateTime64TypeInfo.cs +++ b/src/Octonica.ClickHouseClient/Types/DateTime64TypeInfo.cs @@ -350,7 +350,7 @@ protected override ulong Convert(DateTime value) } } - private sealed class DateTimeOffsetWriter : StructureWriterBase + private sealed class DateTimeOffsetWriter : StructureWriterBase { private readonly int _ticksScale; private readonly long _ticksMaxValue; @@ -364,9 +364,9 @@ public DateTimeOffsetWriter(string columnName, string columnType, int precision, _timeZone = timeZone; } - protected override ulong Convert(DateTimeOffset value) + protected override long Convert(DateTimeOffset value) { - ulong ticks; + long ticks; if (value == default) { ticks = 0; @@ -376,13 +376,11 @@ protected override ulong Convert(DateTimeOffset value) var offset = _timeZone.GetUtcOffset(value); var valueWithOffset = value.ToOffset(offset); var dateTimeTicks = (valueWithOffset - DateTimeOffset.UnixEpoch).Ticks; - if (dateTimeTicks < 0 || dateTimeTicks > _ticksMaxValue) - throw new OverflowException($"The value must be in range [{DateTimeOffset.UnixEpoch:O}, {DateTimeOffset.UnixEpoch.AddTicks(_ticksMaxValue):O}]."); if (_ticksScale < 0) - ticks = checked((ulong) dateTimeTicks * (uint) -_ticksScale); + ticks = checked(dateTimeTicks * (uint) -_ticksScale); else - ticks = (ulong) dateTimeTicks / (uint) _ticksScale; + ticks = dateTimeTicks / (uint) _ticksScale; } return ticks;