zhjwpku commented on code in PR #653:
URL: https://github.com/apache/iceberg-cpp/pull/653#discussion_r3287947086


##########
src/iceberg/expression/literal.cc:
##########
@@ -250,14 +263,27 @@ Result<Literal> LiteralCaster::CastFromString(
 Result<Literal> LiteralCaster::CastFromTimestamp(
     const Literal& literal, const std::shared_ptr<PrimitiveType>& target_type) 
{
   auto timestamp_val = std::get<int64_t>(literal.value_);
+  const auto& source_timestamp =
+      internal::checked_cast<const TimestampBase&>(*literal.type());
+  const bool source_is_nanos = source_timestamp.time_unit() == 
TimeUnit::kNanosecond;
 
   switch (target_type->type_id()) {
     case TypeId::kDate: {
       ICEBERG_ASSIGN_OR_RAISE(auto days, TemporalUtils::ExtractDay(literal));
       return Literal::Date(std::get<int32_t>(days.value()));
     }
+    case TypeId::kTimestamp:
+      return source_is_nanos ? Literal::Timestamp(timestamp_val / 1000)
+                             : Literal::Timestamp(timestamp_val);
     case TypeId::kTimestampTz:
-      return Literal::TimestampTz(timestamp_val);
+      return source_is_nanos ? Literal::TimestampTz(timestamp_val / 1000)
+                             : Literal::TimestampTz(timestamp_val);
+    case TypeId::kTimestampNs:
+      return source_is_nanos ? Literal::TimestampNs(timestamp_val)
+                             : Literal::TimestampNs(timestamp_val * 1000);
+    case TypeId::kTimestampTzNs:

Review Comment:
   I checked the logic in java impl, ISTM zoned vs non-zoned is not 
distinguished at the literal cast level, in java zoned vs non-zoned share the 
same TypeID.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to