-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add timediff function #1505
Add timediff function #1505
Conversation
I think that you need't import a new udf type to implement timediff. |
gensrc/script/gen_functions.py
Outdated
@@ -552,6 +554,7 @@ | |||
'VARCHAR': 'string_val', | |||
'DATE': 'datetime_val', | |||
'DATETIME': 'datetime_val', | |||
'TIME': 'datetime_val', |
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 it's better to use bigint_val
@@ -89,6 +91,11 @@ public IntLiteral(long longValue, Type type) throws AnalysisException { | |||
} | |||
// no need to check upper bound | |||
break; | |||
case TIME: |
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 it is not fit to add type TIME in IntLiteral
be/src/runtime/result_writer.cpp
Outdated
@@ -105,7 +105,8 @@ Status ResultWriter::add_one_row(TupleRow* row) { | |||
break; | |||
|
|||
case TYPE_DATE: | |||
case TYPE_DATETIME: { | |||
case TYPE_DATETIME: | |||
case TYPE_TIME: { | |||
char buf[64]; | |||
const DateTimeValue* time_val = (const DateTimeValue*)(item); |
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 use bigint to represent time in memory?
403f208
to
4fb06b4
Compare
be/src/exprs/literal.cpp
Outdated
@@ -87,6 +87,11 @@ Literal::Literal(const TExprNode& node) : | |||
_value.datetime_val.from_date_str( | |||
node.date_literal.value.c_str(), node.date_literal.value.size()); | |||
break; | |||
case TYPE_TIME: |
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.
reuse TYPE_DOUBLE
public: | ||
static void init(); | ||
|
||
static BooleanVal cast_to_boolean_val(FunctionContext*, const DoubleVal&); |
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
be/src/runtime/raw_value.cpp
Outdated
@@ -267,6 +267,7 @@ void RawValue::write(const void* value, void* dst, const TypeDescriptor& type, M | |||
break; | |||
} | |||
|
|||
case TYPE_TIME: |
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 this should be the same as TYPE_DOUBLE
@@ -104,6 +104,39 @@ Status ResultWriter::add_one_row(TupleRow* row) { | |||
buf_ret = _row_buffer->push_double(*static_cast<double*>(item)); | |||
break; | |||
|
|||
case TYPE_TIME: { |
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.
you can write a function to do this to avoid write this many times
@@ -480,6 +481,7 @@ public static String getUdfType(PrimitiveType t) { | |||
case INT: | |||
return "IntVal"; | |||
case BIGINT: | |||
case TIME: |
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.
why BIGINT?
@@ -480,6 +486,7 @@ public static boolean isImplicitCast(PrimitiveType type, PrimitiveType target) { | |||
compatibilityMatrix[DECIMALV2.ordinal()][DECIMAL.ordinal()] = DECIMALV2; | |||
|
|||
compatibilityMatrix[HLL.ordinal()][HLL.ordinal()] = HLL; | |||
compatibilityMatrix[TIME.ordinal()][TIME.ordinal()] = TIME; |
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.
you should add more relation between time and other types
e649d62
to
92d7b85
Compare
…to add-timediff
92d7b85
to
7118a60
Compare
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.
LGTM
merge to apache-doris 0694b6a
Add timediff function
#1428