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


##########
src/iceberg/transform.h:
##########
@@ -56,14 +56,45 @@ enum class TransformType {
   kVoid,
 };
 
+/// \brief Get the relative transform name
+constexpr std::string_view ToString(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";
+    default:
+      return "invalid";
+  }
+}
+
 /// \brief A transform function used for partitioning.
 class ICEBERG_EXPORT TransformFunction : public util::Formattable {
  public:
-  explicit TransformFunction(TransformType type);
+  explicit TransformFunction(TransformType transform_type,
+                             std::shared_ptr<Type> source_type);
   /// \brief Transform an input array to a new array
   virtual expected<ArrowArray, Error> Transform(const ArrowArray& data) = 0;
   /// \brief Get the transform type
-  virtual TransformType transform_type() const;
+  TransformType transform_type() const;
+  /// \brief Get the source type of transform function
+  std::shared_ptr<Type> source_type() const;
+  /// \brief Get the result type of transform function
+  virtual expected<std::shared_ptr<Type>, Error> result_type() const = 0;

Review Comment:
   Reasonable, I will modify it. Thank you.



##########
src/iceberg/transform.h:
##########
@@ -56,14 +56,45 @@ enum class TransformType {
   kVoid,
 };
 
+/// \brief Get the relative transform name
+constexpr std::string_view ToString(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";
+    default:
+      return "invalid";
+  }
+}
+
 /// \brief A transform function used for partitioning.
 class ICEBERG_EXPORT TransformFunction : public util::Formattable {
  public:
-  explicit TransformFunction(TransformType type);
+  explicit TransformFunction(TransformType transform_type,
+                             std::shared_ptr<Type> source_type);
   /// \brief Transform an input array to a new array
   virtual expected<ArrowArray, Error> Transform(const ArrowArray& data) = 0;
   /// \brief Get the transform type
-  virtual TransformType transform_type() const;
+  TransformType transform_type() const;
+  /// \brief Get the source type of transform function
+  std::shared_ptr<Type> source_type() const;

Review Comment:
   Reasonable, I will modify it. Thank you.



##########
src/iceberg/transform/transform_spec.h:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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
+
+/// \file iceberg/transform/transform_spec.h
+
+#include <memory>
+#include <optional>
+
+#include "iceberg/arrow_c_data.h"
+#include "iceberg/type_fwd.h"
+
+namespace iceberg {
+/// \brief A specification for creating a TransformFunction instance.
+///
+/// This struct encapsulates all necessary information to describe a transform,
+/// including the type of the transform and any optional parameters it may 
require.
+/// It is used by the TransformFactory to instantiate the corresponding 
transform
+/// implementation.
+///
+/// For example:
+/// - A Bucket transform with 10 buckets: TransformType::kBucket, params = [10]
+/// - An Identity transform: TransformType::kIdentity, no parameters
+struct TransformSpec {
+  /// \brief The type of the transform (e.g., kBucket, kTruncate, kIdentity, 
etc.)
+  TransformType transform_type;
+
+  /// \brief Optional parameter values passed to the transform, represented as 
an
+  /// ArrowArray.
+  ///
+  /// For transforms that require parameters (e.g., Bucket(N)), this holds the 
arguments
+  /// as a primitive ArrowArray (e.g., INT32 for num_buckets or width).
+  /// If the transform does not require parameters, this will be std::nullopt.
+  std::optional<ArrowArray> params_opt;

Review Comment:
   1. Using ArrowArray is necessary, as different Transforms may use different 
types and numbers of parameters, which should be needed within the Transform or 
when creating an instance of the Transform.
   
   2. TransformSpec is used to describe a transform, which can be derived from 
JSON and is also convenient for future extensions. 
   
   @lidavidm 



##########
src/iceberg/arrow_c_data.h:
##########
@@ -73,4 +73,44 @@ struct ArrowArray {
 
 #endif  // ARROW_C_DATA_INTERFACE
 
+#ifndef ARROW_C_STREAM_INTERFACE
+#  define ARROW_C_STREAM_INTERFACE
+
+struct ArrowArrayStream {

Review Comment:
   I have the impression that I relied on it when testing and copying 
ArrowArray, and I would delete it



##########
src/iceberg/transform.h:
##########
@@ -56,14 +56,45 @@ enum class TransformType {
   kVoid,
 };
 
+/// \brief Get the relative transform name
+constexpr std::string_view ToString(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";
+    default:
+      return "invalid";
+  }
+}
+
 /// \brief A transform function used for partitioning.
 class ICEBERG_EXPORT TransformFunction : public util::Formattable {
  public:
-  explicit TransformFunction(TransformType type);
+  explicit TransformFunction(TransformType transform_type,

Review Comment:
   Reasonable, I will modify it. Thank you.



##########
src/iceberg/transform/transform_spec.h:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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
+
+/// \file iceberg/transform/transform_spec.h
+
+#include <memory>
+#include <optional>
+
+#include "iceberg/arrow_c_data.h"
+#include "iceberg/type_fwd.h"
+
+namespace iceberg {
+/// \brief A specification for creating a TransformFunction instance.
+///
+/// This struct encapsulates all necessary information to describe a transform,
+/// including the type of the transform and any optional parameters it may 
require.
+/// It is used by the TransformFactory to instantiate the corresponding 
transform
+/// implementation.
+///
+/// For example:
+/// - A Bucket transform with 10 buckets: TransformType::kBucket, params = [10]
+/// - An Identity transform: TransformType::kIdentity, no parameters
+struct TransformSpec {
+  /// \brief The type of the transform (e.g., kBucket, kTruncate, kIdentity, 
etc.)
+  TransformType transform_type;
+
+  /// \brief Optional parameter values passed to the transform, represented as 
an
+  /// ArrowArray.
+  ///
+  /// For transforms that require parameters (e.g., Bucket(N)), this holds the 
arguments
+  /// as a primitive ArrowArray (e.g., INT32 for num_buckets or width).
+  /// If the transform does not require parameters, this will be std::nullopt.
+  std::optional<ArrowArray> params_opt;

Review Comment:
   The main difference lies in the fact that your approach sub-classes 
uniformly provide a lambda function. I am concerned that the function might 
become too complex, as the same Transform type may need to implement 
corresponding logic based on different source types. However, iceberg-java has 
a similar approach; it generates specific function objects by binding the 
source type.  @wgtmac 



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