A Mini SQL Engine which runs a subset of queries using Command Line Interface.
This mini SQL engine supports the following SQL query features:
- SELECT: Retrieve data from tables. Supports
*for all columns and specific column selection. - FROM: Specify tables to retrieve data from. Supports joining multiple tables.
- WHERE: Filter data based on conditions. Supports comparison operators (
=,<,>,<=,>=) and logical operators (AND,OR). - GROUP BY: Aggregate data based on one or more columns. Supports aggregate functions like
SUM(),AVG(),MIN(),MAX(), andCOUNT(). - ORDER BY: Sort the result set in ascending (
ASC) or descending (DESC) order. - DISTINCT: Retrieve unique values from a column.
-
Prerequisites: Ensure you have Python 3 installed.
-
Setup Database Files:
- The
files/directory containsmetadata.txtand CSV files (table1.csv,table2.csv,table3.csv) which represent the database schema and data. metadata.txtdefines the tables and their columns.- The CSV files contain the actual data for each table.
- The
-
Execute Queries: Run the
SQLengine.pyscript from the command line, passing your SQL query as an argument.Example:
python3 SQLengine.py "SELECT * FROM table1;" python3 SQLengine.py "SELECT A, B FROM table1 WHERE A > 10 AND B < 50;" python3 SQLengine.py "SELECT SUM(A) FROM table1 GROUP BY B;" python3 SQLengine.py "SELECT A, B FROM table1 ORDER BY A DESC;" python3 SQLengine.py "SELECT DISTINCT A FROM table1;" python3 SQLengine.py "SELECT table1.A, table2.B FROM table1, table2 WHERE table1.A = table2.A;"
SQLengine.py: The main script containing the SQL parsing and execution logic.preprocessing.py: Handles reading metadata and CSV data to set up the in-memory database.error.py: Contains functions for displaying various error messages.files/:metadata.txt: Defines the database schema (table names and column names).table1.csv,table2.csv,table3.csv: CSV files containing the data for each table.
2020201082.sh: (Optional) A shell script that might contain example commands or setup instructions.files.zip: (Optional) A zip archive of thefiles/directory.files1/: (Optional) Another directory possibly containing alternative or sample data/metadata.