/* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SRC_TRACE_PROCESSOR_PERFETTO_SQL_ENGINE_TABLE_POINTER_MODULE_H_ #define SRC_TRACE_PROCESSOR_PERFETTO_SQL_ENGINE_TABLE_POINTER_MODULE_H_ #include <array> #include <cstdint> #include <optional> #include "src/trace_processor/db/table.h" #include "src/trace_processor/sqlite/bindings/sqlite_module.h" namespace perfetto::trace_processor { // SQLite module which allows iteration over a table pointer (i.e. a instance of // Table which is being directly passed in as a SQL value). This allows for a // dynamic, schema-less iteration over table pointers. This is generally not // possible as SQLite reqiures the schema to be defined upfront but this class // works around that by having a fixed schema but then allowing "binding" table // pointer columns to SQLite columns dynamically at query time. // // Example: // ``` // -- Renaming the static columns defined by this table to the particular // -- column names for this query. // SELECT c0 AS node_id, c1 AS parent_node_id // -- The call to this class // FROM __intrinsic_table_ptr(( // -- An aggregate function which returns the table pointer we want to // -- iterate over. // SELECT __intrinsic_dfs(g.source_node_id, g.dest_node_id, $start_node_id) // FROM $graph_table g // )) // -- Informs this class about which SQLite column corresponds to which // -- SQLite column. The SQLite columns bindings should be dense starting from // -- 0. // WHERE __intrinsic_table_ptr_bind(c0, 'node_id') // AND __intrinsic_table_ptr_bind(c1, 'parent_node_id') // ``` // // Note: this class is *not* intended to be used directly by end users. It is // a building block intended for use by very low-level macros in the standard // library. struct TablePointerModule : sqlite::Module<TablePointerModule> { … }; } // namespace perfetto::trace_processor #endif // SRC_TRACE_PROCESSOR_PERFETTO_SQL_ENGINE_TABLE_POINTER_MODULE_H_