Variable types

Overview

All variables in Redivis have a type associated with them. All types in Redivis support NULL values; that is, an empty cell.

Supported types

String

A string can be used to store any textual data (UTF-8 encoded). Moreover, a string is a "universal" data type — any other type can be converted to a string without error.

Storage cost: 2 bytes + UTF-8 encoded string size (1 byte for ASCII characters).

Integer

A 64-bit signed integer. Supports any integer value between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807 .

Storage cost: 8 bytes per cell.

Float

A 64-bit (double precision) floating point decimal value.

Storage cost: 8 bytes per cell.

Boolean

A representation of either TRUE or FALSE

Storage cost: 1 byte per cell.

Date

Represents a calendar date independent of time zone. Supports any value between 0001-01-01 and 9999-12-31

Storage cost: 8 bytes per cell

Format:

'YYYY-[M]M-[D]D'

  • YYYY: Four digit year

  • [M]M: One or two digit month

  • [D]D: One or two digit day

All values in brackets are optional. If your Date is not in this format, you can convert it using format strings.

DateTime

Represents a year, month, day, hour, minute, second, and subsecond, independent of timezone. Supports any value between 0001-01-01 00:00:00 and 9999-12-31 23:59:59.999999

Storage cost: 8 bytes per cell

Format:

'YYYY-[M]M-[D]D[( |T)[H]H:[M]M:[S]S[.DDDDDD]]'
  • YYYY: Four digit year

  • [M]M: One or two digit month

  • [D]D: One or two digit day

  • ( |T): A space or a Tseparator

  • [H]H: One or two digit hour (valid values from 00 to 23)

  • [M]M: One or two digit minutes (valid values from 00 to 59)

  • [S]S: One or two digit seconds (valid values from 00 to 59)

  • [.DDDDDD]: Up to six fractional digits (i.e. up to microsecond precision)

All values in brackets are optional. If your DateTime is not in this format, you can convert it using format strings.

Time

Represents a time, independent of a specific date. Supports values between 00:00:00 and 23:59:59.999999

Storage cost: 8 bytes per cell

Format:

'[H]H:[M]M:[S]S[.DDDDDD]'
  • [H]H: One or two digit hour (valid values from 00 to 23)

  • [M]M: One or two digit minutes (valid values from 00 to 59)

  • [S]S: One or two digit seconds (valid values from 00 to 59)

  • [.DDDDDD]: Up to six fractional digits (i.e. up to microsecond precision)

All values in brackets are optional. If your Time is not in this format, you can convert it using format strings.

Conversion rules

Some types can be implicitly converted within a query (e.g., 1 (integer) < 2.2 (float)), in other circumstances, you will explicitly need to convert the type of a variable before performing certain operations (e.g., "1.0" (string) < 2.2 (float)).

Variable types can be converted within the transform interface in a project. The following conversions are supported:

From

To

Rule(s) when casting x

Integer

Float

Returns a close but potentially not exact FLOAT64 value.

Integer

Boolean

Returns FALSE if x is 0, TRUE otherwise.

Float

Integer

Returns the closest INT64 value. Halfway cases such as 1.5 or -0.5 round away from zero.

Float

String

Returns an approximate string representation.

Date

DateTime

Returns a DateTime at midnight on the corresponding date. For example, if x is 1970-01-01, returns 1970-01-01 00:00:00

DateTime

Date

Returns the part of the DateTime which is the calendar date. Note that this will not round the DateTime to the nearest Date. E.g., if x is 1970-01-01 23:59:59 , returns 1970-01-01 .

DateTime

Time

Returns the part of the DateTime which is the clock time. E.g., if x is 1970-01-01 23:59:59 , returns 23:59:59 .

Boolean

Integer

Returns 1 if x is TRUE, 0 otherwise.

Boolean

String

Returns "true" if x is TRUE, "false" otherwise.

String

Float

Returns x as a FLOAT64 value, interpreting it as having the same form as a valid FLOAT64 literal. Also supports casts from "inf", "+inf", "-inf", and "nan". Conversions are case-insensitive.

String

Boolean

Returns TRUE if x is "true" and FALSE if x is "false" All other values of x are invalid and throw an error instead of casting to BOOL. STRINGs are case-insensitive when converting to BOOL.

Format strings

Since there are a wide variety of mechanisms for specifying dates, date times, and times, it is common that calendar and temporal data will often be initially imported as a string unless the data complies with the canonical format for the respective type listed above.

However, by using format strings, you can specify how various fields are encoded within your data and convert to the appropriate type.

For example, to convert dates of mm/dd/yy format (common in the U.S.; e.g. 03/22/89 ), we would specify the format string %m/%d/%y . For a DateTime displayed as Mon Oct 17 2016 17:32:56 , we would specify %a %b %d %Y %H:%M:%S

A complete list of format elements and their meaning can be found below:

Format element

Description

%A

The full weekday name.

%a

The abbreviated weekday name.

%B

The full month name.

%b or %h

The abbreviated month name.

%C

The century (a year divided by 100 and truncated to an integer) as a decimal number (00-99).

%c

The date and time representation.

%D

The date in the format %m/%d/%y.

%d

The day of the month as a decimal number (01-31).

%e

The day of month as a decimal number (1-31); single digits are preceded by a space.

%F

The date in the format %Y-%m-%d.

%G

The ISO 8601 year with century as a decimal number. Each ISO year begins on the Monday before the first Thursday of the Gregorian calendar year. Note that %G and %Y may produce different results near Gregorian year boundaries, where the Gregorian year and ISO year can diverge.

%g

The ISO 8601 year without century as a decimal number (00-99). Each ISO year begins on the Monday before the first Thursday of the Gregorian calendar year. Note that %g and %y may produce different results near Gregorian year boundaries, where the Gregorian year and ISO year can diverge.

%H

The hour (24-hour clock) as a decimal number (00-23).

%I

The hour (12-hour clock) as a decimal number (01-12).

%j

The day of the year as a decimal number (001-366).

%k

The hour (24-hour clock) as a decimal number (0-23); single digits are preceded by a space.

%l

The hour (12-hour clock) as a decimal number (1-12); single digits are preceded by a space.

%M

The minute as a decimal number (00-59).

%m

The month as a decimal number (01-12).

%n

A newline character.

%P

Either am or pm.

%p

Either AM or PM.

%R

The time in the format %H:%M.

%r

The 12-hour clock time using AM/PM notation.

%S

The second as a decimal number (00-60).

%s

The number of seconds since 1970-01-01 00:00:00. Always overrides all other format elements, independent of where %s appears in the string. If multiple %s elements appear, then the last one takes precedence.

%T

The time in the format %H:%M:%S.

%t

A tab character.

%U

The week number of the year (Sunday as the first day of the week) as a decimal number (00-53).

%u

The weekday (Monday as the first day of the week) as a decimal number (1-7).

%V

The week number of the year (Monday as the first day of the week) as a decimal number (01-53). If the week containing January 1 has four or more days in the new year, then it is week 1; otherwise it is week 53 of the previous year, and the next week is week 1.

%W

The week number of the year (Monday as the first day of the week) as a decimal number (00-53).

%w

The weekday (Sunday as the first day of the week) as a decimal number (0-6).

%X

The time representation in HH:MM:SS format.

%x

The date representation in MM/DD/YY format.

%Y

The year with century as a decimal number.

%y

The year without century as a decimal number (00-99), with an optional leading zero. Can be mixed with %C. If %C is not specified, years 00-68 are 2000s, while years 69-99 are 1900s.

%%

A single % character.

%E#S

Seconds with # digits of fractional precision.

%E*S

Seconds with full fractional precision (a literal '*').

%E4Y

Four-character years (0001 ... 9999). Note that %Y produces as many characters as it takes to fully render the year.