This section describes the data types which Couchbase Analytics can operate on.
An instance of Couchbase Analytics data model can be a primitive type (BOOLEAN
, STRING
, BIGINT
, or
DOUBLE
), a special type (NULL
or MISSING
), or a composite type (OBJECT
, ARRAY
, or MULTISET
).
The type names are case-insensitive, e.g., both BIGINT
and bigint
are acceptable.
Primitive Types
Boolean
boolean
data type can have one of the two values: *true* or *false*.
-
Example:
{ "true": true, "false": false };
-
The expected result is:
{ "true": true, "false": false }
String
string
represents a sequence of characters. The total length of the sequence can be up to 2,147,483,648.
-
Example:
{ "v1": string("This is a string."), "v2": string("\"This is a quoted string\"") };
-
The expected result is:
{ "v1": "This is a string.", "v2": "\"This is a quoted string\"" }
Bigint
Bigint type uses 64 bits. The range of Bigint is:
-
bigint
: -9223372036854775808 to 9223372036854775807 -
Example:
{ "bigint": bigint("1700000000000000000") };
-
The expected result is:
{ "bigint": 1700000000000000000 }
All integers in the incoming JSON are parsed as bigint values.
|
Double (double precision)
double
represents approximate numeric data values using 8 bytes. The range of a double value can be from (2^(-1022)) to (2-2^(-52))·2^(1023)
for both positive and negative. Beyond these ranges will get INF
or -INF
.
-
Example:
{ "v1": double("NaN"), "v2": double("INF"), "v3": double("-INF"), "v4": "-2013.593823748327284" };
-
The expected result is:
{ "v1": "NaN", "v2": "INF", "v3": "-INF", "v4": -2013.5938237483274 }
Double precision
is an alias of double
.
All numbers in the incoming JSON which are not integers are parsed as double values.
|
Incomplete Information Types
Null
null
is a special value that is often used to represent an unknown value.
For example, a user might not be able to know the value of a field and let it be null
.
-
Example:
{ "field": null };
-
The expected result is:
{ "field": null }
Missing
missing
indicates that a name-value pair is missing from an object.
If a missing name-value pair is accessed, an empty result value is returned by the query.
As neither the data model nor the system enforces homogeneity for datasets or collections,
items in a dataset or collection can be of heterogeneous types and
so a field can be present in one object and missing
in another.
-
Example:
{ "field": missing };
-
The expected result is:
{ }
Since a field with value missing
means the field is absent, we get an empty object.
A missing value is converted to null when converted to JSON in the query results.
|
Composite Types
Object
An object
(a.k.a., JSON object) contains a set of fields, where each field is described by
its name.
Syntactically, object constructors are surrounded by curly braces "{…}". For example:
{ "name": "Joe Blow", "rank": "Sergeant", "serialno": 1234567 } { "rank": "Private", "serialno": 9876543 } { "name": "Sally Forth", "rank": "Major", "serialno": 2345678, "gender": "F" }
Array
An array
is a container that holds a fixed number of values.
An array
is an ordered collection of items.
Array constructors are denoted by brackets: "[…]".
An example would be
["alice", 123, "bob", null]
An array can appear in the incoming JSON and can be constructed by the query. Each SELECT statement with an ORDER BY clause returns an array .
|
Multiset
A multiset
is an unordered collection of items.
A multiset
allows multiple instances of its elements.
A multiset cannot appear in the incoming JSON. A multiset is converted into a JSON array with an undefined order of elements in the query results. The order of the items in the result might change from one query execution to another. Each SELECT statement without an ORDER BY clause returns a multiset .
|