Versions Compared

Key

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


IDIEP-54
Author
Sponsor
Created

  

Status
Status
colourGrey
titleDRAFT

...

BinaryObject API should be reworked, as it will not represent actual serialized objects anymore. It should be replaced with something like BinaryRecord or DataRecord representing a record in a cache or table. Similarly Similar to the current binary objects, records will provide access to individual fields. A record can also be deserialized into a class with any subset of fields represented in the record.

Schema Definition API

There are several ways a schema can be defined. The initial entry point to the schema definition is SchemaBuilder java API:

TBD (see SchemaBuilders class for details)

The schema builder calls are transparently mapped to DDL statements so that all operations possible via a builder are also possible via DDL and vice versa.

Data restrictions

The Schema-first approach imposes certain natural requirements which are more strict than binary object serialization format:

  • The column type must be of one of a predefined set of available 'primitives' (including Strings, UUIDs, date & time values)
  • Arbitrary nested objects and collections are not allowed as column values. Nested POJOs should either be inlined into a schema or stored as BLOBs
  • Date & time values should be compressed with preserving natural order and decompression should be a trivial operation (like applying bitmask).

The suggested list of supported built-in data types is listed in the table below:

TypeSizeDescription
Bitmask(n)n/8 bytesA fixed-length bitmask of n bits
Int81 byte1-byte signed integer
Uint81 byte1-byte unsigned integer
Int162 bytes2-byte signed integer
Uint162 bytes2-byte unsigned integer
Int324 bytes4-byte signed integer
Uint324 bytes4-byte unsigned integer
Int648 bytes8-byte signed integer
Uint648 bytes8-byte unsigned integer
Float4 bytes4-byte floating-point number
Double8 bytes8-byte floating-point number
Number([n])VariableVariable-length number (optionally bound by n bytes in size)
DecimalVariableVariable-length floating-point number
UUID16 bytesUUID
StringVariableA string encoded with a given Charset
Date3 bytesA timezone-free date encoded as a year (1 sign bit + 14 bits), month (4 bits), day (5 bits)
Time5 bytesA timezone-free time encoded as padding (3 bits), hour (5 bits), minute (6 bits), second (6 bits), microseconds (20 bits)
Datetime8 bytesA timezone-free datetime encoded as (date, time)
Timestamp10 bytesNumber of microseconds since Jan 1, 1970 00:00:00.000000 (with no timezone)
BinaryVariableVariable-size byte array
Data Layout

Given a set of user-defined columns, this set is then rearranged so that fixed-sized columns go first. This sorted set of columns is used to form a row. Row layout is as follows:

Field

Size

Comments
Schema version2 bytes.

short number. The possible values are:

  • positive - regular row: key  and value chunks are present;
  • 0 - no value. If the flag is set, the value chunk is omitted, e.g. the row represents a tombstone or key-row to lookup by the key;
  • negative - invalid schema version.
Key columns hash4 bytes
Key chunk:

Key chunk size
4 bytes
Flags1 byte
Variable-length columns offsets table size0-2 bytes
  • Vartable is skipped (zero size) when the chunk contains one varlen column or doesn't contain varlen column.
  • 1 byte size for table with TINY format (see table below)
  • 2 bytes for table with MEDIUM and LARGE format (see table below)
Variable-length columns offsets tableVariable (number of non-null varlen columns * <format_size>)<format_size> - depends on the Flags field. See the table below
Fix-sized columns valuesVariable
Variable-length columns valuesVariable
Value chunk:

Value chunk size4 bytes
Flags1 byte
Null-map

(number of columns / 8 ) or 0 bytes

Zero size if and only if schema has no nullable columns
Variable-length  columns offsets table size2 or 0 bytes
  • Vartable is skipped (zero size) when the chunk contains one varlen column or doesn't contain varlen column.
  • 1 byte size for table with TINY format (see table below)
  • 2 bytes for table with MEDIUM and LARGE format (see table below)
Variable-length  columns offsets tableVariable (number of non-null varlen columns * <format_size>)<format_size> - depends on the Flags field. See the table below
Fix-sized columns valuesVariable
Variable-length columns valuesVariable

For the small rows, the metadata sizes may introduce a very noticeable overhead, so it looks reasonable to write them in a more compact way using different techniques.

  • VarInt - variable size integer for sizes
  • different VarTable formats with byte/short/int offsets
  • skip writing VarTable and/or Null-map if possible.

The flags field is used to detect the format. We propose 3 formats for a vartable: tiny, medium, and large with offset fields sizes of byte, short, and int respectively.
Vartable length field is the size of byte for tiny format and the size of short for others.
Vertable length is calculated as: <count_of _not_null_varlen_fields> - 1. The offset for the first varlen field is not stored at the table. It is calculated as the begin of the varlen values block.

IMPORTANT: having multiple formats MUST guarantee the key (as well as value) chunk will be always written in a single possible way to allow comparing chunks of rows of the same version as just byte arrays.

The flags field is a bitmask with each bit treated as a flag, with the following flags available (from flag 0 being the LSB to flag 7 being MSB):

Flags BitsDescription
0, 1

VarTable formats:

  • (0, 0) - SKIPPED.  VarTable for chunk is omitted  (all column values in the chunk either of fix-sized type or null);
  • (0, 1) - TINY format (1 byte for offset), format_size = 1;
  • (1, 0) - MEDIUM format (2 bytes for offset), format_size = 2;
  • (1, 1) - LARGE format (4 bytes for offset), format_size = 4
2-7Reserverd


Risks and Assumptions

n/a

Tickets

Jira
serverASF JIRA
columnskey,summary,type,created,updated,due,assignee,reporter,priority,status,resolution
maximumIssues20
jqlQueryproject=IGNITE and labels in (iep-54)
serverId5aa69414-a9e9-3523-82ec-879b028fb15b

Discussion Links

http://apache-ignite-developers.2346864.n4.nabble.com/IEP-54-Schema-first-approach-for-3-0-td49017.html

Reference Links

n/a

...

n/a