zhjwpku commented on code in PR #156:
URL: https://github.com/apache/iceberg-cpp/pull/156#discussion_r2251855818
##########
src/iceberg/transform_function.cc:
##########
@@ -91,6 +140,46 @@ Result<ArrowArray> TruncateTransform::Transform(const
ArrowArray& input) {
return NotImplemented("TruncateTransform::Transform");
}
+Result<std::optional<Literal>> TruncateTransform::Transform(const Literal&
literal) {
+ assert(literal.type() == source_type());
+ if (literal.IsBelowMin() || literal.IsAboveMax()) {
+ return InvalidArgument(
+ "Cannot apply truncate transform to literal with value {} of type {}",
+ literal.ToString(), source_type()->ToString());
+ }
+
+ switch (source_type()->type_id()) {
+ case TypeId::kInt: {
+ auto value = std::get<int32_t>(literal.value());
+ return Literal::Int(value % width_);
+ }
+ case TypeId::kLong: {
+ auto value = std::get<int64_t>(literal.value());
+ return Literal::Long(value % width_);
+ }
+ case TypeId::kDecimal: {
+ // TODO(zhjwpku): Handle decimal truncation logic here
+ return NotImplemented("Truncate for Decimal is not implemented yet");
+ }
+ case TypeId::kString: {
+ auto value = std::get<std::string>(literal.value());
+ if (value.size() > static_cast<size_t>(width_)) {
+ value.resize(width_);
Review Comment:
Good catch, I didn't realize that before, please check again if I'm doing it
right now.
--
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]