Skip to content

A lightweight SQL engine implemented in Python that parses and executes a subset of SQL queries via the command line. It supports core SQL features like SELECT, WHERE, GROUP BY, ORDER BY, DISTINCT, and simple joins on CSV-based datasets, providing an educational insight into how SQL engines work internally.

Notifications You must be signed in to change notification settings

vishalpatel72/Mini-SQL-Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mini-SQL-Engine

A Mini SQL Engine which runs a subset of queries using Command Line Interface.

Features

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(), and COUNT().
  • ORDER BY: Sort the result set in ascending (ASC) or descending (DESC) order.
  • DISTINCT: Retrieve unique values from a column.

How to Run

  1. Prerequisites: Ensure you have Python 3 installed.

  2. Setup Database Files:

    • The files/ directory contains metadata.txt and CSV files (table1.csv, table2.csv, table3.csv) which represent the database schema and data.
    • metadata.txt defines the tables and their columns.
    • The CSV files contain the actual data for each table.
  3. Execute Queries: Run the SQLengine.py script 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;"

Project Structure

  • 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 the files/ directory.
  • files1/: (Optional) Another directory possibly containing alternative or sample data/metadata.

About

A lightweight SQL engine implemented in Python that parses and executes a subset of SQL queries via the command line. It supports core SQL features like SELECT, WHERE, GROUP BY, ORDER BY, DISTINCT, and simple joins on CSV-based datasets, providing an educational insight into how SQL engines work internally.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published