"""Count GitHub events by ``type`` across all Parquet partitions.

Output: a tab-separated table of ``type \t count`` ordered by count
descending. Runs in <2 seconds on the L02 partitions (one day of
gharchive data).
"""

from __future__ import annotations

from .query import open_pipeline_db


def main() -> None:
    with open_pipeline_db() as con:
        rows = con.execute(
            """
            SELECT type, count(*) AS n
            FROM events
            GROUP BY type
            ORDER BY n DESC
            """
        ).fetchall()
    for event_type, count in rows:
        print(f"{event_type}\t{count}")


if __name__ == "__main__":
    main()
