1 /* 2 * Copyright (C) 2022 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_PRELUDE_TABLE_FUNCTIONS_TABLE_FUNCTION_H_ 18 #define SRC_TRACE_PROCESSOR_PRELUDE_TABLE_FUNCTIONS_TABLE_FUNCTION_H_ 19 20 #include "perfetto/base/status.h" 21 #include "src/trace_processor/db/table.h" 22 #include "src/trace_processor/sqlite/query_constraints.h" 23 24 namespace perfetto { 25 namespace trace_processor { 26 27 // Interface which can be subclassed to allow generation of tables dynamically 28 // at filter time. 29 // This class is used to implement table-valued functions and other similar 30 // tables. 31 class TableFunction { 32 public: 33 virtual ~TableFunction(); 34 35 // Returns the schema of the table that will be returned by ComputeTable. 36 virtual Table::Schema CreateSchema() = 0; 37 38 // Returns the name of the dynamic table. 39 // This will be used to register the table with SQLite. 40 virtual std::string TableName() = 0; 41 42 // Returns the estimated number of rows the table would generate. 43 virtual uint32_t EstimateRowCount() = 0; 44 45 // Checks that the constraint set is valid. 46 // 47 // Returning base::OkStatus means that the required constraints are present 48 // in |qc| for dynamically computing the table (e.g. any required 49 // constraints on hidden columns for table-valued functions are present). 50 virtual base::Status ValidateConstraints(const QueryConstraints& qc) = 0; 51 52 // Dynamically computes the table given the constraints and order by 53 // vectors. 54 // The table is returned via |table_return|. There are no guarantees on 55 // its value if the method returns a non-ok status. 56 virtual base::Status ComputeTable(const std::vector<Constraint>& cs, 57 const std::vector<Order>& ob, 58 const BitVector& cols_used, 59 std::unique_ptr<Table>& table_return) = 0; 60 }; 61 62 } // namespace trace_processor 63 } // namespace perfetto 64 65 #endif // SRC_TRACE_PROCESSOR_PRELUDE_TABLE_FUNCTIONS_TABLE_FUNCTION_H_ 66