-
Notifications
You must be signed in to change notification settings - Fork 14
Conversation
de68bcd
to
510ca18
Compare
586db69
to
c83d743
Compare
return {builder_, expr_->cast(new_type), "", true}; | ||
} | ||
} else if (expr_->type()->isTimestamp()) { | ||
if (new_type->isNumber() || new_type->isDate() || new_type->isTimestamp()) { | ||
if (new_type->isInteger() || new_type->isDate() || new_type->isTime() || |
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 use isDateTime
here.
omniscidb/QueryEngine/CastIR.cpp
Outdated
@@ -108,6 +108,14 @@ llvm::Value* CodeGenerator::codegenCast(llvm::Value* operand_lv, | |||
operand_type->as<hdk::ir::TimestampType>()->unit(), | |||
type->nullable()); | |||
} | |||
if (operand_type->isTimestamp() && type->isTime()) { | |||
const auto operand_unit = (operand_type->isTimestamp()) |
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 know here operand_type
is a timestamp.
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.
removed
omniscidb/QueryEngine/CastIR.cpp
Outdated
? operand_type->as<hdk::ir::TimestampType>()->unit() | ||
: hdk::ir::TimeUnit::kSecond; | ||
// if (operand_unit != type->as<hdk::ir::TimestampType>()->unit()) { | ||
return codegenCastTimestampToTime(operand_lv, operand_type, type, type->nullable()); |
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 don't see why nullalbe
should be a separate argument if it can be extracted from types. Also, not clear why we use nullable
from the target type, not the source.
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.
removed unnecessary argument.
omniscidb/QueryEngine/CastIR.cpp
Outdated
LOG(ERROR) << " units from: " << operand_unit << " to: " << target_unit; | ||
CHECK(ts_lv->getType()->isIntegerTy(64)); | ||
const auto target_sec_scale = hdk::ir::unitsPerSecond(target_unit) / | ||
hdk::ir::unitsPerSecond(hdk::ir::TimeUnit::kSecond); |
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.
No need to divide by 1.
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.
removed
omniscidb/QueryEngine/CastIR.cpp
Outdated
{{ts_lv, | ||
cgen_state_->llInt(scale), | ||
cgen_state_->llInt(target_sec_scale), | ||
cgen_state_->inlineIntNull(ctx.int64())}}); |
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.
Null arg is not required here.
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.
removed
omniscidb/QueryEngine/CastIR.cpp
Outdated
{{ts_lv, | ||
cgen_state_->llInt(scale), | ||
cgen_state_->llInt(target_sec_scale), | ||
cgen_state_->inlineIntNull(ctx.int64())}}); |
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.
Null arg is not required here.
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.
removed
omniscidb/QueryEngine/CastIR.cpp
Outdated
{{ts_lv, | ||
cgen_state_->llInt(scale), | ||
cgen_state_->llInt(target_sec_scale), | ||
cgen_state_->inlineIntNull(ctx.int64())}}); |
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 you need to use operand_type to get a proper null value.
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.
agree, passing source and target null values
const int64_t target_sec_scale, | ||
const int64_t null_val) { | ||
if (timeval == null_val) { | ||
return null_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.
Here we need to return the target null value, not the source one.
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.
agree, done
omniscidb/Tests/QueryBuilderTest.cpp
Outdated
|
||
createTable("test_tmstmp", | ||
{{"col_bi", ctx().int64()}, | ||
{"col_tmstp", ctx().timestamp(hdk::ir::TimeUnit::kSecond)}, |
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.
Also, try non-nullable types. For nullable types add some NULL values.
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.
made 2 tests, first one is non-nullable, second one is nullable.
19e5a39
to
7125f3c
Compare
1e60caa
to
a587707
Compare
I am not sure, that nulls handled in correct way. Arrow array in case Time32[s] will have int32, canonical type is int64, so in ResultSet will be null int64_t, after conversion to arrow int32 null. |
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.
Overall looks good!
I just have some non-functional comments.
The only open question remaining for me is negative timestamps. I see them in tests but don't actually understand how we handle them using unsigned mod. Can you elaborate on this?
// scale is 10^{3,6,9} | ||
inline DEVICE int64_t | ||
timestamp_to_time_truncation_upscale(const int64_t timeval, | ||
const int64_t conersion_scale, |
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.
conersion -> conversion in multiple places
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.
done
timestamp_to_time_truncation_upscale(const int64_t timeval, | ||
const int64_t conersion_scale, | ||
const int64_t target_sec_scale) { | ||
return unsigned_mod(timeval * conersion_scale, target_sec_scale * kSecsPerDay); |
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.
So what about negative values? Do we support them?
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.
yes, changed the order of calculation. On downscale we at first cut of date part, than cut of unused unit precision. Tests also modified to align with this behavior.
omniscidb/QueryEngine/CastIR.cpp
Outdated
const auto scale = | ||
hdk::ir::unitsPerSecond(target_unit) / hdk::ir::unitsPerSecond(operand_unit); | ||
|
||
// codegenCastBetweenIntTypesOverflowChecks(ts_lv, operand_type, target_type, scale); |
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.
Remove comment?
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.
done
omniscidb/QueryEngine/CastIR.cpp
Outdated
const auto scale = | ||
hdk::ir::unitsPerSecond(operand_unit) / hdk::ir::unitsPerSecond(target_unit); | ||
|
||
// codegenCastBetweenIntTypesOverflowChecks(ts_lv, operand_type, target_type, scale); |
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.
Remove comment?
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.
done
omniscidb/ResultSet/ResultSet.cpp
Outdated
oss << getStrTimeFromSeconds(boost::get<int64_t>(current_scalar)); | ||
oss << getStrTStamp(boost::get<int64_t>(current_scalar), | ||
col_type->as<hdk::ir::TimeType>()->unit()) | ||
<< " scalar: " << current_scalar; |
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 function is used to print result sets in PyHDK, scalar values would be really unexpected there.
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.
getStrTStamp
print all time types as timestamp, it looks like a debug function. If it's for end user we should rewrite it.
omniscidb/Tests/QueryBuilderTest.cpp
Outdated
@@ -519,6 +562,180 @@ TEST_F(QueryBuilderTest, Arithmetics) { | |||
compare_res_data(res, std::vector<int64_t>({0, NULL_BIGINT})); | |||
} | |||
|
|||
TEST_F(QueryBuilderTest, TmstmpToTime) { |
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.
Please use unabbreviated TimestampToTime
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.
done
0ae014d
to
d14f208
Compare
Adding timestamp to time conversion. The units is also taken into account. Resolves: #318 Signed-off-by: Dmitrii Makarenko <[email protected]>
d14f208
to
48d8b98
Compare
Adding timestamp to time conversion. The units is also taken into account.
Resolves: #318
Signed-off-by: Dmitrii Makarenko [email protected]