Skip to content
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

https://github.com/ClickHouse/ClickHouse/issues/37066 #76

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Octonica.ClickHouseClient/ClickHouseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("))");
Expand Down
12 changes: 5 additions & 7 deletions src/Octonica.ClickHouseClient/Types/DateTime64TypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ protected override ulong Convert(DateTime value)
}
}

private sealed class DateTimeOffsetWriter : StructureWriterBase<DateTimeOffset, ulong>
private sealed class DateTimeOffsetWriter : StructureWriterBase<DateTimeOffset, long>
{
private readonly int _ticksScale;
private readonly long _ticksMaxValue;
Expand All @@ -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;
Expand All @@ -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;
Expand Down