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


##########
src/iceberg/expression/term.h:
##########
@@ -0,0 +1,267 @@
+/*
+ * 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/expression/term.h
+/// Term interface for Iceberg expressions - represents values that can be 
evaluated.
+
+#include <memory>
+#include <string>
+#include <string_view>
+
+#include "iceberg/arrow_c_data.h"
+#include "iceberg/expression/literal.h"
+#include "iceberg/type_fwd.h"
+#include "iceberg/util/formattable.h"
+
+namespace iceberg {
+
+// TODO(gangwu): add a struct-like interface to wrap a row of data from 
ArrowArray or
+// structs like ManifestFile and ManifestEntry to facilitate generailization 
of the
+// evaluation of expressions on top of different data structures.
+class StructLike;
+
+/// \brief A term is an expression node that produces a typed value when 
evaluated.
+class ICEBERG_EXPORT Term : public util::Formattable {
+ public:
+  enum class Kind : uint8_t { kReference = 0, kTransform, kExtract };
+
+  /// \brief Returns the kind of this term.
+  virtual Kind kind() const = 0;
+};
+
+/// \brief Interface for unbound expressions that need schema binding.
+///
+/// Unbound expressions contain string-based references that must be resolved
+/// against a concrete schema to produce bound expressions that can be 
evaluated.
+///
+/// \tparam B The bound type this term produces when binding is successful
+template <typename B>
+class ICEBERG_EXPORT Unbound {
+ public:
+  /// \brief Bind this expression to a concrete schema.
+  ///
+  /// \param schema The schema to bind against
+  /// \param case_sensitive Whether field name matching should be case 
sensitive
+  /// \return A bound expression or an error if binding fails
+  virtual Result<std::shared_ptr<B>> Bind(const Schema& schema,
+                                          bool case_sensitive) const = 0;
+
+  /// \brief Overloaded Bind method that uses case-sensitive matching by 
default.
+  Result<std::shared_ptr<B>> Bind(const Schema& schema) const;
+
+  /// \brief Returns the underlying named reference for this unbound term.
+  virtual std::shared_ptr<class NamedReference> reference() = 0;
+};
+
+/// \brief Interface for bound expressions that can be evaluated.
+///
+/// Bound expressions have been resolved against a concrete schema and contain
+/// all necessary information to evaluate against data structures.
+class ICEBERG_EXPORT Bound {
+ public:
+  virtual ~Bound();
+
+  /// \brief Evaluate this expression against a row-based data.
+  virtual Result<Literal::Value> Evaluate(const StructLike& data) const = 0;
+
+  /// \brief Evaluate this expression against an Arrow array.
+  virtual Result<std::vector<Literal::Value>> Evaluate(const ArrowArray& data) 
const = 0;
+
+  /// \brief Returns the underlying bound reference for this term.
+  virtual std::shared_ptr<class BoundReference> reference() = 0;
+};
+
+/// \brief Base class for unbound terms.
+///
+/// \tparam B The bound type this term produces when binding is successful.
+template <typename B>
+class ICEBERG_EXPORT UnboundTerm : public Unbound<B>, public Term {
+ public:
+  using BoundType = B;
+};
+
+/// \brief Base class for bound terms.
+class ICEBERG_EXPORT BoundTerm : public Bound, public Term {
+ public:
+  ~BoundTerm() override;
+
+  /// \brief Returns the type produced by this term.
+  virtual std::shared_ptr<Type> type() const = 0;

Review Comment:
   No, we can't due to following code where Transform::ResultType() cannot 
return const ref.
   
   ```cpp
   std::shared_ptr<Type> BoundTransform::type() const {
     return transform_func_->ResultType();
   }
   ```



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