Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Type Promotion

What happens when we multiply data of type BYTE with data of type INTEGER? RetractorDB follows strict type-promotion rules. Multiplying a BYTE-type field by a value of a field that is of type INTEGER produces a schema field of type INTEGER. This happens at compile time.

At present, RetractorDB supports the following data types:

TypeDescription
BYTEvalues 0–255
INTEGER4-byte values for signed numbers
UINTlike INTEGER, for unsigned numbers
RATIONALrational numbers
FLOATfloating-point numbers
DOUBLEdouble-precision floating-point numbers
STRINGcharacter strings

The STRING and RATIONAL types still need review, fixes, and test coverage. During development I focused my effort on number processing. In the future I want to add complex numbers and rational Eisenstein complex numbers to this set as well.

An example of type promotion in practice — the scaled query from the chapter Underscore Symbol Processing:

SELECT core0[_] * core1[_] \
STREAM scaled \
FROM core0 + core1

core0 has fields BYTE and INTEGER, core1 has fields INTEGER and FLOAT. After expanding _, the compiler determines the output fields’ types:

ExpressionLeft typeRight typeResult type
scaled[0] * scaled[2]BYTEINTEGERINTEGER
scaled[1] * scaled[3]INTEGERFLOATFLOAT