// tql_to_sql: emite SQL DuckDB equivalente a una pipeline TQL State. // Pure. Sin DuckDB linkado. Solo string emit + validacion. // Ver issue 0080 + docs/TQL.md (seccion "SQL transpile subset"). #pragma once #include "data_table_logic.h" #include #include namespace tql_to_sql { struct SqlEmit { std::string sql; // SELECT/CTE chain DuckDB std::vector params; // bound values posicionales (?) std::vector warnings; // soft issues (col not found, etc.) std::string error; // si non-empty, emit fallo }; // Pure: emite SQL DuckDB equivalente a stages 0..active del state. // `tables` provee schema (headers/types/name) de cada TableInput. El caller // es responsable de hidratar las tablas en DuckDB con esos nombres. // `up_to_stage = -1` => state.active_stage. SqlEmit emit_sql(const data_table::State& state, const std::vector& tables, int up_to_stage = -1); // Pure: valida que `formula` (cuerpo Lua de un derived col) este dentro del // subset SQL-transpilable. Si valido, retorna true. Si no, false + razon // concreta en `error_out` (categoria + token problematico). // Ver docs/TQL.md#sql-transpile-subset. bool is_transpilable(const std::string& formula, std::string& error_out); // Pure: transpila formula Lua subset -> SQL expression. Si fuera de subset, // retorna "" y rellena `error_out`. Asume is_transpilable retornaria true. // `in_headers` necesario para resolver `[col]` refs y emitir identifier // SQL apropiado (quoted si tiene char especial). std::string transpile_expr(const std::string& formula, const std::vector& in_headers, std::string& error_out); } // namespace tql_to_sql