zhjwpku commented on code in PR #491:
URL: https://github.com/apache/iceberg-cpp/pull/491#discussion_r2678503021
##########
src/iceberg/expression/binder.cc:
##########
@@ -113,4 +115,54 @@ Result<bool> IsBoundVisitor::Aggregate(
return false;
}
+Result<std::unordered_set<int32_t>> ReferenceVisitor::GetReferencedFieldIds(
+ const std::shared_ptr<Expression>& expr) {
+ ICEBERG_PRECHECK(expr != nullptr, "Expression cannot be null");
+ ReferenceVisitor visitor;
+ return Visit<FieldIdsSetRef, ReferenceVisitor>(expr, visitor);
+}
+
+Result<FieldIdsSetRef> ReferenceVisitor::AlwaysTrue() { return
referenced_field_ids_; }
+
+Result<FieldIdsSetRef> ReferenceVisitor::AlwaysFalse() { return
referenced_field_ids_; }
+
+Result<FieldIdsSetRef> ReferenceVisitor::Not(
+ [[maybe_unused]] const FieldIdsSetRef& child_result) {
+ return referenced_field_ids_;
+}
+
+Result<FieldIdsSetRef> ReferenceVisitor::And(
+ [[maybe_unused]] const FieldIdsSetRef& left_result,
+ [[maybe_unused]] const FieldIdsSetRef& right_result) {
+ return referenced_field_ids_;
+}
+
+Result<FieldIdsSetRef> ReferenceVisitor::Or(
+ [[maybe_unused]] const FieldIdsSetRef& left_result,
+ [[maybe_unused]] const FieldIdsSetRef& right_result) {
+ return referenced_field_ids_;
+}
+
+Result<FieldIdsSetRef> ReferenceVisitor::Predicate(
+ const std::shared_ptr<BoundPredicate>& pred) {
+ referenced_field_ids_.insert(pred->reference()->field_id());
+ return referenced_field_ids_;
+}
+
+Result<FieldIdsSetRef> ReferenceVisitor::Predicate(
+ [[maybe_unused]] const std::shared_ptr<UnboundPredicate>& pred) {
+ return referenced_field_ids_;
Review Comment:
Should we error on unbound predicates and unbound aggregates? ISTM that an
expression should be either fully bound or fully unbound, and that mixing the
two is not possible, and visiting an unbound expression would be meaningless.
--
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]