Classification: Team coursework for CS562. Repository history credits both E-P-C and Pangqiang-Gary; it is not presented as a solo project.
This project parses an MF-structure query specification and generates an executable Python query processor for a PostgreSQL sales relation. It makes the steps between a declarative specification, grouping-variable scans, aggregate state, the G predicate, and final output explicit.
My public commits include the MF-structure parser and query-generator implementation, reproducible cases, an additional n=2/HAVING case, and integration work. The main implementation is visible in this commit; the full contributor history preserves the team attribution.
phi specification -> parser -> typed MF representation -> Python code generator -> PostgreSQL query processor
The input format contains:
S— selected output attributes;n— number of grouping variables;V— grouping attributes;F— aggregate functions;sigma— per-grouping-variable predicates;G— post-aggregation condition.
The repository contains six specifications (phi_input_case1.txt through phi_input_case6.txt) and their recorded outputs under Output/. The extended implementation and additional generated processors are being reviewed in PR #2.
python -m venv .venv
# Windows: .venv\Scripts\activate
# macOS/Linux: source .venv/bin/activate
pip install -r requirements.txtCreate local database configuration from the safe template:
# Windows
copy .env.example .env
# macOS/Linux
cp .env.example .envGenerate a processor from one case:
python codegen.py phi_input_case1.txt generated_case1.py
python generated_case1.pyThe configured PostgreSQL database must contain the sales relation expected by the selected specification. load_sales_10000_table (NEW).sql provides the project dataset setup script.
| Path | Purpose |
|---|---|
phi_parser.py |
Parses and validates the MF specification |
codegen.py |
Emits an executable Python query processor |
qpe.py |
Example generated processor |
phi_input_case*.txt |
Six reproducible specifications |
Output/case*.txt |
Recorded outputs for comparison |
COLAB_ONE_CELL_SETUP.txt |
Self-contained Colab setup helper |
CI checks every committed Python source file and generates a compilable processor for each of the six specifications without requiring database credentials.
python -m py_compile codegen.py phi_parser.py qpe.py
python codegen.py phi_input_case1.txt generated_case1.py
python -m py_compile generated_case1.pyDatabase credentials belong only in the untracked .env file. .env.example contains placeholders and is safe to commit. Generated predicates are evaluated in a restricted namespace, but specifications should still be treated as trusted project inputs rather than arbitrary user input.