Data Types

Input Parameter Types

When parameters are passed into JavaScript UDFs, Rockset values will be converted to JavaScript values according to their types, as follows:

Rockset Data TypeJavascript TypeRemarks
NULLnull
UNDEFINEDnullNote that this is not mapped to JavaScript undefined. You can use JavaScript undefined to detect that your function was called with fewer arguments than specified.
intnumberNote that this will result in loss of precision for values ≥ 2^53. If you want to handle large integers up to int64, see instructions regarding BigInt below.
intBigIntWhen function property input_convert_int64_to_bigint is set to true
floatnumber
stringstring
boolboolean or numberThe parameter value could be a JavaScript boolean or a JavaScript number and will evaluate to “true” or “false” when used in a boolean expression.
objectobject
objectMapWhen function property input_convert_object_to_map is set to true
arrayarray or TypedArrayNote that a Rockset array consisting solely of booleans may be converted to Uint8Array.
dateDate
timeDate
datetimeDate
timestampDate

Special Properties for Input Parameters

You can optionally do the following data type conversions on the JavaScript UDF input parameters by setting certain properties on the function definition:

  • int64BigInt
    • Set the property input_convert_int64_to_bigint = true
  • objectMap
    - Set the property input_convert_object_to_map = true
    For example:
script {{{

export function echo(n) { return n }

echo.input_convert_int64_to_bigint = true

}}}

SELECT _script.echo(9223372036854775807);

The above function will return the correct value 9223372036854775807 since the Rockset datatype will get mapped to BigInt.

If input_convert_int64_to_bigint was not set to true, then the SQL above will return 9223372036854776000 instead, since JavaScript numbers lose precision beyond 2^53.

Output Return Types

JavaScript values returned by the UDF will be converted into Rockset values according to their types, as follows:

Javascript TypeRockset Data TypeRemarks
nullNULL
undefinedNULLNote that this is not Rockset UNDEFINED
numberint or floatBased on whether value is integral or not. It will always return a Rockset float when function property output_always_convert_number_to_float is set to true.
BigIntint or errorNote that Rockset int data type are signed 64-bit integers. If value returned in JavaScript BigInt doesn’t fit in Rockset int, an error will be thrown.
stringstring
booleanbool
plain JS objectobjectThe Rockset object will contain all enumerable, non-Symbol keys from the JS object. If either of these keys or their corresponding values cannot be converted to Rockset types, an error will be thrown.
Mapobject
Setarray
arrayarray
TypedArrayarrayExcept Uint8Array, see below.
Uint8Arrayarray of boolNote that the values in the JavaScript Uint8Array are interpreted as boolean instead of number.
Datetimestamp

Special Properties for Output Return Types

You can optionally do the following data type conversions on the JavaScript UDF return values by setting certain properties on the function definition:

  • number -> float
    • Set the property output_always_convert_number_to_float = true

For Example:

script {{{

export function echo(n) { return n }

echo.output_always_convert_number_to_float = true

}}}

SELECT typeof(_script.echo(10));

The above function will return float. But if output_always_convert_number_to_float was not set to true, then it will return int.