Lightweight, in‑memory relational toolkit that lets you define schemas, create typed tables, insert tuples/rows, and perform lookups, projection, and natural joins. Types are pluggable via a small IType interface; the project ships with INT and VARCHAR(n) implementations that support fixed‑width binary serialization using ByteBuffer.
- Project Name:
SchemaCraft - Modules: single‑module Maven project (root)
- Maven: wrapper present (
mvnw,.mvn/wrapper) - Coordinates:
schemacraft:schemacraft:1.0-SNAPSHOT - Java Toolchain: 17+ (set via
maven.compiler.releaseor compatible) - Testing: JUnit Jupiter 5.11.0
- Entry Point:
schemacraft.MainApplication(demo); library API is underschemacraft.* - Key Package:
schemacraft
SchemaCraft/
├── .mvn/
│ └── wrapper/
│ ├── maven-wrapper.jar
│ ├── maven-wrapper.properties
│ └── MavenWrapperDownloader.java
├── src/
│ ├── main/
│ │ └── java/
│ │ └── schemacraft/
│ │ ├── Constants.java
│ │ ├── ITable.java
│ │ ├── IType.java
│ │ ├── MainApplication.java
│ │ ├── Schema.java
│ │ ├── Table.java
│ │ ├── Tuple.java
│ │ ├── TypeInt.java
│ │ └── TypeVarchar.java
│ └── test/
│ └── java/
│ └── schemacraft/
│ ├── TableTest.java
│ └── TupleTest.java
├── .gitignore
├── mvnw
├── mvnw.cmd
├── pom.xml
└── README.md
# from the project root (folder containing pom.xml)
./mvnw -q clean package
./mvnw -q testThis produces target/schemacraft-1.0-SNAPSHOT.jar (no external runtime deps).
-
Schemas & Types
Schemadefines an ordered set of columns (optionally a key column).- Built‑in types:
TypeInt=INTTypeVarchar(max)=VARCHAR(n)with fixed maximum length and padded binary layout.
- Add columns with helpers:
addIntType(name),addVarCharType(name, max), andaddKey*variants. - Utilities:
size(),getTupleSizeInBytes(),getColumnIndex(name),getType(i),getName(i).
-
Tables & Tuples
Tableholds a collection ofTuples for aSchema.- Core ops:
insert(Tuple),delete(key),lookup(key)(by key),lookup(colName, value)(by predicate),iterator(),size(). Tuplegives field‑level accessors:get(i),get(String),getInt(i),getString(i),set(i, value),getKey().
-
Relational Operations
Schema.project(String... attrs)→ new projectedSchema.Schema.naturaljoin(Schema other)→ combinedSchema(no key) for natural join.Tuple.project(Schema projected)andTuple.joinTuple(Schema joinSchema, Tuple t1, Tuple t2)offer row‑wise transforms.Table.lookup(col, value)returns a newTablewith matching tuples.
-
Binary Serialization
IType.readValue(ByteBuffer)/writeValue(Object, ByteBuffer)permit fixed‑width row serialization.Schema.serialize(ByteBuffer)andTuple.serialize(ByteBuffer)support compact storage.Constants.BLOCK_SIZE = 4096suggests page/block alignment for future storage engines.
-
Developer Ergonomics
Constants.MAX_COLUMN_NAME_LENGTH = 24andConstants.DEBUGflag.- Clean, minimal API — easy to extend with custom
ITypeimplementations.
- Add columns:
addIntType,addVarCharType,addKeyIntType,addKeyVarCharType - Inspect:
getKey,getColumnIndex,getType,getName,getMaxSQLSize,size,getTupleSizeInBytes - Algebra:
project(String[]),naturaljoin(Schema) - IO:
serialize(ByteBuffer) - toString(): human‑readable schema listing
- Lifecycle:
Table(Schema),close() - Mutation:
insert(Tuple),delete(key) - Query:
lookup(key),lookup(colName, value),iterator(),size() - toString(): pretty prints rows
- Construct:
Tuple(Schema, Object... values); validates arity and types - Access:
get(int),get(String),getInt(int),getString(int),set(int, Object),getKey() - Transform:
project(Schema),joinTuple(Schema, Tuple, Tuple) - IO:
serialize(ByteBuffer),deserialize(Schema, ByteBuffer)
String getColumnName();
int getMaxSizeBytes();
int getMaxSQLLength();
String getExternalName();
int getInternalType();
Object readValue(ByteBuffer buf);
void writeValue(Object value, ByteBuffer buf);- Fixed‑size
ByteBufferencoding;VARCHARpads/truncates tomaxbytes.
BLOCK_SIZE = 4096,MAX_COLUMN_NAME_LENGTH = 24,DEBUG
- Small demo showing schema creation, inserts, and
lookupby column/key.
Below is a minimal example using the public API:
import schemacraft.*;
public class Demo {
public static void main(String[] args) {
// 1) Define a schema with a key column and two attributes
Schema schema = new Schema();
schema.addKeyIntType("ID");
schema.addVarCharType("dept_name", 20);
schema.addVarCharType("building", 16);
// 2) Create a table and insert tuples
Table table = new Table(schema);
table.insert(new Tuple(schema, 19803, "Comp. Sci.", "SIG"));
table.insert(new Tuple(schema, 19901, "Comp. Sci.", "GHC"));
table.insert(new Tuple(schema, 20123, "Math", "Wean"));
// 3) Lookup by key and by non-key column
Table row = table.lookup(19803);
Table cs = table.lookup("dept_name", "Comp. Sci.");
// 4) Project columns
Schema proj = schema.project(new String[] {"dept_name"});
System.out.println(row);
System.out.println(cs);
System.out.println(proj);
}
}Compile & run your own demo (outside Maven build):
# compile (point to target jar if you also want to reuse build outputs)
javac -cp target/schemacraft-1.0-SNAPSHOT.jar Demo.java
java DemoJUnit 5 tests (e.g., tuple construction & schema validation):
./mvnw -q test