stupidb.core

StupiDB. The stupidest database you’ll ever come across.

This is project designed to illustate the concepts that underly a typical relational database implementation, starting at naive execution of table-stakes features up to rule-based query optimization.

Warning

Please do not use this for any other reason than learning. There are no guarantees here except that there will be bugs.

Classes

Aggregation(child, metrics)

A relation representing aggregation of columns.

CrossJoin(left, right)

Difference(left, right)

Unique difference between two relations.

DifferenceAll(left, right)

Non-unique difference between two relations.

GroupBy(child, group_by)

A relation representing a partitioning of rows by a key.

InnerJoin(left, right, predicate)

Intersect(left, right)

Intersection of two relations.

IntersectAll(left, right)

Non-unique intersection between two relations.

Join(left, right)

LeftJoin(left, right, predicate)

Limit(child, *, offset, limit)

Mutate(child, projections)

A relation representing appending columns to an existing relation.

Projection(child, projections)

A relation representing column selection.

Relation()

An abstract relation.

RightJoin(left, right, predicate)

Selection(child, predicate)

A relation of rows selected based on a predicate.

SetOperation(left, right)

An abstract set operation.

SortBy(child, order_by, null_ordering)

A relation representing rows of its child sorted by one or more keys.

Table(rows)

Union(left, right)

Union between two relations.

UnionAll(left, right)

Non-unique union between two relations.

class stupidb.core.Aggregation(child, metrics)[source]

A relation representing aggregation of columns.

class stupidb.core.CrossJoin(left, right)[source]
class stupidb.core.Difference(left, right)[source]

Unique difference between two relations.

class stupidb.core.DifferenceAll(left, right)[source]

Non-unique difference between two relations.

class stupidb.core.GroupBy(child, group_by)[source]

A relation representing a partitioning of rows by a key.

group_by

A callable that takes an AbstractRow and returns an instance of typing.Hashable.

class stupidb.core.InnerJoin(left, right, predicate)[source]
class stupidb.core.Intersect(left, right)[source]

Intersection of two relations.

class stupidb.core.IntersectAll(left, right)[source]

Non-unique intersection between two relations.

class stupidb.core.Join(left, right)[source]
class stupidb.core.LeftJoin(left, right, predicate)[source]
class stupidb.core.Limit(child, *, offset, limit)[source]
class stupidb.core.Mutate(child, projections)[source]

A relation representing appending columns to an existing relation.

class stupidb.core.Projection(child, projections)[source]

A relation representing column selection.

child
aggregations
projections
class stupidb.core.Relation[source]

An abstract relation.

class stupidb.core.RightJoin(left, right, predicate)[source]
class stupidb.core.Selection(child, predicate)[source]

A relation of rows selected based on a predicate.

predicate

A callable that takes an AbstractRow and returns a bool.

class stupidb.core.SetOperation(left, right)[source]

An abstract set operation.

static itemize(mappings)[source]

Return a hashable version of mappings.

class stupidb.core.SortBy(child, order_by, null_ordering)[source]

A relation representing rows of its child sorted by one or more keys.

order_by

A callable that takes an AbstractRow and returns an instance of Comparable.

null_ordering

Whether to place the nulls of a column first or last.

class stupidb.core.Table(rows)[source]
class stupidb.core.Union(left, right)[source]

Union between two relations.

class stupidb.core.UnionAll(left, right)[source]

Non-unique union between two relations.