Lindorm Cassandra Query Language (CQL) supports JSON in SELECT and INSERT statements. Support on the JSON format does not change the manner in which the Lindorm CQL API is used. For example, you must define a schema for your database when you use the Lindorm CQL API even if the JSON format is supported. The JSON format only provides a method to work with JSON documents. Lindorm CQL can be used to write or display the data of multiple columns in the JSON format.
SELECT JSON
You can specify the JSON keyword in a SELECT statement. In this case, the SELECT statement returns the data of each row as a JSON-encoded map. The remainder of the behavior for the SELECT statement remains unchanged.
The result `map keys are the same as the column names in a regular result set. For
example, after you execute the SELECT JSON a,b FROM ... statement, a map that contains the a and b keys is returned.
INSERT JSON
You can specify the JSON keyword in an INSERT statement. In this case, the INSERT
statement is used to insert a JSON-encoded map as a row. In most cases, the format
of the JSON map must match the format of the result set that is returned by a SELECT
JSON statement executed on the same table. Take note that case-sensitive column names
must be enclosed in double quotation marks ("). For example, you can execute the following
statement to insert a JSON map into a table that contains the myKey and value columns:
INSERT INTO persioninfo JSON '{ "c1": "key", "c2": "value"}'By default, columns that are not specified in a JSON map are set to NULL. This rule also applies when the default value NULL is explicitly specified. This way, all existing values of the columns that are not specified are removed.
JSON Encoding of CQL Data Types
In some cases, Lindorm CQL represents and accepts data types in the native JSON format. Lindorm CQL also accepts string representations that match the text format of Lindorm CQL for all single-field types. For example, float values, integers, UUIDs, and dates can be represented by Lindorm CQL text strings.
| JSON data type | Accepted data type | Returned data type | Description |
|---|---|---|---|
| ascii | string | string | The string for which the \u JSON escaping character is used.
|
| bigint | integer, string | integer | The string must be a valid 64-bit integer. |
| blob | string | string | The string must be an even number of hexadecimal digits that are prefixed with 0x. |
| boolean | boolean, string | boolean | Valid values: true and false.
|
| date | string | string | The string that contains a date in the YYYY-MM-DD format. The date is displayed in UTC.
|
| decimal | integer, float, string | float | The precision may exceed that of a 32-bit or 64-bit IEEE-754 floating point number. |
| double | integer, float, string | float | The string must represent a valid integer or a floating-point number. |
| float | integer, float, string | float | The string must represent a valid integer or a floating-point number. |
| inet | string | string | The IPv4 or IPv6 address. |
| int | integer, string | integer | The string must represent a 32-bit integer. |
| smallint | integer, string | integer | The string must represent a 16-bit integer. |
| text | string | string | The string for which the \u JSON escaping character is used.
|
| time | string | string | The string that contains a time in the hh-mm-ss[.fffffffff] format.
|
| timestamp | integer, string | string | The timestamp. The string can represent a timestamp in the YYYY-MM-DD hh:mm:ss.SSS format.
|
| timeuuid | string | string | The Type 1 UUID. |
| tinyint | integer, string | integer | The string must be a valid 8-bit integer. |
| uuid | string | string | The string in the UUID format. |
| varint | integer, string | integer | The integer with variable length. An integer overflow may occur when a 32-bit or 64-bit integer is transferred to a client-side decoder. |