Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The field location information is represented as a table of field offsets. This table allows to determine both the offset and the length of each field.

To represent NULL values a tuple may contain a nullmap. Nullmap is skipped if there are no actual NULL values in a given tuple.To be more precise the layout of a tuple looks like this:

  1. Header;
  2. Nullmap (optionally);
  3. Offset table;
  4. Value area.

Header

It contains only one byte with flags.

Bits 0-1: Size class of the variable-length area.

Bit 2: Set if the nullmap is presentFlag indicating that the size class is not optimal.

Size class encodes the number of bytes used for entries in the offset table. It is encoded like this:

...

NOTE: By the way, the last option works fine for C++ and possibly other languages but for Java it will be hard to support, so it might be excluded.

Nullmap

If a schema has nullable columns then the corresponding tuple may contain a nullmap. The nullmap is skipped if there are no actual NULL values in a given tuple instance.

Offset Table

The number of elements in the table is equal to Nullmap is a bitset that contains N bits, occupies (N + 7) / 8 bytes, where `N` is the number of columns in the schema.

In the bitset if a bit is set to `1` then the respective field is NULL.

Offset Table

The number of elements in the table is equal to the number of columns in the schema.

The size of table The size of table elements might be 1, 2, 4, or 8 bytes depending on the header flags.

Each element in the table specifies where the corresponding field ends. Or in In other words, for each given field the table stores the offset where the next field starts. The last element in the table specifies the end of the last field and at the same time the end of the whole value area and consequently the end of the entire tuple.

...

If a value is equal to NULL then it is absent in the value area. This means that in the offset table the corresponding entry is equal to the previous entry. At the same time the corresponding bit in the nullmap is set.

For any some variable-length type types we can encounter a value with zero length. Quite naturally To distinguish a zero-length variable-length value translates to a zero-length field in a tuple. This approach is extended to fixed-size types by introducing a notion of default values. We define specific default values for different types (specified in the table below). If a given value is equal to the corresponding default value then this translates to a zero-length field in a tuple.

To sum things up, when a zero-length field is met (by looking in the offset table) we have the following cases:

...

from a null value we use a special magic byte that denotes an empty value. That is an empty value is encoded as single-byte sequence – 0x80. In turn if the original variable-length value starts with the magic byte 0x80 byte then this byte is doubled.

The Number and Decimal types are never empty, at least one significant byte is always present. The variable-length types that use the magic byte for encoding are as follows:

  • String;
  • Binary;
  • Bitmask

...

  • .

The list of supported data types is as follows:

0 0.0 0 empty bit-string

Jan 1, 1 BC  (1 BC is immediately

before 1 AD in the Gregorian calendar)0  (PT0S)0  (P0D)false 
TypeField SizeDefault ValueDescription
Int810 1-byte signed integer
Int161, 20 2-byte signed integer, but may occupy less space due to compression mechanism described below

Int32

1, 2, 40 4-byte signed integer, but may occupy less space due to compression mechanism described below
Int641, 2, 4, 88-byte signed integer, but may occupy less space due to compression mechanism described below
Float444-byte floating-point number
Double4, 80.0 8-byte floating-point number, but may occupy 4 bytes if fits into float w/o loss of precision
NumbervariableVariable-length integer
Decimalvariable 0 Variable-length fixed-point number, the scale is determined by the schema
UUID1600000000-0000-0000-0000-000000000000UUID
Stringvariableempty stringAn utf-8 encoded string
Binaryvariableempty binaryVariable-length arbitrary binary data
BitmaskvariableVariable-length binary data representing a bit-string
Date33A timezone-free date (a year, month, day)
Time4, 5, 600:00:00.000000 A timezone-free time (hour, minute, second, microseconds)
DateTime7, 8, 9Jan 1, 1 BC, 00:00:00.000000 A timezone-free datetime encoded as (date, time)
Timestamp8, 12Jan 1, 1970, 00:00:00.000000 Number of microseconds since Jan 1, 1970 00:00:00.000000 (with no timezone)
Duration8, 12See below
Period3, 6, 12See below
Boolean1A boolean value (either true  of false)

Integer Representation

All integer values are stored in the little-endian byte order.

...