xref: /aosp_15_r20/external/perfetto/src/trace_processor/db/column/dense_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_DENSE_NULL_OVERLAY_H_
18 #define SRC_TRACE_PROCESSOR_DB_COLUMN_DENSE_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 but without changing the
34 // "spacing" of the underlying storage i.e. this overlay simply "masks" out
35 // rows in the underlying storage with nulls.
36 class DenseNullOverlay final : public OverlayLayer {
37  public:
38   explicit DenseNullOverlay(const BitVector* non_null);
39   ~DenseNullOverlay() override;
40 
41   void Flatten(uint32_t* start, const uint32_t* end, uint32_t stride) override;
42 
43   std::unique_ptr<DataLayerChain> MakeChain(
44       std::unique_ptr<DataLayerChain>,
45       ChainCreationArgs = ChainCreationArgs());
46 
47  private:
48   class ChainImpl : public DataLayerChain {
49    public:
50     ChainImpl(std::unique_ptr<DataLayerChain> inner, const BitVector* non_null);
51 
52     SingleSearchResult SingleSearch(FilterOp,
53                                     SqlValue,
54                                     uint32_t) const override;
55 
56     SearchValidationResult ValidateSearchConstraints(FilterOp,
57                                                      SqlValue) const override;
58 
59     RangeOrBitVector SearchValidated(FilterOp, SqlValue, Range) const override;
60 
61     void IndexSearchValidated(FilterOp, SqlValue, Indices&) const override;
62 
63     void StableSort(Token* start, Token* end, SortDirection) const override;
64 
65     void Distinct(Indices&) const override;
66 
67     std::optional<Token> MaxElement(Indices&) const override;
68 
69     std::optional<Token> MinElement(Indices&) const override;
70 
71     SqlValue Get_AvoidUsingBecauseSlow(uint32_t index) const override;
72 
size()73     uint32_t size() const override { return non_null_->size(); }
74 
DebugString()75     std::string DebugString() const override { return "DenseNullOverlay"; }
76 
77    private:
78     std::unique_ptr<DataLayerChain> inner_;
79     const BitVector* non_null_ = nullptr;
80   };
81 
82   const BitVector* non_null_ = nullptr;
83 };
84 
85 }  // namespace perfetto::trace_processor::column
86 
87 #endif  // SRC_TRACE_PROCESSOR_DB_COLUMN_DENSE_NULL_OVERLAY_H_
88