/HeapQuery

HeapQuery is an in-memory database system in Java for managing schemas and tuples, supporting basic data manipulation, relational operations, and boolean query conditions.

Primary LanguageJava

HeapQuery Project

This project, named HeapQuery, is a simple, in-memory database system implemented in Java. It provides core functionalities for managing and querying tabular data, including creating schemas, inserting and deleting tuples (rows), and performing lookups.

For sample I/O traces and additional information, visit the project page: https://www.rsiddiq.com/database-systems.html


Project Structure

The project follows a standard Maven directory layout.

  • src/main/java/heapquery: Contains the main source code for the database components.
  • src/main/java/heapquery/resource: Contains classes for defining and evaluating query conditions.
  • src/test/java/heapquery: Holds the JUnit test suite for the project.
  • target/: This directory is generated by Maven and contains the compiled .class files.
  • pom.xml: The project's build configuration file.
  • mvnw and mvnw.cmd: Maven Wrapper scripts for building and running the project without a pre-installed Maven.

Core Components

The system is built around several key classes and interfaces:

  • Schema.java: Defines the structure of a table, including column names, data types, and the primary key. It supports int and varchar data types.
  • IType.java and its implementations (TypeInt.java, TypeVarchar.java): These interfaces and classes handle the specific characteristics of different data types, such as their size in bytes and how they are read and written to a buffer.
  • Tuple.java: Represents a single row of data in a table. It stores an array of Object values and a Schema to define its structure. It includes methods for getting and setting values by index or column name, and for serializing/deserializing data.
  • ITable.java and its implementation (Table.java): The Table class is an in-memory storage for Tuple objects. It provides methods for basic database operations like insert, delete, lookup, and retrieving the table size. It handles duplicate key checks during insertion if a primary key is defined in the schema.
  • resource package (Condition.java, EqCondition.java, AndCondition.java, OrCondition.java, SelectQuery.java): This package provides a basic query language for the database.
    • Condition is an abstract class for evaluating boolean conditions on a tuple.
    • EqCondition, AndCondition, and OrCondition implement different types of conditions for building complex queries.
    • SelectQuery is the main class for running a select query with an optional projection and a where clause.

Building and Running

The project is built using Apache Maven. The provided mvnw and mvnw.cmd scripts are the recommended way to interact with the project, as they automatically handle downloading the correct Maven version.

Prerequisites

  • Java Development Kit (JDK) version 17 or later.

Build the Project

To compile the source code, run the tests, and package the application, use the following command from the root directory of the project:

./mvnw package

Run the Application

The MainApplication.java class serves as the entry point. You can run it using the following command after building the project:

./mvnw exec:java -Dexec.mainClass="heapquery.MainApplication"

The expected output demonstrates the basic functionality of the database, including insertion, deletion, and querying:

Initial table:
[12121, Kim, Elect. Engr., 65000]
[19803, Wisneski, Comp. Sci., 46000]
[24734, Bruns, Comp. Sci., 70000]
[55552, Scott, Math, 80000]
[12321, Tao, Comp. Sci., 95000]
Delete 12121: true
[19803, Wisneski, Comp. Sci., 46000]
[24734, Bruns, Comp. Sci., 70000]
[55552, Scott, Math, 80000]
[12321, Tao, Comp. Sci., 95000]
Attempt to delete 12121 again: false
eval dept_name=Comp. Sci.
[19803, Wisneski, Comp. Sci., 46000]
[24734, Bruns, Comp. Sci., 70000]
[12321, Tao, Comp. Sci., 95000]
eval ID=19803
[19803, Wisneski, Comp. Sci., 46000]
eval ID=19802
Empty Table

Running Tests

The project includes unit tests to ensure the functionality of its components. You can run all tests using the following command:

./mvnw test