wgtmac commented on code in PR #156:
URL: https://github.com/apache/iceberg-cpp/pull/156#discussion_r2258733759
##########
src/iceberg/expression/literal.cc:
##########
@@ -126,12 +126,23 @@ Literal::Literal(Value value,
std::shared_ptr<PrimitiveType> type)
: value_(std::move(value)), type_(std::move(type)) {}
// Factory methods
+
Review Comment:
```suggestion
```
##########
src/iceberg/expression/literal.cc:
##########
@@ -126,12 +126,23 @@ Literal::Literal(Value value,
std::shared_ptr<PrimitiveType> type)
: value_(std::move(value)), type_(std::move(type)) {}
// Factory methods
+
Literal Literal::Boolean(bool value) { return {Value{value},
iceberg::boolean()}; }
Literal Literal::Int(int32_t value) { return {Value{value}, iceberg::int32()};
}
+Literal Literal::Date(int32_t value) { return {Value{value}, iceberg::date()};
}
Review Comment:
nit: we don't need `iceberg::` namespace prefix.
##########
src/iceberg/transform_function.h:
##########
@@ -97,11 +97,11 @@ class YearTransform : public TransformFunction {
/// \param source_type Must be a timestamp type.
explicit YearTransform(std::shared_ptr<Type> const& source_type);
- /// \brief Extracts the year from each timestamp in the input array.
- Result<ArrowArray> Transform(const ArrowArray& input) override;
+ /// \brief Extract a date or timestamp year, as years from 1970.
Review Comment:
Also uses `Extracts` to be consistent. Same for below.
##########
src/iceberg/util/truncate_utils.h:
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <utility>
+
+#include "iceberg/iceberg_export.h"
+
+namespace iceberg {
+
+ICEBERG_EXPORT class TruncateUtils {
+ public:
+ /// \brief Truncate a UTF-8 string to a specified number of code points.
+ ///
+ /// \param source The input string to truncate.
+ /// \param L The maximum number of code points allowed in the output string.
+ /// \return A valid UTF-8 string truncated to L code points.
+ /// If the input string is already valid and has fewer than L code points,
it is
+ /// returned unchanged.
+ static std::string TruncateUTF8(std::string&& source, size_t L) {
+ size_t code_point_count = 0;
+ size_t safe_point = 0;
+
+ for (size_t i = 0; i < source.size(); ++i) {
+ // Start of a new UTF-8 code point
+ if ((source[i] & 0xC0) != 0x80) {
+ code_point_count++;
+ if (code_point_count > static_cast<size_t>(L)) {
+ safe_point = i;
+ break;
+ }
+ }
+ }
+
+ if (safe_point != 0) {
+ // Resize the string to the safe point
+ source.resize(safe_point);
+ }
+
+ return std::move(source);
+ }
+
+ /// \brief Truncate an integer v, either int32_t or int64_t, to v - (v % W).
+ ///
+ /// The remainder, v % W, must be positive. For languages where % can
produce negative
+ /// values, the correct truncate function is: v - (((v % W) + W) % W)
+ template <typename T>
Review Comment:
nit: use concepts to limit T to int32_t and int64_t
##########
src/iceberg/transform_function.h:
##########
@@ -116,11 +116,11 @@ class MonthTransform : public TransformFunction {
/// \param source_type Must be a timestamp type.
explicit MonthTransform(std::shared_ptr<Type> const& source_type);
- /// \brief Extracts the month (1-12) from each timestamp in the input array.
- Result<ArrowArray> Transform(const ArrowArray& input) override;
+ /// \brief Extract a date or timestamp month, as months from 1970-01-01.
Review Comment:
ditto
##########
src/iceberg/transform_function.h:
##########
@@ -97,11 +97,11 @@ class YearTransform : public TransformFunction {
/// \param source_type Must be a timestamp type.
explicit YearTransform(std::shared_ptr<Type> const& source_type);
- /// \brief Extracts the year from each timestamp in the input array.
- Result<ArrowArray> Transform(const ArrowArray& input) override;
+ /// \brief Extract a date or timestamp year, as years from 1970.
Review Comment:
The comment is incorrect.
--
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]