Skip to content

Commit 5f65bce

Browse files
committed
ARROW-17287: Working around duplicate symbol errors from expression_internal.h
1 parent f281aab commit 5f65bce

4 files changed

Lines changed: 48 additions & 49 deletions

File tree

cpp/src/arrow/compute/exec/expression.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,53 @@ ARROW_EXPORT Expression or_(Expression lhs, Expression rhs);
279279
ARROW_EXPORT Expression or_(const std::vector<Expression>&);
280280
ARROW_EXPORT Expression not_(Expression operand);
281281

282+
/// Modify an Expression with pre-order and post-order visitation.
283+
/// `pre` will be invoked on each Expression. `pre` will visit Calls before their
284+
/// arguments, `post_call` will visit Calls (and no other Expressions) after their
285+
/// arguments. Visitors should return the Identical expression to indicate no change; this
286+
/// will prevent unnecessary construction in the common case where a modification is not
287+
/// possible/necessary/...
288+
///
289+
/// If an argument was modified, `post_call` visits a reconstructed Call with the modified
290+
/// arguments but also receives a pointer to the unmodified Expression as a second
291+
/// argument. If no arguments were modified the unmodified Expression* will be nullptr.
292+
template <typename PreVisit, typename PostVisitCall>
293+
Result<Expression> Modify(Expression expr, const PreVisit& pre,
294+
const PostVisitCall& post_call) {
295+
ARROW_ASSIGN_OR_RAISE(expr, Result<Expression>(pre(std::move(expr))));
296+
297+
auto call = expr.call();
298+
if (!call) return expr;
299+
300+
bool at_least_one_modified = false;
301+
std::vector<Expression> modified_arguments;
302+
303+
for (size_t i = 0; i < call->arguments.size(); ++i) {
304+
ARROW_ASSIGN_OR_RAISE(auto modified_argument,
305+
Modify(call->arguments[i], pre, post_call));
306+
307+
if (Identical(modified_argument, call->arguments[i])) {
308+
continue;
309+
}
310+
311+
if (!at_least_one_modified) {
312+
modified_arguments = call->arguments;
313+
at_least_one_modified = true;
314+
}
315+
316+
modified_arguments[i] = std::move(modified_argument);
317+
}
318+
319+
if (at_least_one_modified) {
320+
// reconstruct the call expression with the modified arguments
321+
auto modified_call = *call;
322+
modified_call.arguments = std::move(modified_arguments);
323+
return post_call(Expression(std::move(modified_call)), &expr);
324+
}
325+
326+
return post_call(std::move(expr), nullptr);
327+
}
328+
282329
/// @}
283330

284331
} // namespace compute

cpp/src/arrow/compute/exec/expression_internal.h

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -287,52 +287,5 @@ inline Result<std::shared_ptr<compute::Function>> GetFunction(
287287
return GetCastFunction(*to_type);
288288
}
289289

290-
/// Modify an Expression with pre-order and post-order visitation.
291-
/// `pre` will be invoked on each Expression. `pre` will visit Calls before their
292-
/// arguments, `post_call` will visit Calls (and no other Expressions) after their
293-
/// arguments. Visitors should return the Identical expression to indicate no change; this
294-
/// will prevent unnecessary construction in the common case where a modification is not
295-
/// possible/necessary/...
296-
///
297-
/// If an argument was modified, `post_call` visits a reconstructed Call with the modified
298-
/// arguments but also receives a pointer to the unmodified Expression as a second
299-
/// argument. If no arguments were modified the unmodified Expression* will be nullptr.
300-
template <typename PreVisit, typename PostVisitCall>
301-
Result<Expression> Modify(Expression expr, const PreVisit& pre,
302-
const PostVisitCall& post_call) {
303-
ARROW_ASSIGN_OR_RAISE(expr, Result<Expression>(pre(std::move(expr))));
304-
305-
auto call = expr.call();
306-
if (!call) return expr;
307-
308-
bool at_least_one_modified = false;
309-
std::vector<Expression> modified_arguments;
310-
311-
for (size_t i = 0; i < call->arguments.size(); ++i) {
312-
ARROW_ASSIGN_OR_RAISE(auto modified_argument,
313-
Modify(call->arguments[i], pre, post_call));
314-
315-
if (Identical(modified_argument, call->arguments[i])) {
316-
continue;
317-
}
318-
319-
if (!at_least_one_modified) {
320-
modified_arguments = call->arguments;
321-
at_least_one_modified = true;
322-
}
323-
324-
modified_arguments[i] = std::move(modified_argument);
325-
}
326-
327-
if (at_least_one_modified) {
328-
// reconstruct the call expression with the modified arguments
329-
auto modified_call = *call;
330-
modified_call.arguments = std::move(modified_arguments);
331-
return post_call(Expression(std::move(modified_call)), &expr);
332-
}
333-
334-
return post_call(std::move(expr), nullptr);
335-
}
336-
337290
} // namespace compute
338291
} // namespace arrow

cpp/src/arrow/dataset/dataset.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <memory>
2121
#include <utility>
2222

23-
#include "arrow/compute/exec/expression_internal.h"
2423
#include "arrow/dataset/dataset_internal.h"
2524
#include "arrow/dataset/scanner.h"
2625
#include "arrow/table.h"

cpp/src/arrow/dataset/partition.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "arrow/compute/api_scalar.h"
3030
#include "arrow/compute/api_vector.h"
3131
#include "arrow/compute/cast.h"
32-
#include "arrow/compute/exec/expression.h"
32+
#include "arrow/compute/exec/expression_internal.h"
3333
#include "arrow/compute/row/grouper.h"
3434
#include "arrow/dataset/dataset_internal.h"
3535
#include "arrow/filesystem/path_util.h"

0 commit comments

Comments
 (0)