wgtmac commented on code in PR #177: URL: https://github.com/apache/iceberg-cpp/pull/177#discussion_r2296499288
########## src/iceberg/expression/expressions.cc: ########## @@ -0,0 +1,356 @@ +/* + * 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>(std::move(left), std::move(right)); +} + +std::shared_ptr<Expression> Expressions::Or(std::shared_ptr<Expression> left, + std::shared_ptr<Expression> right) { + if (left->op() == Expression::Operation::kTrue || + right->op() == Expression::Operation::kTrue) { + return AlwaysTrue(); + } + + if (left->op() == Expression::Operation::kFalse) { + return right; + } + + if (right->op() == Expression::Operation::kFalse) { + return left; + } + + return std::make_shared<::iceberg::Or>(std::move(left), std::move(right)); +} + +// Transform functions Review Comment: These are different concepts and abstractions: - `Transform`: the simplest form of a transform function with a name and an optional parameter. - `TransformFunction`: A bound version of `Transform` with concrete source and result types. It is like a compute kernel function to transform values. - `UnboundTransform`: `Transform` with a name reference. - 'BoundTransform': A bound version of `UnboundTransform` with bound reference. In short, `Transform` and `TransformFunction` are abstractions for transform function metadata and kernels, and should have nothing to do with the expression/predicate. `UnboundTransform` and 'BoundTransform' are expressions and are built on top of `Transform` and `TransformFunction`. It is an anti-pattern to create expression from non-expression class. -- 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]
