wgtmac commented on code in PR #585:
URL: https://github.com/apache/iceberg-cpp/pull/585#discussion_r2923434974


##########
src/iceberg/util/truncate_util.cc:
##########
@@ -29,6 +29,93 @@
 namespace iceberg {
 
 namespace {
+constexpr uint32_t kUtf8MaxCodePoint = 0x10FFFF;
+constexpr uint32_t kUtf8MinSurrogate = 0xD800;
+constexpr uint32_t kUtf8MaxSurrogate = 0xDFFF;
+
+bool DecodeUtf8CodePoint(std::string_view source, uint32_t& code_point) {

Review Comment:
   ```suggestion
   std::optional<uint32_t> DecodeUtf8CodePoint(std::string_view source) {
   ```
   
   nit: this might look simpler



##########
src/iceberg/util/truncate_util.cc:
##########
@@ -72,8 +159,85 @@ Literal TruncateLiteralImpl<TypeId::kBinary>(const Literal& 
literal, int32_t wid
   return Literal::Binary(std::vector<uint8_t>(data.begin(), data.begin() + 
width));
 }
 
+template <TypeId type_id>
+Result<Literal> TruncateLiteralMaxImpl(const Literal& literal, int32_t width) {
+  std::unreachable();

Review Comment:
   nit: let's return a `NotSupported` error instead of an exception since you 
already return Result here?



##########
src/iceberg/util/truncate_util.cc:
##########
@@ -72,8 +159,85 @@ Literal TruncateLiteralImpl<TypeId::kBinary>(const Literal& 
literal, int32_t wid
   return Literal::Binary(std::vector<uint8_t>(data.begin(), data.begin() + 
width));
 }
 
+template <TypeId type_id>
+Result<Literal> TruncateLiteralMaxImpl(const Literal& literal, int32_t width) {
+  std::unreachable();
+}
+
+template <>
+Result<Literal> TruncateLiteralMaxImpl<TypeId::kString>(const Literal& literal,
+                                                        int32_t width) {
+  const auto& str = std::get<std::string>(literal.value());
+  ICEBERG_ASSIGN_OR_RAISE(std::string truncated,
+                          TruncateUtils::TruncateUTF8Max(str, width));
+  if (truncated == str) {
+    return literal;
+  }

Review Comment:
   ```suggestion
   ```
   
   Should we remove this block? It does not run faster than line 176.



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