Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add docs for data model and encoding #1535

Merged
merged 2 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions docs/data-model-and-encoding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Data Model and Encoding

## Data Model

> Source files: `common/src/types`

RisingWave adapts a relational data model with extensive support for semi-structured data. Relational tables, including tables and materialized views, consist of a list of named, strong-typed columns.

Tables created by users have an implicit, auto-generated row-id column as their primary key; while for materialized views, the primary key is derived from queries. For example, the primary key of an aggregation (group-by) materialized view is the specified group keys.

`NULL` values mean missing or unknown fields. Currently, all columns are implicitly nullable.

Primitive data types:

- Integers: `SMALLINT` (16-bit), `INT` (32-bit), `BIGINT` (64-bit)
- Booleans: `BOOLEAN`
- Decimals: `NUMERIC`
- Floating-point numbers: `FLOAT`, `DOUBLE`
- Date & Time: `DATE`, `TIME`, `TIMESTAMP`, `TIMESTAMPZ` (timestamp without timezone)
- Time Interval: `INTERVAL`
- Strings: `VARCHAR`, `CHAR`

Composite data types (WIP):

- `Struct`: A structure with a list of named, strong-typed fields.
- `List`: A variable-length list of values with same data type

## In-Memory Encoding

> Source files: `common/src/array`

In-memory data is encoded in arrays for vectorized execution. For variable-length data like strings, generally we use another offset array to mark the start of encoded values in a byte buffer.

A Data Chunk consists of multiple columns and a visibility array to mark each row as visible or not, which helps filtering some rows while keeping other data arrays unchanged.

A Stream Chunk consists of columns, visibility array and an additional `ops` column to mark the operation of row, which can be one of `Delete`, `Insert`, `UpdateDelete` and `UpdateInsert`.

![chunk](./images/data-model-and-encoding/chunk.svg)

## On-Disk Encoding

> Source files: `utils/memcomparable`, `utils/value-encoding`

RisingWave stores user data in shared key-value storage called 'Hummock'. Tables, materialized views and checkpoints of internal streaming operators are encoded into key-value entries. Every field of a row aka. cell is encoded as a key-value entry, except `NULL` values are omitted.

![row-format](./images/data-model-and-encoding/row-format.svg)

Considering that ordering matters in some cases like result set of an order-by query, fields of keys must preserve the order of original values after being encoded into bytes. This is what `memcomparable` for. For example, integers must be encoded in big-endien and the sign bit must be flipped to perserve order. In contrast, the encoding of values does not need to preserve order.



4 changes: 4 additions & 0 deletions docs/images/data-model-and-encoding/chunk.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading