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_ARRANGEMENT_OVERLAY_H_ 18 #define SRC_TRACE_PROCESSOR_DB_COLUMN_ARRANGEMENT_OVERLAY_H_ 19 20 #include <cstdint> 21 #include <memory> 22 #include <optional> 23 #include <string> 24 #include <vector> 25 26 #include "perfetto/trace_processor/basic_types.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 // Storage responsible for rearranging the elements of another Storage. It deals 33 // with duplicates, permutations and selection; for selection only, it's more 34 // efficient to use `SelectorOverlay`. 35 class ArrangementOverlay final : public DataLayer { 36 public: 37 ArrangementOverlay(const std::vector<uint32_t>* arrangement, 38 DataLayerChain::Indices::State arrangement_state); 39 ~ArrangementOverlay() override; 40 41 std::unique_ptr<DataLayerChain> MakeChain( 42 std::unique_ptr<DataLayerChain>, 43 ChainCreationArgs = ChainCreationArgs()); 44 45 private: 46 class ChainImpl : public DataLayerChain { 47 public: 48 ChainImpl(std::unique_ptr<DataLayerChain> inner, 49 const std::vector<uint32_t>* arrangement, 50 Indices::State arrangement_state, 51 bool does_arrangement_order_storage); 52 53 SingleSearchResult SingleSearch(FilterOp, 54 SqlValue, 55 uint32_t) const override; 56 57 SearchValidationResult ValidateSearchConstraints(FilterOp, 58 SqlValue) const override; 59 60 RangeOrBitVector SearchValidated(FilterOp, SqlValue, Range) const override; 61 62 void IndexSearchValidated(FilterOp, SqlValue, Indices&) const override; 63 64 void StableSort(SortToken* start, 65 SortToken* end, 66 SortDirection) const override; 67 68 void Distinct(Indices&) const override; 69 70 std::optional<Token> MaxElement(Indices&) const override; 71 72 std::optional<Token> MinElement(Indices&) const override; 73 74 SqlValue Get_AvoidUsingBecauseSlow(uint32_t index) const override; 75 76 void Serialize(StorageProto*) const override; 77 size()78 uint32_t size() const override { 79 return static_cast<uint32_t>(arrangement_->size()); 80 } 81 DebugString()82 std::string DebugString() const override { return "ArrangementOverlay"; } 83 84 private: 85 std::unique_ptr<DataLayerChain> inner_; 86 const std::vector<uint32_t>* arrangement_; 87 const Indices::State arrangement_state_; 88 const bool does_arrangement_order_storage_; 89 }; 90 91 std::unique_ptr<DataLayerChain> inner_; 92 const std::vector<uint32_t>* arrangement_; 93 const DataLayerChain::Indices::State arrangement_state_; 94 }; 95 96 } // namespace perfetto::trace_processor::column 97 98 #endif // SRC_TRACE_PROCESSOR_DB_COLUMN_ARRANGEMENT_OVERLAY_H_ 99