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


##########
src/iceberg/transform_function.cc:
##########
@@ -124,6 +224,34 @@ Result<ArrowArray> YearTransform::Transform(const 
ArrowArray& input) {
   return NotImplemented("YearTransform::Transform");
 }
 
+Result<std::optional<Literal>> YearTransform::Transform(const Literal& 
literal) {
+  assert(literal.type() == source_type());
+  if (literal.IsBelowMin() || literal.IsAboveMax()) {
+    return InvalidArgument(
+        "Cannot apply year transform to literal with value {} of type {}",
+        literal.ToString(), source_type()->ToString());
+  }
+
+  using namespace std::chrono;
+  switch (source_type()->type_id()) {
+    case TypeId::kDate: {
+      auto value = std::get<int32_t>(literal.value());
+      auto epoch = sys_days(year{1970} / January / 1);
+      auto ymd = year_month_day(epoch + days{value});
+      return Literal::Int(static_cast<int32_t>(ymd.year()));
+    }
+    case TypeId::kTimestamp:
+    case TypeId::kTimestampTz: {
+      auto value = std::get<int64_t>(literal.value());
+      // Convert milliseconds-since-epoch into a `year_month_day` object

Review Comment:
   You are right, fixed.



-- 
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