SPB Git

spb/firc0001_uqo

Public
1.7 KB · 28 lines python
1"""N0 probe: open both DuckDB files read-only, describe the tables used by N1-N13."""2import sys, json3from pathlib import Path4sys.path.insert(0, str(Path(__file__).resolve().parent))5from common import *67r = Run("n0_probe")8con = connect(SPID_DB)9out = {}10for t in ["extracted_sections", "project_mentions", "projects", "project_timeline", "spid_sections", "v_sections", "src_filings", "src_sections", "src_companies"]:11    out[t] = [tuple(x[:2]) for x in con.execute(f"DESCRIBE {t}").fetchall()]12out["views"] = con.execute("select view_name, sql from duckdb_views() where not internal").fetchall()13out["counts"] = {t: con.execute(f"select count(*) from {t}").fetchone()[0] for t in ["extracted_sections", "project_mentions", "projects", "project_timeline", "spid_sections"]}14out["ledger_words"] = con.execute("select count(*), sum(v.word_count) from extracted_sections e join (select section_id, word_count from src_sections union all select section_id, word_count from spid_sections) v using(section_id)").fetchone()15out["parquet_files"] = con.execute("select count(*), sum(length(text))/1e9 from src_sections").fetchone()16e = connect(EDGAR_DB)17for t in ["filings", "filing_sections", "companies", "annual_panel"]:18    out["edgar_"+t] = [tuple(x[:2]) for x in e.execute(f"DESCRIBE {t}").fetchall()]19out["edgar_tables"] = [x[0] for x in e.execute("select table_name from duckdb_tables() where not internal").fetchall()]20r.write_json("schema.json", out)21# can we create a temp table on a read_only connection?22try:23    con.execute("CREATE TEMP TABLE _t AS SELECT 1 AS x"); out["temp_ok"] = True24except Exception as ex:25    out["temp_ok"] = str(ex)26r.write_json("schema.json", out)27r.finish()28
Files · main
Menu

Theme