This project is a homework assignment focused on implementing a Query Language inspired by SQL, built upon a custom in-memory database.
The goal is to implement operations on individual tables as well as interactions between multiple tables, allowing for complex data manipulation and querying.
This project implements a lightweight database engine with the following capabilities:
- Insert: Add new rows to a table.
- Delete: Remove rows from a table.
- Sort: detailed sorting of table data by column.
- Select: Project specific columns from a table.
- Filter: Apply complex conditions to filter rows.
- Join: Perform inner/outer joins between two tables.
- Cartesian Product: Generate the Cartesian product of two tables.
- Manage Tables: Create, retrieve, and delete tables within a database instance.
The project includes a domain-specific language (DSL) for filtering data:
- Filter Conditions:
Equal,And,Or,Not. - Complex Queries: Pre-defined queries for common use cases (e.g., finding customers by age and city, filtering orders by date).
src/main/scala/Table.scala: Core data structure representing a database table.src/main/scala/Database.scala: Manages a collection of tables.src/main/scala/FilterCond.scala: Defines the filtering logic and conditions.src/main/scala/Queries.scala: Contains specific business logic queries.src/test/scala/: Contains unit tests for the application.
- Scala: Version 3.3.1 or higher.
- sbt: The Scala Build Tool. Install sbt.
Note: This environment does not have
sbtpre-installed. You will need to install it to build and run the project.
-
Clone the repository:
git clone <repository_url> cd tema2
-
Run Tests: Execute the unit tests to verify the implementation.
sbt test -
Run the Application: You can use the
sbt consoleto interact with the code:sbt console
Then, inside the REPL:
import Table._ import Database._ val db = Database(List()) val newDb = db.insert("Users") println(newDb)
val csvData = """
name,age,city
Alice,30,New York
Bob,25,Los Angeles
"""
val table = Table.fromCSV(csvData)import FilterCond._
// Assuming 'table' exists
val filter = Field("age", _.toInt > 20)
val filteredTable = table.filter(filter)