| 72 | const char* kind_name() const override { return "FilterNode"; } |
| 73 | |
| 74 | Result<ExecBatch> ProcessBatch(ExecBatch batch) override { |
| 75 | ARROW_ASSIGN_OR_RAISE(Expression simplified_filter, |
| 76 | SimplifyWithGuarantee(filter_, batch.guarantee)); |
| 77 | |
| 78 | arrow::util::tracing::Span span; |
| 79 | START_COMPUTE_SPAN(span, "Filter", |
| 80 | {{"filter.expression", ToStringExtra()}, |
| 81 | {"filter.expression.simplified", simplified_filter.ToString()}, |
| 82 | {"filter.length", batch.length}}); |
| 83 | |
| 84 | ARROW_ASSIGN_OR_RAISE( |
| 85 | Datum mask, ExecuteScalarExpression(simplified_filter, batch, |
| 86 | plan()->query_context()->exec_context())); |
| 87 | |
| 88 | if (mask.is_scalar()) { |
| 89 | const auto& mask_scalar = mask.scalar_as<BooleanScalar>(); |
| 90 | if (mask_scalar.is_valid && mask_scalar.value) { |
| 91 | return batch; |
| 92 | } |
| 93 | return batch.Slice(0, 0); |
| 94 | } |
| 95 | |
| 96 | // if the values are all scalar then the mask must also be |
| 97 | DCHECK(!std::all_of(batch.values.begin(), batch.values.end(), |
| 98 | [](const Datum& value) { return value.is_scalar(); })); |
| 99 | |
| 100 | auto values = batch.values; |
| 101 | for (auto& value : values) { |
| 102 | if (value.is_scalar()) continue; |
| 103 | ARROW_ASSIGN_OR_RAISE(value, Filter(value, mask, FilterOptions::Defaults())); |
| 104 | } |
| 105 | return ExecBatch::Make(std::move(values)); |
| 106 | } |
| 107 | |
| 108 | protected: |
| 109 | std::string ToStringExtra(int indent = 0) const override { |