]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/cpp/src/arrow/compute/exec/expression_benchmark.cc
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / arrow / compute / exec / expression_benchmark.cc
CommitLineData
1d09f67e
TL
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#include "benchmark/benchmark.h"
19
20#include "arrow/compute/cast.h"
21#include "arrow/compute/exec/expression.h"
22#include "arrow/dataset/partition.h"
23#include "arrow/testing/gtest_util.h"
24#include "arrow/type.h"
25
26namespace arrow {
27namespace compute {
28
29std::shared_ptr<Scalar> ninety_nine_dict =
30 DictionaryScalar::Make(MakeScalar(0), ArrayFromJSON(int64(), "[99]"));
31
32// A benchmark of SimplifyWithGuarantee using expressions arising from partitioning.
33static void SimplifyFilterWithGuarantee(benchmark::State& state, Expression filter,
34 Expression guarantee) {
35 auto dataset_schema = schema({field("a", int64()), field("b", int64())});
36 ASSIGN_OR_ABORT(filter, filter.Bind(*dataset_schema));
37
38 for (auto _ : state) {
39 ABORT_NOT_OK(SimplifyWithGuarantee(filter, guarantee));
40 }
41}
42
43auto to_int64 = compute::CastOptions::Safe(int64());
44// A fully simplified filter.
45auto filter_simple_negative = and_(equal(field_ref("a"), literal(int64_t(99))),
46 equal(field_ref("b"), literal(int64_t(98))));
47auto filter_simple_positive = and_(equal(field_ref("a"), literal(int64_t(99))),
48 equal(field_ref("b"), literal(int64_t(99))));
49// A filter with casts inserted due to converting between the
50// assumed-by-default type and the inferred partition schema.
51auto filter_cast_negative =
52 and_(equal(call("cast", {field_ref("a")}, to_int64), literal(99)),
53 equal(call("cast", {field_ref("b")}, to_int64), literal(98)));
54auto filter_cast_positive =
55 and_(equal(call("cast", {field_ref("a")}, to_int64), literal(99)),
56 equal(call("cast", {field_ref("b")}, to_int64), literal(99)));
57
58// An unencoded partition expression for "a=99/b=99".
59auto guarantee = and_(equal(field_ref("a"), literal(int64_t(99))),
60 equal(field_ref("b"), literal(int64_t(99))));
61
62// A partition expression for "a=99/b=99" that uses dictionaries (inferred by default).
63auto guarantee_dictionary = and_(equal(field_ref("a"), literal(ninety_nine_dict)),
64 equal(field_ref("b"), literal(ninety_nine_dict)));
65
66// Negative queries (partition expressions that fail the filter)
67BENCHMARK_CAPTURE(SimplifyFilterWithGuarantee, negative_filter_simple_guarantee_simple,
68 filter_simple_negative, guarantee);
69BENCHMARK_CAPTURE(SimplifyFilterWithGuarantee, negative_filter_cast_guarantee_simple,
70 filter_cast_negative, guarantee);
71BENCHMARK_CAPTURE(SimplifyFilterWithGuarantee,
72 negative_filter_simple_guarantee_dictionary, filter_simple_negative,
73 guarantee_dictionary);
74BENCHMARK_CAPTURE(SimplifyFilterWithGuarantee, negative_filter_cast_guarantee_dictionary,
75 filter_cast_negative, guarantee_dictionary);
76// Positive queries (partition expressions that pass the filter)
77BENCHMARK_CAPTURE(SimplifyFilterWithGuarantee, positive_filter_simple_guarantee_simple,
78 filter_simple_positive, guarantee);
79BENCHMARK_CAPTURE(SimplifyFilterWithGuarantee, positive_filter_cast_guarantee_simple,
80 filter_cast_positive, guarantee);
81BENCHMARK_CAPTURE(SimplifyFilterWithGuarantee,
82 positive_filter_simple_guarantee_dictionary, filter_simple_positive,
83 guarantee_dictionary);
84BENCHMARK_CAPTURE(SimplifyFilterWithGuarantee, positive_filter_cast_guarantee_dictionary,
85 filter_cast_positive, guarantee_dictionary);
86
87} // namespace compute
88} // namespace arrow