mapleFU commented on code in PR #177: URL: https://github.com/apache/iceberg-cpp/pull/177#discussion_r2281123528
########## src/iceberg/expression/expressions.cc: ########## @@ -0,0 +1,344 @@ +/* + * 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. + */ + +#include "iceberg/expression/expressions.h" + +#include "iceberg/exception.h" +#include "iceberg/transform.h" +#include "iceberg/type.h" + +namespace iceberg { + +// Logical operations + +std::shared_ptr<Expression> Expressions::And(std::shared_ptr<Expression> left, + std::shared_ptr<Expression> right) { + if (left->op() == Expression::Operation::kFalse || + right->op() == Expression::Operation::kFalse) { + return AlwaysFalse(); + } + + if (left->op() == Expression::Operation::kTrue) { + return right; + } + + if (right->op() == Expression::Operation::kTrue) { + return left; + } + + return std::make_shared<::iceberg::And>(left, right); Review Comment: ```suggestion return std::make_shared<::iceberg::And>(std::move(left), std::move(right)); ``` ########## src/iceberg/expression/predicate.h: ########## @@ -0,0 +1,192 @@ +/* + * 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/predicate.h +/// Predicate interface for boolean expressions that test terms. + +#include <memory> +#include <string> +#include <vector> + +#include "iceberg/expression/expression.h" +#include "iceberg/expression/term.h" + +namespace iceberg { + +/// \brief A predicate is a boolean expression that tests a term against some criteria. +/// +/// \tparam TermType The type of the term being tested +template <typename TermType> +class ICEBERG_EXPORT Predicate : public Expression { + public: + /// \brief Create a predicate with an operation and term. + /// + /// \param op The operation this predicate performs + /// \param term The term this predicate tests + Predicate(Expression::Operation op, std::shared_ptr<TermType> term); + + ~Predicate() override = default; + + Expression::Operation op() const override { return operation_; } + + /// \brief Returns the term this predicate tests. + const std::shared_ptr<TermType>& term() const { return term_; } + + protected: + Expression::Operation operation_; + std::shared_ptr<TermType> term_; +}; + +/// \brief Unbound predicates contain unbound terms and must be bound to a concrete schema +/// before they can be evaluated. +/// +/// \tparam B The bound type this predicate produces when binding is successful +template <typename B> +class ICEBERG_EXPORT UnboundPredicate : public Predicate<UnboundTerm<B>>, Review Comment: Waht can be `B` be here? Generally `UnboundTerm<BoundReference>`? -- 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]
