#include "src/trace_processor/perfetto_sql/intrinsics/operators/span_join_operator.h"
#include <sqlite3.h>
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <optional>
#include <string>
#include <tuple>
#include <unordered_set>
#include <utility>
#include <vector>
#include "perfetto/base/compiler.h"
#include "perfetto/base/logging.h"
#include "perfetto/base/status.h"
#include "perfetto/ext/base/string_splitter.h"
#include "perfetto/ext/base/string_utils.h"
#include "perfetto/trace_processor/basic_types.h"
#include "src/trace_processor/perfetto_sql/engine/perfetto_sql_engine.h"
#include "src/trace_processor/sqlite/bindings/sqlite_result.h"
#include "src/trace_processor/sqlite/module_lifecycle_manager.h"
#include "src/trace_processor/sqlite/sql_source.h"
#include "src/trace_processor/sqlite/sqlite_utils.h"
#include "src/trace_processor/tp_metatrace.h"
#include "src/trace_processor/util/status_macros.h"
#include "protos/perfetto/trace_processor/metatrace_categories.pbzero.h"
namespace perfetto::trace_processor {
namespace {
constexpr char kTsColumnName[] = …;
constexpr char kDurColumnName[] = …;
bool IsRequiredColumn(const std::string& name) { … }
std::optional<std::string> HasDuplicateColumns(
const std::vector<std::pair<SqlValue::Type, std::string>>& t1,
const std::vector<std::pair<SqlValue::Type, std::string>>& t2,
const std::optional<std::string>& partition_col) { … }
std::string OpToString(int op) { … }
std::string EscapedSqliteValueAsString(sqlite3_value* value) { … }
}
void SpanJoinOperatorModule::State::PopulateColumnLocatorMap(uint32_t offset) { … }
std::string SpanJoinOperatorModule::State::BestIndexStrForDefinition(
const sqlite3_index_info* info,
const TableDefinition& defn) { … }
base::Status SpanJoinOperatorModule::TableDefinition::Create(
PerfettoSqlEngine* engine,
const TableDescriptor& desc,
EmitShadowType emit_shadow_type,
TableDefinition* defn) { … }
std::string
SpanJoinOperatorModule::TableDefinition::CreateVtabCreateTableSection() const { … }
std::string SpanJoinOperatorModule::State::GetNameForGlobalColumnIndex(
const TableDefinition& defn,
int global_column) { … }
SpanJoinOperatorModule::Query::Query(SpanJoinOperatorModule::State* state,
const TableDefinition* definition)
: … { … }
SpanJoinOperatorModule::Query::~Query() = default;
base::Status SpanJoinOperatorModule::Query::Initialize(
std::string sql_query,
InitialEofBehavior eof_behavior) { … }
base::Status SpanJoinOperatorModule::Query::Next() { … }
bool SpanJoinOperatorModule::Query::IsValidSlice() { … }
base::Status SpanJoinOperatorModule::Query::FindNextValidSlice() { … }
base::Status SpanJoinOperatorModule::Query::NextSliceState() { … }
base::Status SpanJoinOperatorModule::Query::Rewind() { … }
base::Status SpanJoinOperatorModule::Query::CursorNext() { … }
void SpanJoinOperatorModule::Query::ReportSqliteResult(sqlite3_context* context,
size_t index) { … }
SpanJoinOperatorModule::TableDefinition::TableDefinition(
std::string name,
std::string partition_col,
std::vector<std::pair<SqlValue::Type, std::string>> cols,
EmitShadowType emit_shadow_type,
uint32_t ts_idx,
uint32_t dur_idx,
uint32_t partition_idx)
: … { … }
base::Status SpanJoinOperatorModule::TableDescriptor::Parse(
const std::string& raw_descriptor,
TableDescriptor* descriptor) { … }
std::string SpanJoinOperatorModule::TableDefinition::CreateSqlQuery(
base::StringSplitter& idx,
sqlite3_value** argv) const { … }
int SpanJoinOperatorModule::Create(sqlite3* db,
void* ctx,
int argc,
const char* const* argv,
sqlite3_vtab** vtab,
char** pzErr) { … }
int SpanJoinOperatorModule::Destroy(sqlite3_vtab* vtab) { … }
int SpanJoinOperatorModule::Connect(sqlite3* db,
void* ctx,
int,
const char* const* argv,
sqlite3_vtab** vtab,
char**) { … }
int SpanJoinOperatorModule::Disconnect(sqlite3_vtab* vtab) { … }
int SpanJoinOperatorModule::BestIndex(sqlite3_vtab* tab,
sqlite3_index_info* info) { … }
int SpanJoinOperatorModule::Open(sqlite3_vtab* tab,
sqlite3_vtab_cursor** cursor) { … }
int SpanJoinOperatorModule::Close(sqlite3_vtab_cursor* cursor) { … }
int SpanJoinOperatorModule::Filter(sqlite3_vtab_cursor* cursor,
int,
const char* idxStr,
int,
sqlite3_value** argv) { … }
int SpanJoinOperatorModule::Next(sqlite3_vtab_cursor* cursor) { … }
int SpanJoinOperatorModule::Eof(sqlite3_vtab_cursor* cur) { … }
int SpanJoinOperatorModule::Column(sqlite3_vtab_cursor* cursor,
sqlite3_context* context,
int N) { … }
int SpanJoinOperatorModule::Rowid(sqlite3_vtab_cursor*, sqlite_int64*) { … }
int SpanJoinOperatorModule::FindFunction(sqlite3_vtab*,
int,
const char* name,
FindFunctionFn** fn,
void**) { … }
bool SpanJoinOperatorModule::Cursor::IsOverlappingSpan() const { … }
base::Status SpanJoinOperatorModule::Cursor::FindOverlappingSpan() { … }
SpanJoinOperatorModule::Query*
SpanJoinOperatorModule::Cursor::FindEarliestFinishQuery() { … }
}