zclllyybb commented on code in PR #56945:
URL: https://github.com/apache/doris/pull/56945#discussion_r2430961982
##########
be/src/vec/functions/function_date_or_datetime_computation.h:
##########
@@ -1267,5 +1267,236 @@ class FunctionTime : public IFunction {
return Status::OK();
}
};
+
+class PeriodHelper {
+protected:
+ // For two digit year, 70-99 -> 1970-1999, 00-69 -> 2000-2069
+ // this rule is same as MySQL
+ static constexpr int YY_PART_YEAR = 70;
+ static Status valid_period(int64_t period) {
+ if (period <= 0 || (period % 100) == 0 || (period % 100) > 12) {
+ return Status::InvalidArgument("Period function got invalid
period: {}", period);
+ }
+ return Status::OK();
+ }
+
+ static int64_t check_and_convert_period_to_month(uint64_t period) {
+ THROW_IF_ERROR(valid_period(period));
+ uint64_t year = period / 100;
+ if (year < 100) {
+ year += (year >= YY_PART_YEAR) ? 1900 : 2000;
+ }
+ return year * 12LL + (period % 100) - 1;
+ }
+
+ static int64_t convert_month_to_period(uint64_t month) {
+ uint64_t year = month / 12;
+ if (year < 100) {
+ year += (year >= YY_PART_YEAR) ? 1900 : 2000;
+ }
+ return year * 100 + month % 12 + 1;
+ }
+};
+
+template <typename Impl>
+class FunctionPeriodUnion : public IFunction {
+public:
+ static constexpr auto name = Impl::name;
+ static FunctionPtr create() { return
std::make_shared<FunctionPeriodUnion>(); }
+ String get_name() const override { return name; }
+ size_t get_number_of_arguments() const override { return 2; }
+ bool use_default_implementation_for_nulls() const override { return false;
}
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
+ return std::make_shared<DataTypeInt64>();
+ }
+
+ Status execute_impl(FunctionContext* context, Block& block, const
ColumnNumbers& arguments,
Review Comment:
这种const+nullable都要处理的,提取个基模板出来吧,估计有很多函数可以复用
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]