Websocket Spec
Data Access - Query Data via SQL
A WebSocket allows the client to request data using SQL as input.
Use the following URL to open a WebSocket connection. Depending on deployment, use ws (not-secure) or wss (secure) connection:
Once the connection is established, the server expects the client to send a JSON message with the following structure:
Login to Lenses to get the token. See Authentication API
token
Login token for lenses.
long
sql
The SQL query used to fetch data
string
live
If set, enables partial results for aggregation queries.
optional[boolean]
stats
Millis interval to receive query stats. If not provided the stats information is not sent
optional[int]
The client should wait for incoming messages and stop when EOF is received. The server sends JSON-encoded messages, the payload structure is:
Since there are multiple types of messages the server sends, the type
attribute determines the data structure for the data
payload. Below is the list of possible type
values:
HEARTBEAT
To keep the connection alive, the server injects an empty message.
RECORD
The message represents a data record.
ERROR
The message contains information about an error that occurred.
STATS
The message contains information about the current execution.Only activated if the stats
field in the request is present.
METADATA
The message contains a list of metadata fields each record message will contain. For example: offset, partition,timestamp, __keysize, __valueSize, valueSchemaId.
SCHEMA
Reserved.
PAGE_END
Reserved.
END
The message signals the end of the execution. The server will close the socket after this message is sent.
BADRECORD
The message contains information about the Kafka message which cannot be read. For example, if the topic expects Avro and the payload is not a valid Avro.
SENTINEL
The message contains information about the execution termination reason when query thresholds are reached.
Message types
Heartbeat
The data
the attribute is null. The client should ignore these messages.
Error
In this case, the payload structure is:
Stats
When requested the payload format is:
A possible payload can be:
Metadata
The payload format is:
End
The payload format is:
Bad Record
The payload format is:
Sentinel
The payload format is:
Record
Given the type
RECORD the payloads contains the data returned to the client, and it is dependent on the SQL input. The payload format is:
data.key
Returns the underlying Kafka message key value. Only applied when *
projection is used. When a key projection is used (i.e. _key.MMSI), the value is returned as data.value.MMSI
.
data.data
Will contain the output generated by the SQL projections. If *
is used for the SQL projection, it will return the Kafka message value structure.
data.metadata
Returned when no aggregations are involved. It contains the Kafka message partition, offset, byte size information
data.rownum
Reserved optional long value.
Examples
For a topic which contains nested data for both key and value.
The payload format is:
If the Kafka message key is null the response would be:
Projecting the key will not return the key
attribute:
produces the following output:
Aggregating data will not return the key
and metadata
attributes:
Last updated