-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add timediff function #1505
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
Merged
Merged
Add timediff function #1505
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // 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. | ||
|
|
||
| #include "exprs/time_operators.h" | ||
|
|
||
| #include <iomanip> | ||
| #include <sstream> | ||
| #include <math.h> | ||
|
|
||
| #include "exprs/anyval_util.h" | ||
| #include "exprs/case_expr.h" | ||
| #include "exprs/expr.h" | ||
| #include "runtime/tuple_row.h" | ||
| #include "util/string_parser.hpp" | ||
| #include "util/date_func.h" | ||
|
|
||
| namespace doris { | ||
| void TimeOperators::init() { | ||
| } | ||
|
|
||
| #define CAST_TIME_TO_INT(to_type, type_name) \ | ||
| to_type TimeOperators::cast_to_##type_name( \ | ||
| FunctionContext* context, const DoubleVal& val) { \ | ||
| if (val.is_null) return to_type::null(); \ | ||
| int time = (int) val.val ; \ | ||
| int second = time % 60; \ | ||
| int minute = time / 60 % 60; \ | ||
| int hour = time / 3600; \ | ||
| return to_type(hour * 10000 + minute * 100 + second); \ | ||
| } | ||
|
|
||
| #define CAST_FROM_TIME() \ | ||
| CAST_TIME_TO_INT(BooleanVal, boolean_val);\ | ||
| CAST_TIME_TO_INT(TinyIntVal, tiny_int_val);\ | ||
| CAST_TIME_TO_INT(SmallIntVal, small_int_val);\ | ||
| CAST_TIME_TO_INT(IntVal, int_val);\ | ||
| CAST_TIME_TO_INT(BigIntVal, big_int_val);\ | ||
| CAST_TIME_TO_INT(LargeIntVal, large_int_val);\ | ||
| CAST_TIME_TO_INT(FloatVal, float_val);\ | ||
| CAST_TIME_TO_INT(DoubleVal, double_val); | ||
|
|
||
| CAST_FROM_TIME(); | ||
|
|
||
| StringVal TimeOperators::cast_to_string_val( | ||
| FunctionContext* ctx, const DoubleVal& val) { | ||
| if (val.is_null) { | ||
| return StringVal::null(); | ||
| } | ||
| return AnyValUtil::from_string_temp(ctx, time_str_from_int(val.val)); | ||
| } | ||
|
|
||
| DateTimeVal TimeOperators::cast_to_datetime_val( | ||
| FunctionContext* context, const DoubleVal& val) { | ||
| return DateTimeVal::null(); | ||
| } | ||
|
|
||
| DecimalVal TimeOperators::cast_to_decimal_val( | ||
| FunctionContext* context, const DoubleVal& val) { | ||
| return DecimalVal::null(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // 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. | ||
|
|
||
| #ifndef DORIS_BE_SRC_EXPRS_TIME_OPERATORS_H | ||
| #define DORIS_BE_SRC_EXPRS_TIME_OPERATORS_H | ||
|
|
||
| #include <stdint.h> | ||
| #include "udf/udf.h" | ||
|
|
||
| namespace doris { | ||
| class Expr; | ||
| struct ExprValue; | ||
| class TupleRow; | ||
|
|
||
| /// Implementation of the time operators. These include the cast, | ||
| /// arithmetic and binary operators. | ||
| class TimeOperators { | ||
| public: | ||
| static void init(); | ||
|
|
||
| static BooleanVal cast_to_boolean_val(FunctionContext*, const DoubleVal&); | ||
| static TinyIntVal cast_to_tiny_int_val(FunctionContext*, const DoubleVal&); | ||
| static SmallIntVal cast_to_small_int_val(FunctionContext*, const DoubleVal&); | ||
| static IntVal cast_to_int_val(FunctionContext*, const DoubleVal&); | ||
| static BigIntVal cast_to_big_int_val(FunctionContext*, const DoubleVal&); | ||
| static LargeIntVal cast_to_large_int_val(FunctionContext*, const DoubleVal&); | ||
| static FloatVal cast_to_float_val(FunctionContext*, const DoubleVal&); | ||
| static DoubleVal cast_to_double_val(FunctionContext*, const DoubleVal&); | ||
| static StringVal cast_to_string_val(FunctionContext*, const DoubleVal&); | ||
| static DateTimeVal cast_to_datetime_val(FunctionContext*, const DoubleVal&); | ||
| static DecimalVal cast_to_decimal_val(FunctionContext*, const DoubleVal&); | ||
| }; | ||
| } | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| #include "runtime/buffer_control_block.h" | ||
| #include "util/mysql_row_buffer.h" | ||
| #include "util/types.h" | ||
| #include "util/date_func.h" | ||
|
|
||
| #include "gen_cpp/PaloInternalService_types.h" | ||
|
|
||
|
|
@@ -104,6 +105,13 @@ Status ResultWriter::add_one_row(TupleRow* row) { | |
| buf_ret = _row_buffer->push_double(*static_cast<double*>(item)); | ||
| break; | ||
|
|
||
| case TYPE_TIME: { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can write a function to do this to avoid write this many times |
||
| double time = *static_cast<double *>(item); | ||
| std::string time_str = time_str_from_int((int) time); | ||
| buf_ret = _row_buffer->push_string(time_str.c_str(), time_str.size()); | ||
| break; | ||
| } | ||
|
|
||
| case TYPE_DATE: | ||
| case TYPE_DATETIME: { | ||
| char buf[64]; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can only support time to double and to string