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
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.classfiles.pom.xml: The project's build configuration file.mvnwandmvnw.cmd: Maven Wrapper scripts for building and running the project without a pre-installed Maven.
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 supportsintandvarchardata types.IType.javaand 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 ofObjectvalues and aSchemato define its structure. It includes methods for getting and setting values by index or column name, and for serializing/deserializing data.ITable.javaand its implementation (Table.java): TheTableclass is an in-memory storage forTupleobjects. It provides methods for basic database operations likeinsert,delete,lookup, and retrieving the table size. It handles duplicate key checks during insertion if a primary key is defined in the schema.resourcepackage (Condition.java,EqCondition.java,AndCondition.java,OrCondition.java,SelectQuery.java): This package provides a basic query language for the database.Conditionis an abstract class for evaluating boolean conditions on a tuple.EqCondition,AndCondition, andOrConditionimplement different types of conditions for building complex queries.SelectQueryis the main class for running a select query with an optional projection and awhereclause.
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.
- Java Development Kit (JDK) version 17 or later.
To compile the source code, run the tests, and package the application, use the following command from the root directory of the project:
./mvnw packageThe 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
The project includes unit tests to ensure the functionality of its components. You can run all tests using the following command:
./mvnw test