Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions be/src/vec/functions/function_timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "vec/columns/column_vector.h"
#include "vec/columns/columns_number.h"
#include "vec/common/assert_cast.h"
#include "vec/common/int_exp.h"
#include "vec/common/pod_array_fwd.h"
#include "vec/common/string_ref.h"
#include "vec/core/block.h"
Expand Down Expand Up @@ -674,11 +675,10 @@ struct UnixTimeStampDateImpl {
DCHECK(valid);

auto [sec, ms] = UnixTimeStampImpl::trim_timestamp(timestamp);
auto ms_str = std::to_string(ms).substr(0, scale);
if (ms_str.empty()) {
ms_str = "0";
}
col_result_data[i] = Decimal64::from_int_frac(sec, std::stoll(ms_str), scale).value;
col_result_data[i] =
Decimal64::from_int_frac(
sec, ms / static_cast<int64_t>(std::pow(10, 6 - scale)), scale)
.value;
}
block.replace_by_position(result, std::move(col_result));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ private static String getTimestamp(LocalDateTime dateTime) {
if (duration.getNano() == 0) {
return String.valueOf(duration.getSeconds());
} else {
return duration.getSeconds() + "." + (duration.getNano() / 1000);
return duration.getSeconds() + "." + String.format("%06d", duration.getNano() / 1000);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ February
-- !sql_ustamp9 --
0

-- !sql_ustamp10 --
1447381219.00001

-- !sql_ustamp11 --
1447381219.012000

-- !sql --
0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,13 @@ suite("test_date_function") {
qt_sql_ustamp7 """ select unix_timestamp(cast('2007-11-30 10:30:19.123456' as datetimev2(4))) """
qt_sql_ustamp8 """ SELECT UNIX_TIMESTAMP('9999-12-30 23:59:59.999'); """
qt_sql_ustamp9 """ SELECT UNIX_TIMESTAMP('9999-12-30 23:59:59'); """
testFoldConst("SELECT UNIX_TIMESTAMP('9999-12-30 23:59:59.999');")
testFoldConst("SELECT UNIX_TIMESTAMP('9999-12-30 23:59:59');")
qt_sql_ustamp10 """ select UNIX_TIMESTAMP('2015-11-13 10:20:19.000010'); """
qt_sql_ustamp11 """ select UNIX_TIMESTAMP(cast('2015-11-13 10:20:19.012' as datetime(6))); """
check_fold_consistency(" UNIX_TIMESTAMP('9999-12-30 23:59:59.999')")
check_fold_consistency(" UNIX_TIMESTAMP('9999-12-30 23:59:59')")
check_fold_consistency(" UNIX_TIMESTAMP('2015-11-13 10:20:19.000010')")
check_fold_consistency(" UNIX_TIMESTAMP(cast('2015-11-13 10:20:19.000' as datetime(6)))")
check_fold_consistency(" UNIX_TIMESTAMP(cast('2015-11-13 10:20:19.012' as datetime(6)))")

// UTC_TIMESTAMP
def utc_timestamp_str = sql """ select utc_timestamp(),utc_timestamp() + 1 """
Expand Down
Loading