Skip to content

Commit 483fa0f

Browse files
committed
review
1 parent c6b8cc8 commit 483fa0f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/iceberg/expression/literal.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "iceberg/expression/literal.h"
2121

22+
#include <chrono>
2223
#include <cmath>
2324
#include <concepts>
2425

@@ -28,10 +29,10 @@ namespace iceberg {
2829

2930
namespace {
3031

31-
constexpr int64_t kMicrosPerDay = 86400000000LL; // 24 * 60 * 60 * 1000 * 1000
32-
33-
int32_t MicrosToDays(int64_t micros) {
34-
return static_cast<int32_t>(std::floor(static_cast<double>(micros) / kMicrosPerDay));
32+
int32_t MicrosToDays(int64_t micros_since_epoch) {
33+
std::chrono::microseconds micros(micros_since_epoch);
34+
auto days_duration = std::chrono::floor<std::chrono::days>(micros);
35+
return static_cast<int32_t>(days_duration.count());
3536
}
3637

3738
} // namespace
@@ -178,7 +179,7 @@ Result<Literal> LiteralCaster::CastFromDouble(
178179
if (double_val > static_cast<double>(std::numeric_limits<float>::max())) {
179180
return AboveMaxLiteral(target_type);
180181
}
181-
if (double_val < -static_cast<double>(std::numeric_limits<float>::max())) {
182+
if (double_val < static_cast<double>(std::numeric_limits<float>::lowest())) {
182183
return BelowMinLiteral(target_type);
183184
}
184185
return Literal::Float(static_cast<float>(double_val));
@@ -488,7 +489,7 @@ std::string Literal::ToString() const {
488489
}
489490
case TypeId::kDecimal:
490491
case TypeId::kUuid: {
491-
throw IcebergError("Not implemented: ToString for " + type_->ToString());
492+
throw NotImplemented("kDecimal and kUuid are not implemented yet");
492493
}
493494
default: {
494495
throw IcebergError("Unknown type: " + type_->ToString());

0 commit comments

Comments
 (0)