Lindorm Cassandra Query Language (CQL) supports JSON in SELECT and INSERT statements. JSON support does not change how the Lindorm CQL API works — you still define a schema, and the JSON format simply provides a way to read and write column data as JSON documents.
SELECT JSON
Add the JSON keyword to a SELECT statement to return each row as a JSON-encoded map.
SELECT JSON a, b FROM <table_name>;The map keys match the column names in a regular result set. For example, the statement above returns a map with the keys "a" and "b".
INSERT JSON
Add the JSON keyword to an INSERT statement to insert a JSON-encoded map as a row. The JSON map format must match the result set format that SELECT JSON returns for the same table. Enclose case-sensitive column names in double quotation marks (").
INSERT INTO persioninfo JSON '{ "c1": "key", "c2": "value"}'By default, columns not included in the JSON map are set to null, and any existing values for those columns are removed.
JSON encoding of CQL data types
Lindorm CQL represents and accepts most data types in their native JSON format, and also accepts string representations for all single-field types (for example, float values, integers, UUIDs, and dates can be represented as CQL text strings).
The following table describes the JSON types that Lindorm CQL accepts in INSERT JSON statements and fromJson() calls, and the types it returns in SELECT JSON statements and toJson() calls.
| CQL data type | Accepted JSON type | Returned JSON type | Description |
|---|---|---|---|
| ascii | string | string | Uses \u JSON escape sequences. |
| bigint | integer, string | integer | String must be a valid 64-bit integer. |
| blob | string | string | String must be an even number of hexadecimal digits prefixed with 0x. |
| boolean | boolean, string | boolean | Valid string values: true and false. |
| date | string | string | Date in YYYY-MM-DD format, displayed in UTC. |
| decimal | integer, float, string | float | Precision may exceed that of a 32-bit or 64-bit IEEE 754 floating-point number. |
| double | integer, float, string | float | String must represent a valid integer or floating-point number. |
| float | integer, float, string | float | String must represent a valid integer or floating-point number. |
| inet | string | string | IPv4 or IPv6 address. |
| int | integer, string | integer | String must represent a 32-bit integer. |
| smallint | integer, string | integer | String must represent a 16-bit integer. |
| text | string | string | Uses \u JSON escape sequences. |
| time | string | string | Time in hh-mm-ss[.fffffffff] format. |
| timestamp | integer, string | string | String in YYYY-MM-DD hh:mm:ss.SSS format. |
| timeuuid | string | string | Type 1 UUID. |
| tinyint | integer, string | integer | String must be a valid 8-bit integer. |
| uuid | string | string | UUID format. |
| varint | integer, string | integer | Variable-length integer. Integer overflow may occur when a 32-bit or 64-bit integer is transferred to a client-side decoder. |