xref: /aosp_15_r20/external/perfetto/src/trace_processor/db/column/null_overlay.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SRC_TRACE_PROCESSOR_DB_COLUMN_NULL_OVERLAY_H_
18 #define SRC_TRACE_PROCESSOR_DB_COLUMN_NULL_OVERLAY_H_
19 
20 #include <cstdint>
21 #include <memory>
22 #include <optional>
23 #include <string>
24 
25 #include "perfetto/trace_processor/basic_types.h"
26 #include "src/trace_processor/containers/bit_vector.h"
27 #include "src/trace_processor/db/column/data_layer.h"
28 #include "src/trace_processor/db/column/overlay_layer.h"
29 #include "src/trace_processor/db/column/types.h"
30 
31 namespace perfetto::trace_processor::column {
32 
33 // Overlay which introduces the layer of nullability. Specifically, spreads out
34 // the storage with nulls using a BitVector.
35 class NullOverlay final : public OverlayLayer {
36  public:
37   explicit NullOverlay(const BitVector* non_null);
38   ~NullOverlay() override;
39 
40   void Flatten(uint32_t* start, const uint32_t* end, uint32_t stride) override;
41 
42   std::unique_ptr<DataLayerChain> MakeChain(
43       std::unique_ptr<DataLayerChain>,
44       ChainCreationArgs = ChainCreationArgs());
45 
46  private:
47   class ChainImpl : public DataLayerChain {
48    public:
49     ChainImpl(std::unique_ptr<DataLayerChain>, const BitVector* non_null);
50 
51     SingleSearchResult SingleSearch(FilterOp,
52                                     SqlValue,
53                                     uint32_t) const override;
54 
55     SearchValidationResult ValidateSearchConstraints(FilterOp,
56                                                      SqlValue) const override;
57 
58     RangeOrBitVector SearchValidated(FilterOp, SqlValue, Range) const override;
59 
60     void IndexSearchValidated(FilterOp, SqlValue, Indices&) const override;
61 
62     void StableSort(Token* start, Token* end, SortDirection) const override;
63 
64     void Distinct(Indices&) const override;
65 
66     std::optional<Token> MaxElement(Indices&) const override;
67 
68     std::optional<Token> MinElement(Indices&) const override;
69 
70     SqlValue Get_AvoidUsingBecauseSlow(uint32_t index) const override;
71 
size()72     uint32_t size() const override { return non_null_->size(); }
73 
DebugString()74     std::string DebugString() const override { return "NullOverlay"; }
75 
76    private:
77     std::unique_ptr<DataLayerChain> inner_ = nullptr;
78     const BitVector* non_null_ = nullptr;
79   };
80 
81   const BitVector* non_null_ = nullptr;
82 };
83 
84 }  // namespace perfetto::trace_processor::column
85 
86 #endif  // SRC_TRACE_PROCESSOR_DB_COLUMN_NULL_OVERLAY_H_
87