Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rschu1ze committed Mar 1, 2024
1 parent 3e5bf79 commit 52b1fc6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Common/DateLUTImpl.h
Expand Up @@ -596,8 +596,9 @@ class DateLUTImpl
template <typename DateOrTime>
unsigned toMillisecond(const DateOrTime & datetime, Int64 scale_multiplier) const
{
const auto microsecond_multiplier = 1000000;
const auto millisecond_multiplier = 1000;
constexpr Int64 millisecond_multiplier = 1'000;
constexpr Int64 microsecond_multiplier = 1'000 * millisecond_multiplier;
constexpr Int64 divider = microsecond_multiplier / millisecond_multiplier;

auto components = DB::DecimalUtils::splitWithScaleMultiplier(datetime, scale_multiplier);

Expand All @@ -612,7 +613,6 @@ class DateLUTImpl
else if (scale_multiplier < microsecond_multiplier)
fractional = fractional * (microsecond_multiplier / scale_multiplier);

constexpr Int64 divider = microsecond_multiplier / millisecond_multiplier;
UInt16 millisecond = static_cast<UInt16>(fractional / divider);
return millisecond;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Functions/DateTimeTransforms.h
Expand Up @@ -1530,7 +1530,7 @@ struct ToMillisecondImpl

static UInt16 execute(UInt32, const DateLUTImpl &)
{
return 0; /// Only DateTime64 type will give a value for milliseconds
return 0;
}
static UInt16 execute(Int32, const DateLUTImpl &)
{
Expand Down
10 changes: 5 additions & 5 deletions tests/queries/0_stateless/02998_to_milliseconds.sql
Expand Up @@ -5,11 +5,11 @@ SELECT toMillisecond(toDate('2024-02-28')); -- { serverError ILLEGAL_TYPE_OF_ARG
SELECT toMillisecond(toDate32('2024-02-28')); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }

-- Tests with constant and non-constant arguments
SELECT toDateTime('2023-04-21 10:20:30') AS dt, toMillisecond(dt), toMillisecond(materialize(dt)); -- wrong, needs to return 0
SELECT toDateTime64('2023-04-21 10:20:30', 0) AS dt64, toMillisecond(dt64), toMillisecond(materialize(dt64)); -- wrong, needs to return 0
SELECT toDateTime64('2023-04-21 10:20:30.123', 3) AS dt64, toMillisecond(dt64), toMillisecond(materialize(dt64)); -- wrong, needs to return 123
SELECT toDateTime64('2023-04-21 10:20:30.123456', 6) AS dt64, toMillisecond(dt64), toMillisecond(materialize(dt64)); -- wrong, needs to return 123
SELECT toDateTime64('2023-04-21 10:20:30.123456789', 9) AS dt64, toMillisecond(dt64), toMillisecond(materialize(dt64)); -- wrong, needs to return 123
SELECT toDateTime('2023-04-21 10:20:30') AS dt, toMillisecond(dt), toMillisecond(materialize(dt));
SELECT toDateTime64('2023-04-21 10:20:30', 0) AS dt64, toMillisecond(dt64), toMillisecond(materialize(dt64));
SELECT toDateTime64('2023-04-21 10:20:30.123', 3) AS dt64, toMillisecond(dt64), toMillisecond(materialize(dt64));
SELECT toDateTime64('2023-04-21 10:20:30.123456', 6) AS dt64, toMillisecond(dt64), toMillisecond(materialize(dt64));
SELECT toDateTime64('2023-04-21 10:20:30.123456789', 9) AS dt64, toMillisecond(dt64), toMillisecond(materialize(dt64));

-- Special cases
SELECT MILLISECOND(toDateTime64('2023-04-21 10:20:30.123456', 2)); -- Alias
Expand Down

0 comments on commit 52b1fc6

Please sign in to comment.