• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/types.h"
29 
30 namespace perfetto::trace_processor::column {
31 
32 // Overlay which introduces the layer of nullability. Specifically, spreads out
33 // the storage with nulls using a BitVector.
34 class NullOverlay final : public DataLayer {
35  public:
36   explicit NullOverlay(const BitVector* non_null);
37   ~NullOverlay() override;
38 
39   std::unique_ptr<DataLayerChain> MakeChain(
40       std::unique_ptr<DataLayerChain>,
41       ChainCreationArgs = ChainCreationArgs());
42 
43  private:
44   class ChainImpl : public DataLayerChain {
45    public:
46     ChainImpl(std::unique_ptr<DataLayerChain>, const BitVector* non_null);
47 
48     SingleSearchResult SingleSearch(FilterOp,
49                                     SqlValue,
50                                     uint32_t) const override;
51 
52     SearchValidationResult ValidateSearchConstraints(FilterOp,
53                                                      SqlValue) const override;
54 
55     RangeOrBitVector SearchValidated(FilterOp, SqlValue, Range) const override;
56 
57     void IndexSearchValidated(FilterOp, SqlValue, Indices&) const override;
58 
59     void StableSort(SortToken* start,
60                     SortToken* end,
61                     SortDirection) const override;
62 
63     void Distinct(Indices&) const override;
64 
65     std::optional<Token> MaxElement(Indices&) const override;
66 
67     std::optional<Token> MinElement(Indices&) const override;
68 
69     SqlValue Get_AvoidUsingBecauseSlow(uint32_t index) const override;
70 
71     void Serialize(StorageProto*) const override;
72 
size()73     uint32_t size() const override { return non_null_->size(); }
74 
DebugString()75     std::string DebugString() const override { return "NullOverlay"; }
76 
77    private:
78     std::unique_ptr<DataLayerChain> inner_ = nullptr;
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_NULL_OVERLAY_H_
88