lidavidm commented on code in PR #61:
URL: https://github.com/apache/iceberg-cpp/pull/61#discussion_r2038705942


##########
src/iceberg/transform.h:
##########
@@ -56,16 +57,98 @@ enum class TransformType {
   kVoid,
 };
 
+/// \brief Get the relative transform name
+constexpr std::string_view TransformTypeToString(TransformType type) {
+  switch (type) {
+    case TransformType::kUnknown:
+      return "unknown";
+    case TransformType::kIdentity:
+      return "identity";
+    case TransformType::kBucket:
+      return "bucket";
+    case TransformType::kTruncate:
+      return "truncate";
+    case TransformType::kYear:
+      return "year";
+    case TransformType::kMonth:
+      return "month";
+    case TransformType::kDay:
+      return "day";
+    case TransformType::kHour:
+      return "hour";
+    case TransformType::kVoid:
+      return "void";
+  }
+}
+
+/// \brief Represents a transform used in partitioning or sorting in Iceberg.
+///
+/// This class supports binding to a source type and instantiating the 
corresponding
+/// TransformFunction, as well as serialization-friendly introspection.
+class ICEBERG_EXPORT Transform : public util::Formattable {
+ public:
+  /// \brief Returns a shared singleton instance of the Identity transform.
+  ///
+  /// This transform leaves values unchanged and is commonly used for direct 
partitioning.
+  /// \return A shared pointer to the Identity transform.
+  static std::shared_ptr<Transform> Identity();
+
+  /// \brief Constructs a Transform of the specified type (for non-parametric 
types).
+  /// \param transform_type The transform type (e.g., identity, year, day).
+  explicit Transform(TransformType transform_type);
+
+  /// \brief Constructs a parameterized Transform (e.g., bucket(16), 
truncate(4)).
+  /// \param transform_type The transform type.
+  /// \param param The integer parameter associated with the transform.
+  Transform(TransformType transform_type, int32_t param);
+
+  /// \brief Returns the transform type.
+  TransformType transform_type() const;
+
+  /// \brief Binds this transform to a source type, returning a typed 
TransformFunction.
+  ///
+  /// This creates a concrete transform implementation based on the transform 
type and
+  /// parameter.
+  /// \param source_type The source column type to bind to.
+  /// \return A TransformFunction instance wrapped in `expected`, or an error 
on failure.
+  expected<std::unique_ptr<TransformFunction>, Error> Bind(
+      const std::shared_ptr<Type>& source_type) const;
+
+  /// \brief Returns a string representation of this transform (e.g., 
"bucket[16]").
+  std::string ToString() const override;
+
+  /// \brief Equality comparison.
+  friend bool operator==(const Transform& lhs, const Transform& rhs) {
+    return lhs.Equals(rhs);
+  }
+
+  /// \brief Inequality comparison.
+  friend bool operator!=(const Transform& lhs, const Transform& rhs) {
+    return !(lhs == rhs);
+  }
+
+ private:
+  /// \brief Checks equality with another Transform instance.
+  [[nodiscard]] virtual bool Equals(const Transform& other) const;
+
+  TransformType transform_type_;
+  ///< Optional parameter (e.g., num_buckets, width)
+  std::variant<std::monostate, int32_t> param_;
+};
+
 /// \brief A transform function used for partitioning.
-class ICEBERG_EXPORT TransformFunction : public util::Formattable {

Review Comment:
   Sounds good to me.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to