| 136 | /// argument. If no arguments were modified the unmodified Expression* will be nullptr. |
| 137 | template <typename PreVisit, typename PostVisitCall> |
| 138 | Result<Expression> ModifyExpression(Expression expr, const PreVisit& pre, |
| 139 | const PostVisitCall& post_call) { |
| 140 | ARROW_ASSIGN_OR_RAISE(expr, Result<Expression>(pre(std::move(expr)))); |
| 141 | |
| 142 | auto call = expr.call(); |
| 143 | if (!call) return expr; |
| 144 | |
| 145 | bool at_least_one_modified = false; |
| 146 | std::vector<Expression> modified_arguments; |
| 147 | |
| 148 | for (size_t i = 0; i < call->arguments.size(); ++i) { |
| 149 | ARROW_ASSIGN_OR_RAISE(auto modified_argument, |
| 150 | ModifyExpression(call->arguments[i], pre, post_call)); |
| 151 | |
| 152 | if (Expression::Identical(modified_argument, call->arguments[i])) { |
| 153 | continue; |
| 154 | } |
| 155 | |
| 156 | if (!at_least_one_modified) { |
| 157 | modified_arguments = call->arguments; |
| 158 | at_least_one_modified = true; |
| 159 | } |
| 160 | |
| 161 | modified_arguments[i] = std::move(modified_argument); |
| 162 | } |
| 163 | |
| 164 | if (at_least_one_modified) { |
| 165 | // reconstruct the call expression with the modified arguments |
| 166 | auto modified_call = *call; |
| 167 | modified_call.arguments = std::move(modified_arguments); |
| 168 | return post_call(Expression(std::move(modified_call)), &expr); |
| 169 | } |
| 170 | |
| 171 | return post_call(std::move(expr), NULLPTR); |
| 172 | } |
| 173 | |
| 174 | // Helper class to calculate the modified number of rows to process using SIMD. |
| 175 | // |
no test coverage detected