[feature](datetime-func)support milliseconds_add/sub/diff and microseconds_diff (#24114)

This commit is contained in:
Liqf
2023-09-20 10:38:56 +08:00
committed by GitHub
parent a71d7f2beb
commit e59aa49f28
27 changed files with 982 additions and 15 deletions

View File

@ -148,6 +148,7 @@ extern ResultType date_time_add(const Arg& t, Int64 delta, bool& is_null) {
}
ADD_TIME_FUNCTION_IMPL(AddMicrosecondsImpl, microseconds_add, MICROSECOND);
ADD_TIME_FUNCTION_IMPL(AddMillisecondsImpl, milliseconds_add, MILLISECOND);
ADD_TIME_FUNCTION_IMPL(AddSecondsImpl, seconds_add, SECOND);
ADD_TIME_FUNCTION_IMPL(AddMinutesImpl, minutes_add, MINUTE);
ADD_TIME_FUNCTION_IMPL(AddHoursImpl, hours_add, HOUR);
@ -210,6 +211,11 @@ struct SubtractMicrosecondsImpl : SubtractIntervalImpl<AddMicrosecondsImpl<DateT
static constexpr auto name = "microseconds_sub";
};
template <typename DateType>
struct SubtractMillisecondsImpl : SubtractIntervalImpl<AddMillisecondsImpl<DateType>, DateType> {
static constexpr auto name = "milliseconds_sub";
};
template <typename DateType>
struct SubtractSecondsImpl : SubtractIntervalImpl<AddSecondsImpl<DateType>, DateType> {
static constexpr auto name = "seconds_sub";
@ -334,6 +340,8 @@ TIME_DIFF_FUNCTION_IMPL(DaysDiffImpl, days_diff, DAY);
TIME_DIFF_FUNCTION_IMPL(HoursDiffImpl, hours_diff, HOUR);
TIME_DIFF_FUNCTION_IMPL(MintueSDiffImpl, minutes_diff, MINUTE);
TIME_DIFF_FUNCTION_IMPL(SecondsDiffImpl, seconds_diff, SECOND);
TIME_DIFF_FUNCTION_IMPL(MilliSecondsDiffImpl, milliseconds_diff, MILLISECOND);
TIME_DIFF_FUNCTION_IMPL(MicroSecondsDiffImpl, microseconds_diff, MICROSECOND);
#define TIME_FUNCTION_TWO_ARGS_IMPL(CLASS, NAME, FUNCTION, RETURN_TYPE) \
template <typename DateType> \

View File

@ -47,6 +47,8 @@ using FunctionToWeekTwoArgsV2 =
using FunctionDatetimeV2AddMicroseconds =
FunctionDateOrDateTimeComputation<AddMicrosecondsImpl<DataTypeDateTimeV2>>;
using FunctionDatetimeV2AddMilliseconds =
FunctionDateOrDateTimeComputation<AddMillisecondsImpl<DataTypeDateTimeV2>>;
using FunctionDatetimeV2AddSeconds =
FunctionDateOrDateTimeComputation<AddSecondsImpl<DataTypeDateTimeV2>>;
using FunctionDatetimeV2AddMinutes =
@ -66,6 +68,8 @@ using FunctionDatetimeV2AddYears =
using FunctionDatetimeV2SubMicroseconds =
FunctionDateOrDateTimeComputation<SubtractMicrosecondsImpl<DataTypeDateTimeV2>>;
using FunctionDatetimeV2SubMilliseconds =
FunctionDateOrDateTimeComputation<SubtractMillisecondsImpl<DataTypeDateTimeV2>>;
using FunctionDatetimeV2SubSeconds =
FunctionDateOrDateTimeComputation<SubtractSecondsImpl<DataTypeDateTimeV2>>;
using FunctionDatetimeV2SubMinutes =
@ -101,6 +105,8 @@ ALL_FUNCTION_DATEV2_WITH_TWO_ARGS(FunctionDatetimeV2HoursDiff, HoursDiffImpl)
ALL_FUNCTION_DATEV2_WITH_TWO_ARGS(FunctionDatetimeV2MinutesDiff, MintueSDiffImpl)
ALL_FUNCTION_DATEV2_WITH_TWO_ARGS(FunctionDatetimeV2SecondsDiff, SecondsDiffImpl)
ALL_FUNCTION_DATEV2_WITH_TWO_ARGS(FunctionDatetimeV2DaysDiff, DaysDiffImpl)
ALL_FUNCTION_DATEV2_WITH_TWO_ARGS(FunctionDatetimeV2MilliSecondsDiff, MilliSecondsDiffImpl)
ALL_FUNCTION_DATEV2_WITH_TWO_ARGS(FunctionDatetimeV2MicroSecondsDiff, MicroSecondsDiffImpl)
using FunctionDatetimeV2ToYearWeekTwoArgs =
FunctionDateOrDateTimeComputation<ToYearWeekTwoArgsImpl<DataTypeDateTimeV2>>;
@ -122,6 +128,7 @@ void register_function_date_time_computation_v2(SimpleFunctionFactory& factory)
factory.register_function<FunctionAddQuartersV2>();
factory.register_function<FunctionDatetimeV2AddMicroseconds>();
factory.register_function<FunctionDatetimeV2AddMilliseconds>();
factory.register_function<FunctionDatetimeV2AddSeconds>();
factory.register_function<FunctionDatetimeV2AddMinutes>();
factory.register_function<FunctionDatetimeV2AddHours>();
@ -141,6 +148,7 @@ void register_function_date_time_computation_v2(SimpleFunctionFactory& factory)
factory.register_function<FunctionSubWeeksV2>();
factory.register_function<FunctionDatetimeV2SubMicroseconds>();
factory.register_function<FunctionDatetimeV2SubMilliseconds>();
factory.register_function<FunctionDatetimeV2SubSeconds>();
factory.register_function<FunctionDatetimeV2SubMinutes>();
factory.register_function<FunctionDatetimeV2SubHours>();
@ -168,6 +176,8 @@ void register_function_date_time_computation_v2(SimpleFunctionFactory& factory)
REGISTER_ALL_DATEV2_FUNCTIONS_WITH_TWO_ARGS(FunctionDatetimeV2MinutesDiff)
REGISTER_ALL_DATEV2_FUNCTIONS_WITH_TWO_ARGS(FunctionDatetimeV2SecondsDiff)
REGISTER_ALL_DATEV2_FUNCTIONS_WITH_TWO_ARGS(FunctionDatetimeV2DaysDiff)
REGISTER_ALL_DATEV2_FUNCTIONS_WITH_TWO_ARGS(FunctionDatetimeV2MilliSecondsDiff)
REGISTER_ALL_DATEV2_FUNCTIONS_WITH_TWO_ARGS(FunctionDatetimeV2MicroSecondsDiff)
factory.register_function<FunctionToYearWeekTwoArgsV2>();
factory.register_function<FunctionToWeekTwoArgsV2>();

View File

@ -2817,14 +2817,16 @@ bool DateV2Value<T>::date_add_interval(const TimeInterval& interval, DateV2Value
int sign = interval.is_neg ? -1 : 1;
if constexpr ((unit == MICROSECOND) || (unit == SECOND) || (unit == MINUTE) || (unit == HOUR) ||
(unit == SECOND_MICROSECOND) || (unit == MINUTE_MICROSECOND) ||
(unit == MINUTE_SECOND) || (unit == HOUR_MICROSECOND) || (unit == HOUR_SECOND) ||
(unit == HOUR_MINUTE) || (unit == DAY_MICROSECOND) || (unit == DAY_SECOND) ||
(unit == DAY_MINUTE) || (unit == DAY_HOUR) || (unit == DAY) || (unit == WEEK)) {
if constexpr ((unit == MICROSECOND) || (unit == MILLISECOND) || (unit == SECOND) ||
(unit == MINUTE) || (unit == HOUR) || (unit == SECOND_MICROSECOND) ||
(unit == MINUTE_MICROSECOND) || (unit == MINUTE_SECOND) ||
(unit == HOUR_MICROSECOND) || (unit == HOUR_SECOND) || (unit == HOUR_MINUTE) ||
(unit == DAY_MICROSECOND) || (unit == DAY_SECOND) || (unit == DAY_MINUTE) ||
(unit == DAY_HOUR) || (unit == DAY) || (unit == WEEK)) {
// This may change the day information
constexpr int64_t microseconds_in_one_second = 1000000L;
int64_t microseconds = this->microsecond() + sign * interval.microsecond;
int64_t microseconds = this->microsecond() + sign * interval.microsecond +
sign * interval.millisecond * 1000L;
int64_t extra_second = microseconds / microseconds_in_one_second;
microseconds -= extra_second * microseconds_in_one_second;
@ -2889,14 +2891,16 @@ bool DateV2Value<T>::date_add_interval(const TimeInterval& interval) {
int sign = interval.is_neg ? -1 : 1;
if constexpr ((unit == MICROSECOND) || (unit == SECOND) || (unit == MINUTE) || (unit == HOUR) ||
(unit == SECOND_MICROSECOND) || (unit == MINUTE_MICROSECOND) ||
(unit == MINUTE_SECOND) || (unit == HOUR_MICROSECOND) || (unit == HOUR_SECOND) ||
(unit == HOUR_MINUTE) || (unit == DAY_MICROSECOND) || (unit == DAY_SECOND) ||
(unit == DAY_MINUTE) || (unit == DAY_HOUR) || (unit == DAY) || (unit == WEEK)) {
if constexpr ((unit == MICROSECOND) || (unit == MILLISECOND) || (unit == SECOND) ||
(unit == MINUTE) || (unit == HOUR) || (unit == SECOND_MICROSECOND) ||
(unit == MINUTE_MICROSECOND) || (unit == MINUTE_SECOND) ||
(unit == HOUR_MICROSECOND) || (unit == HOUR_SECOND) || (unit == HOUR_MINUTE) ||
(unit == DAY_MICROSECOND) || (unit == DAY_SECOND) || (unit == DAY_MINUTE) ||
(unit == DAY_HOUR) || (unit == DAY) || (unit == WEEK)) {
// This may change the day information
constexpr int64_t microseconds_in_one_second = 1000000L;
int64_t microseconds = this->microsecond() + sign * interval.microsecond;
int64_t microseconds = this->microsecond() + sign * interval.microsecond +
sign * interval.millisecond * 1000L;
int64_t extra_second = microseconds / microseconds_in_one_second;
microseconds -= extra_second * microseconds_in_one_second;
@ -3717,6 +3721,10 @@ template int64_t VecDateTimeValue::second_diff<DateV2Value<DateTimeV2ValueType>>
TimeUnit::MICROSECOND, DateValueType2>( \
doris::vectorized::TimeInterval const&, \
doris::vectorized::DateV2Value<DateValueType2>&); \
template bool doris::vectorized::DateV2Value<DateValueType1>::date_add_interval< \
TimeUnit::MILLISECOND, DateValueType2>( \
doris::vectorized::TimeInterval const&, \
doris::vectorized::DateV2Value<DateValueType2>&); \
template bool doris::vectorized::DateV2Value<DateValueType1>::date_add_interval< \
TimeUnit::SECOND, DateValueType2>(doris::vectorized::TimeInterval const&, \
doris::vectorized::DateV2Value<DateValueType2>&); \
@ -3775,6 +3783,8 @@ template bool VecDateTimeValue::date_add_interval<TimeUnit::WEEK, false>(
template bool DateV2Value<DateV2ValueType>::date_add_interval<TimeUnit::MICROSECOND>(
const TimeInterval& interval);
template bool DateV2Value<DateV2ValueType>::date_add_interval<TimeUnit::MILLISECOND>(
const TimeInterval& interval);
template bool DateV2Value<DateV2ValueType>::date_add_interval<TimeUnit::SECOND>(
const TimeInterval& interval);
template bool DateV2Value<DateV2ValueType>::date_add_interval<TimeUnit::MINUTE>(
@ -3794,6 +3804,8 @@ template bool DateV2Value<DateV2ValueType>::date_add_interval<TimeUnit::WEEK>(
template bool DateV2Value<DateTimeV2ValueType>::date_add_interval<TimeUnit::MICROSECOND>(
const TimeInterval& interval);
template bool DateV2Value<DateTimeV2ValueType>::date_add_interval<TimeUnit::MILLISECOND>(
const TimeInterval& interval);
template bool DateV2Value<DateTimeV2ValueType>::date_add_interval<TimeUnit::SECOND>(
const TimeInterval& interval);
template bool DateV2Value<DateTimeV2ValueType>::date_add_interval<TimeUnit::MINUTE>(

View File

@ -48,6 +48,7 @@ using ZoneList = std::unordered_map<std::string, cctz::time_zone>;
enum TimeUnit {
MICROSECOND,
MILLISECOND,
SECOND,
MINUTE,
HOUR,
@ -76,6 +77,7 @@ struct TimeInterval {
int64_t hour;
int64_t minute;
int64_t second;
int64_t millisecond;
int64_t microsecond;
bool is_neg;
@ -86,6 +88,7 @@ struct TimeInterval {
hour(0),
minute(0),
second(0),
millisecond(0),
microsecond(0),
is_neg(false) {}
@ -96,6 +99,7 @@ struct TimeInterval {
hour(0),
minute(0),
second(0),
millisecond(0),
microsecond(0),
is_neg(is_neg_param) {
switch (unit) {
@ -123,6 +127,9 @@ struct TimeInterval {
case SECOND_MICROSECOND:
microsecond = count;
break;
case MILLISECOND:
millisecond = count;
break;
case MICROSECOND:
microsecond = count;
break;
@ -1391,6 +1398,15 @@ int64_t datetime_diff(const DateV2Value<T0>& ts_value1, const DateV2Value<T1>& t
int64_t second = ts_value2.second_diff(ts_value1);
return second;
}
case MILLISECOND: {
int64_t microsecond = ts_value2.microsecond_diff(ts_value1);
int64_t millisecond = microsecond / 1000;
return millisecond;
}
case MICROSECOND: {
int64_t microsecond = ts_value2.microsecond_diff(ts_value1);
return microsecond;
}
}
// Rethink the default return value
return 0;

View File

@ -0,0 +1,49 @@
---
{
"title": "MICROSECONDS_DIFF",
"language": "en"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
## microseconds_diff
### description
#### Syntax
`INT microseconds_diff(DATETIME enddate, DATETIME startdate)`
How many microseconds is the difference between the start time and the end time.
### example
```
mysql> select microseconds_diff('2020-12-25 21:00:00.623000','2020-12-25 21:00:00.123000');
+-----------------------------------------------------------------------------------------------------------------------------+
| microseconds_diff(cast('2020-12-25 21:00:00.623000' as DATETIMEV2(6)), cast('2020-12-25 21:00:00.123000' as DATETIMEV2(6))) |
+-----------------------------------------------------------------------------------------------------------------------------+
| 500000 |
+-----------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.12 sec)
```
### keywords
microseconds_diff

View File

@ -0,0 +1,51 @@
---
{
"title": "MILLISECONDS_ADD",
"language": "en"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
## milliseconds_add
### description
#### Syntax
`DATETIMEV2 milliseconds_add(DATETIMEV2 basetime, INT delta)`
- basetime: Base time whose type is DATETIMEV2
- delta:Milliseconds to add to basetime
- Return type of this function is DATETIMEV2
### example
```
mysql> select milliseconds_add('2023-09-08 16:02:08.435123', 1);
+--------------------------------------------------------------------------+
| milliseconds_add(cast('2023-09-08 16:02:08.435123' as DATETIMEV2(6)), 1) |
+--------------------------------------------------------------------------+
| 2023-09-08 16:02:08.436123 |
+--------------------------------------------------------------------------+
1 row in set (0.04 sec)
```
### keywords
milliseconds_add

View File

@ -0,0 +1,49 @@
---
{
"title": "MILLISECONDS_DIFF",
"language": "en"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
## milliseconds_diff
### description
#### Syntax
`INT milliseconds_diff(DATETIME enddate, DATETIME startdate)`
How many milliseconds is the difference between the start time and the end time?
### example
```
mysql> select milliseconds_diff('2020-12-25 21:00:00.623000','2020-12-25 21:00:00.123000');
+-----------------------------------------------------------------------------------------------------------------------------+
| milliseconds_diff(cast('2020-12-25 21:00:00.623000' as DATETIMEV2(6)), cast('2020-12-25 21:00:00.123000' as DATETIMEV2(6))) |
+-----------------------------------------------------------------------------------------------------------------------------+
| 500 |
+-----------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.03 sec)
```
### keywords
milliseconds_diff

View File

@ -0,0 +1,51 @@
---
{
"title": "MILLISECONDS_SUB",
"language": "en"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
## milliseconds_sub
### description
#### Syntax
`DATETIMEV2 milliseconds_sub(DATETIMEV2 basetime, INT delta)`
- basetime: Base time whose type is DATETIMEV2
- delta: Milliseconds to subtract from basetime
- Return type of this function is DATETIMEV2
### example
```
mysql> select milliseconds_sub('2023-09-08 16:02:08.435123', 1);
+--------------------------------------------------------------------------+
| milliseconds_sub(cast('2023-09-08 16:02:08.435123' as DATETIMEV2(6)), 1) |
+--------------------------------------------------------------------------+
| 2023-09-08 16:02:08.434123 |
+--------------------------------------------------------------------------+
1 row in set (0.11 sec)
```
### keywords
milliseconds_sub

View File

@ -356,6 +356,11 @@
"sql-manual/sql-functions/date-time-functions/date-format",
"sql-manual/sql-functions/date-time-functions/datediff",
"sql-manual/sql-functions/date-time-functions/microseconds-add",
"sql-manual/sql-functions/date-time-functions/microseconds-diff",
"sql-manual/sql-functions/date-time-functions/microseconds-sub",
"sql-manual/sql-functions/date-time-functions/milliseconds-add",
"sql-manual/sql-functions/date-time-functions/milliseconds-diff",
"sql-manual/sql-functions/date-time-functions/milliseconds-sub",
"sql-manual/sql-functions/date-time-functions/minutes-add",
"sql-manual/sql-functions/date-time-functions/minutes-diff",
"sql-manual/sql-functions/date-time-functions/minutes-sub",

View File

@ -0,0 +1,49 @@
---
{
"title": "MICROSECONDS_DIFF",
"language": "zh-CN"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
## microseconds_diff
### description
#### Syntax
`INT microseconds_diff(DATETIME enddate, DATETIME startdate)`
开始时间到结束时间相差几微秒
### example
```
mysql> select microseconds_diff('2020-12-25 21:00:00.623000','2020-12-25 21:00:00.123000');
+-----------------------------------------------------------------------------------------------------------------------------+
| microseconds_diff(cast('2020-12-25 21:00:00.623000' as DATETIMEV2(6)), cast('2020-12-25 21:00:00.123000' as DATETIMEV2(6))) |
+-----------------------------------------------------------------------------------------------------------------------------+
| 500000 |
+-----------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.12 sec)
```
### keywords
microseconds_diff

View File

@ -0,0 +1,51 @@
---
{
"title": "MILLISECONDS_ADD",
"language": "zh-CN"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
## milliseconds_add
### description
#### Syntax
`DATETIMEV2 milliseconds_add(DATETIMEV2 basetime, INT delta)`
- basetime: DATETIMEV2 类型起始时间
- delta: 从 basetime 起需要相加的毫秒数
- 返回类型为 DATETIMEV2
### example
```
mysql> select milliseconds_add('2023-09-08 16:02:08.435123', 1);
+--------------------------------------------------------------------------+
| milliseconds_add(cast('2023-09-08 16:02:08.435123' as DATETIMEV2(6)), 1) |
+--------------------------------------------------------------------------+
| 2023-09-08 16:02:08.436123 |
+--------------------------------------------------------------------------+
1 row in set (0.04 sec)
```
### keywords
milliseconds_add

View File

@ -0,0 +1,49 @@
---
{
"title": "MILLISECONDS_DIFF",
"language": "zh-CN"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
## milliseconds_diff
### description
#### Syntax
`INT milliseconds_diff(DATETIME enddate, DATETIME startdate)`
开始时间到结束时间相差几毫秒
### example
```
mysql> select milliseconds_diff('2020-12-25 21:00:00.623000','2020-12-25 21:00:00.123000');
+-----------------------------------------------------------------------------------------------------------------------------+
| milliseconds_diff(cast('2020-12-25 21:00:00.623000' as DATETIMEV2(6)), cast('2020-12-25 21:00:00.123000' as DATETIMEV2(6))) |
+-----------------------------------------------------------------------------------------------------------------------------+
| 500 |
+-----------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.03 sec)
```
### keywords
milliseconds_diff

View File

@ -0,0 +1,51 @@
---
{
"title": "MILLISECONDS_SUB",
"language": "zh-CN"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
## milliseconds_sub
### description
#### Syntax
`DATETIMEV2 milliseconds_sub(DATETIMEV2 basetime, INT delta)`
- basetime: DATETIMEV2 类型起始时间
- delta: 从 basetime 起需要扣减的毫秒数
- 返回类型为 DATETIMEV2
### example
```
mysql> select milliseconds_sub('2023-09-08 16:02:08.435123', 1);
+--------------------------------------------------------------------------+
| milliseconds_sub(cast('2023-09-08 16:02:08.435123' as DATETIMEV2(6)), 1) |
+--------------------------------------------------------------------------+
| 2023-09-08 16:02:08.434123 |
+--------------------------------------------------------------------------+
1 row in set (0.11 sec)
```
### keywords
milliseconds_sub

View File

@ -576,7 +576,9 @@ public class FunctionCallExpr extends Expr {
|| fnName.getFunction().equalsIgnoreCase("days_diff")
|| fnName.getFunction().equalsIgnoreCase("hours_diff")
|| fnName.getFunction().equalsIgnoreCase("minutes_diff")
|| fnName.getFunction().equalsIgnoreCase("seconds_diff")) {
|| fnName.getFunction().equalsIgnoreCase("seconds_diff")
|| fnName.getFunction().equalsIgnoreCase("milliseconds_diff")
|| fnName.getFunction().equalsIgnoreCase("microseconds_diff")) {
sb.append(children.get(0).toSql()).append(", ");
sb.append(children.get(1).toSql()).append(")");
return sb.toString();

View File

@ -224,8 +224,14 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.MaskLastN;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Md5;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Md5Sum;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MicroSecondTimestamp;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MicroSecondsAdd;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MicroSecondsDiff;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MicroSecondsSub;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Microsecond;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MilliSecondTimestamp;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MilliSecondsAdd;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MilliSecondsDiff;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MilliSecondsSub;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Minute;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MinuteCeil;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MinuteFloor;
@ -586,6 +592,12 @@ public class BuiltinScalarFunctions implements FunctionHelper {
scalar(Md5.class, "md5"),
scalar(Md5Sum.class, "md5sum"),
scalar(Microsecond.class, "microsecond"),
scalar(MicroSecondsAdd.class, "microseconds_add"),
scalar(MicroSecondsDiff.class, "microseconds_diff"),
scalar(MicroSecondsSub.class, "microseconds_sub"),
scalar(MilliSecondsAdd.class, "milliseconds_add"),
scalar(MilliSecondsDiff.class, "milliseconds_diff"),
scalar(MilliSecondsSub.class, "milliseconds_sub"),
scalar(Minute.class, "minute"),
scalar(MinuteCeil.class, "minute_ceil"),
scalar(MinuteFloor.class, "minute_floor"),

View File

@ -0,0 +1,64 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.doris.nereids.trees.expressions.functions.scalar;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args;
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
/**
* ScalarFunction 'MicroSeconds_add'.
*/
public class MicroSecondsAdd extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT)
.args(DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE)
);
public MicroSecondsAdd(Expression arg0, Expression arg1) {
super("microseconds_add", arg0, arg1);
}
@Override
public MicroSecondsAdd withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() == 2);
return new MicroSecondsAdd(children.get(0), children.get(1));
}
@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitMicroSecondsAdd(this, context);
}
}

View File

@ -0,0 +1,70 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.doris.nereids.trees.expressions.functions.scalar;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args;
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.BigIntType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
/**
* ScalarFunction 'microseconds_diff'. This class is generated by GenerateFunction.
*/
public class MicroSecondsDiff extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(BigIntType.INSTANCE)
.args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT)
);
/**
* constructor with 2 arguments.
*/
public MicroSecondsDiff(Expression arg0, Expression arg1) {
super("microseconds_diff", arg0, arg1);
}
/**
* withChildren.
*/
@Override
public MicroSecondsDiff withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() == 2);
return new MicroSecondsDiff(children.get(0), children.get(1));
}
@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitMicroSecondsDiff(this, context);
}
}

View File

@ -0,0 +1,64 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.doris.nereids.trees.expressions.functions.scalar;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args;
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
/**
* ScalarFunction 'MicroSeconds_sub'.
*/
public class MicroSecondsSub extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT)
.args(DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE)
);
public MicroSecondsSub(Expression arg0, Expression arg1) {
super("microseconds_sub", arg0, arg1);
}
@Override
public MicroSecondsSub withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() == 2);
return new MicroSecondsSub(children.get(0), children.get(1));
}
@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitMicroSecondsSub(this, context);
}
}

View File

@ -0,0 +1,64 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.doris.nereids.trees.expressions.functions.scalar;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args;
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
/**
* ScalarFunction 'MilliSeconds_add'.
*/
public class MilliSecondsAdd extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT)
.args(DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE)
);
public MilliSecondsAdd(Expression arg0, Expression arg1) {
super("milliseconds_add", arg0, arg1);
}
@Override
public MilliSecondsAdd withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() == 2);
return new MilliSecondsAdd(children.get(0), children.get(1));
}
@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitMilliSecondsAdd(this, context);
}
}

View File

@ -0,0 +1,70 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.doris.nereids.trees.expressions.functions.scalar;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args;
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.BigIntType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
/**
* ScalarFunction 'milliseconds_diff'. This class is generated by GenerateFunction.
*/
public class MilliSecondsDiff extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(BigIntType.INSTANCE)
.args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT)
);
/**
* constructor with 2 arguments.
*/
public MilliSecondsDiff(Expression arg0, Expression arg1) {
super("milliseconds_diff", arg0, arg1);
}
/**
* withChildren.
*/
@Override
public MilliSecondsDiff withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() == 2);
return new MilliSecondsDiff(children.get(0), children.get(1));
}
@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitMilliSecondsDiff(this, context);
}
}

View File

@ -0,0 +1,64 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.doris.nereids.trees.expressions.functions.scalar;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args;
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
/**
* ScalarFunction 'MilliSeconds_sub'.
*/
public class MilliSecondsSub extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT)
.args(DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE)
);
public MilliSecondsSub(Expression arg0, Expression arg1) {
super("milliseconds_sub", arg0, arg1);
}
@Override
public MilliSecondsSub withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() == 2);
return new MilliSecondsSub(children.get(0), children.get(1));
}
@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitMilliSecondsSub(this, context);
}
}

View File

@ -224,7 +224,13 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.MaskFirstN;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MaskLastN;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Md5;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Md5Sum;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MicroSecondsAdd;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MicroSecondsDiff;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MicroSecondsSub;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Microsecond;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MilliSecondsAdd;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MilliSecondsDiff;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MilliSecondsSub;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Minute;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MinuteCeil;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MinuteFloor;
@ -821,6 +827,22 @@ public interface ScalarFunctionVisitor<R, C> {
return visitScalarFunction(secondsSub, context);
}
default R visitMilliSecondsSub(MilliSecondsSub millisecondsSub, C context) {
return visitScalarFunction(millisecondsSub, context);
}
default R visitMilliSecondsAdd(MilliSecondsAdd millisecondsAdd, C context) {
return visitScalarFunction(millisecondsAdd, context);
}
default R visitMicroSecondsSub(MicroSecondsSub microsecondsSub, C context) {
return visitScalarFunction(microsecondsSub, context);
}
default R visitMicroSecondsAdd(MicroSecondsAdd microsecondsAdd, C context) {
return visitScalarFunction(microsecondsAdd, context);
}
default R visitMonthsAdd(MonthsAdd monthsAdd, C context) {
return visitScalarFunction(monthsAdd, context);
}
@ -1397,6 +1419,14 @@ public interface ScalarFunctionVisitor<R, C> {
return visitScalarFunction(secondsDiff, context);
}
default R visitMilliSecondsDiff(MilliSecondsDiff milliSecondsDiff, C context) {
return visitScalarFunction(milliSecondsDiff, context);
}
default R visitMicroSecondsDiff(MicroSecondsDiff microSecondsDiff, C context) {
return visitScalarFunction(microSecondsDiff, context);
}
default R visitSign(Sign sign, C context) {
return visitScalarFunction(sign, context);
}

View File

@ -935,8 +935,6 @@ visible_functions = {
[['minutes_sub'], 'DATETIME', ['DATETIME', 'INT'], 'ALWAYS_NULLABLE'],
[['seconds_add'], 'DATETIME', ['DATETIME', 'INT'], 'ALWAYS_NULLABLE'],
[['seconds_sub'], 'DATETIME', ['DATETIME', 'INT'], 'ALWAYS_NULLABLE'],
[['microseconds_add'], 'DATETIME', ['DATETIME', 'INT'], ''],
[['microseconds_sub'], 'DATETIME', ['DATETIME', 'INT'], ''],
[['datediff'], 'INT', ['DATETIME', 'DATETIME'], 'ALWAYS_NULLABLE'],
[['timediff'], 'TIME', ['DATETIME', 'DATETIME'], 'ALWAYS_NULLABLE'],
@ -1072,6 +1070,8 @@ visible_functions = {
[['seconds_sub'], 'DATETIMEV2', ['DATETIMEV2', 'INT'], ''],
[['microseconds_add'], 'DATETIMEV2', ['DATETIMEV2', 'INT'], ''],
[['microseconds_sub'], 'DATETIMEV2', ['DATETIMEV2', 'INT'], ''],
[['milliseconds_add'], 'DATETIMEV2', ['DATETIMEV2', 'INT'], ''],
[['milliseconds_sub'], 'DATETIMEV2', ['DATETIMEV2', 'INT'], ''],
[['years_add'], 'DATEV2', ['DATEV2', 'INT'], ''],
[['years_sub'], 'DATEV2', ['DATEV2', 'INT'], ''],
@ -1089,6 +1089,8 @@ visible_functions = {
[['seconds_sub'], 'DATETIMEV2', ['DATEV2', 'INT'], ''],
[['microseconds_add'], 'DATETIMEV2', ['DATEV2', 'INT'], ''],
[['microseconds_sub'], 'DATETIMEV2', ['DATEV2', 'INT'], ''],
[['milliseconds_add'], 'DATETIMEV2', ['DATEV2', 'INT'], ''],
[['milliseconds_sub'], 'DATETIMEV2', ['DATEV2', 'INT'], ''],
[['datediff'], 'INT', ['DATETIMEV2', 'DATETIMEV2'], ''],
[['timediff'], 'TIMEV2', ['DATETIMEV2', 'DATETIMEV2'], ''],
@ -1121,6 +1123,8 @@ visible_functions = {
[['hours_diff'], 'BIGINT', ['DATETIMEV2', 'DATETIMEV2'], ''],
[['minutes_diff'], 'BIGINT', ['DATETIMEV2', 'DATETIMEV2'], ''],
[['seconds_diff'], 'BIGINT', ['DATETIMEV2', 'DATETIMEV2'], ''],
[['microseconds_diff'], 'BIGINT', ['DATETIMEV2', 'DATETIMEV2'], ''],
[['milliseconds_diff'], 'BIGINT', ['DATETIMEV2', 'DATETIMEV2'], ''],
[['years_diff'], 'BIGINT', ['DATEV2', 'DATETIMEV2'], ''],
[['months_diff'], 'BIGINT', ['DATEV2', 'DATETIMEV2'], ''],
@ -1129,6 +1133,8 @@ visible_functions = {
[['hours_diff'], 'BIGINT', ['DATEV2', 'DATETIMEV2'], ''],
[['minutes_diff'], 'BIGINT', ['DATEV2', 'DATETIMEV2'], ''],
[['seconds_diff'], 'BIGINT', ['DATEV2', 'DATETIMEV2'], ''],
[['microseconds_diff'], 'BIGINT', ['DATEV2', 'DATETIMEV2'], ''],
[['milliseconds_diff'], 'BIGINT', ['DATEV2', 'DATETIMEV2'], ''],
[['years_diff'], 'BIGINT', ['DATETIMEV2', 'DATEV2'], ''],
[['months_diff'], 'BIGINT', ['DATETIMEV2', 'DATEV2'], ''],
@ -1137,6 +1143,8 @@ visible_functions = {
[['hours_diff'], 'BIGINT', ['DATETIMEV2', 'DATEV2'], ''],
[['minutes_diff'], 'BIGINT', ['DATETIMEV2', 'DATEV2'], ''],
[['seconds_diff'], 'BIGINT', ['DATETIMEV2', 'DATEV2'], ''],
[['microseconds_diff'], 'BIGINT', ['DATETIMEV2', 'DATEV2'], ''],
[['milliseconds_diff'], 'BIGINT', ['DATETIMEV2', 'DATEV2'], ''],
[['years_diff'], 'BIGINT', ['DATEV2', 'DATEV2'], ''],
[['months_diff'], 'BIGINT', ['DATEV2', 'DATEV2'], ''],
@ -1145,6 +1153,8 @@ visible_functions = {
[['hours_diff'], 'BIGINT', ['DATEV2', 'DATEV2'], ''],
[['minutes_diff'], 'BIGINT', ['DATEV2', 'DATEV2'], ''],
[['seconds_diff'], 'BIGINT', ['DATEV2', 'DATEV2'], ''],
[['microseconds_diff'], 'BIGINT', ['DATEV2', 'DATEV2'], ''],
[['milliseconds_diff'], 'BIGINT', ['DATEV2', 'DATEV2'], ''],
[['year_floor'], 'DATETIMEV2', ['DATETIMEV2'], 'ALWAYS_NULLABLE'],
[['year_floor'], 'DATETIMEV2', ['DATETIMEV2', 'DATETIMEV2'], 'ALWAYS_NULLABLE'],

View File

@ -49,3 +49,39 @@ false
-- !compare_dt2 --
false
-- !sql_milliseconds_add_datetimev2_1 --
2022-01-01T11:11:11.111 2022-01-01T11:11:11.211
2022-01-01T11:11:11.222 2022-01-01T11:11:11.322
-- !sql_milliseconds_add_datetimev2_2 --
2022-01-01T11:11:11.111 2022-01-01T11:11:11.311
2022-01-01T11:11:11.222 2022-01-01T11:11:11.422
-- !sql_milliseconds_add_datetimev2_3 --
2022-01-01T11:11:11.111 2022-01-01T11:11:11.911
2022-01-01T11:11:11.222 2022-01-01T11:11:12.022
-- !sql_milliseconds_add_datetimev2_4 --
2022-01-01T11:11:11.111 2022-01-01T11:11:11.011
2022-01-01T11:11:11.222 2022-01-01T11:11:11.122
-- !sql_milliseconds_add_datetimev2_5 --
2022-01-01T11:11:11.111 2022-01-01T11:11:10.911
2022-01-01T11:11:11.222 2022-01-01T11:11:11.022
-- !sql_milliseconds_sub_datetimev2_1 --
2022-01-01T11:11:11.111 2022-01-01T11:11:11.011
2022-01-01T11:11:11.222 2022-01-01T11:11:11.122
-- !sql_milliseconds_sub_datetimev2_2 --
2022-01-01T11:11:11.111 2022-01-01T11:11:10.911
2022-01-01T11:11:11.222 2022-01-01T11:11:11.022
-- !sql_milliseconds_sub_datetimev2_3 --
2022-01-01T11:11:11.111 2022-01-01T11:11:11.311
2022-01-01T11:11:11.222 2022-01-01T11:11:11.422
-- !sql_milliseconds_sub_datetimev2_4 --
2022-01-01T11:11:11.111 2022-01-01T11:11:11.911
2022-01-01T11:11:11.222 2022-01-01T11:11:12.022

View File

@ -17,3 +17,9 @@
-- !sql --
63113904000
-- !sql --
3020399000
-- !sql --
3020399000000

View File

@ -65,4 +65,25 @@ suite("test_exprs") {
qt_compare_dt1 "select /*SET_VAR(experimental_enable_nereids_planner=true)*/ cast('2020-12-12 12:12:12.123456' as datetime(6)) = cast('2020-12-12 12:12:12.123455' as datetime(6));"
qt_compare_dt2 "select /*SET_VAR(experimental_enable_nereids_planner=false)*/ cast('2020-12-12 12:12:12.123456' as datetime(6)) = cast('2020-12-12 12:12:12.123455' as datetime(6));"
// `milliseconds_add` suites
// 1. Positive milliseconds delta
qt_sql_milliseconds_add_datetimev2_1 " select col,milliseconds_add(col, 100) col1 from ${table1} order by col1; "
qt_sql_milliseconds_add_datetimev2_2 " select col,milliseconds_add(col, 200) col1 from ${table1} order by col1; "
// 1.1 Positive microseconds delta affects second change
qt_sql_milliseconds_add_datetimev2_3 " select col,milliseconds_add(col, 800) col1 from ${table1} order by col1; "
// 2. Negative microseconds delta
qt_sql_milliseconds_add_datetimev2_4 " select col,milliseconds_add(col, -100) col1 from ${table1} order by col1; "
// 2.1 Negative microseconds delta affects second change
qt_sql_milliseconds_add_datetimev2_5 " select col,milliseconds_add(col, -200) col1 from ${table1} order by col1; "
// `microseconds_sub` suites
// 1. Positive microseconds delta
qt_sql_milliseconds_sub_datetimev2_1 " select col,milliseconds_sub(col, 100) col1 from ${table1} order by col1; "
// 1.1 Positive microseconds delta affects second change
qt_sql_milliseconds_sub_datetimev2_2 " select col,milliseconds_sub(col, 200) col1 from ${table1} order by col1; "
// 2. Negative microseconds delta
qt_sql_milliseconds_sub_datetimev2_3 " select col,milliseconds_sub(col, -200) col1 from ${table1} order by col1; "
// 2.2 Negative microseconds delta affects second change
qt_sql_milliseconds_sub_datetimev2_4 " select col,milliseconds_sub(col, -800) col1 from ${table1} order by col1; "
}

View File

@ -22,4 +22,7 @@ suite("test_time_diff") {
qt_sql """SELECT hours_diff('9020-02-02 15:30:00', '1900-02-16 15:27:00'); """
qt_sql """SELECT seconds_diff('3000-02-02 15:30:00', '1900-02-16 15:27:00'); """
qt_sql """SELECT seconds_diff('3000-01-01 00:00:00', '1000-01-01 00:00:00'); """
qt_sql """SELECT milliseconds_diff('2020-02-02 15:30:00', '1951-02-16 15:27:00'); """
qt_sql """SELECT microseconds_diff('2020-02-02 15:30:00', '1951-02-16 15:27:00'); """
}