Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, HyperLogLogs, geospatial indexes with radius queries, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
Calcite’s Redis adapter allows you to query data in Redis using SQL, combining it with data in other Calcite schemas.
The Redis adapter allows querying of live data stored in Redis. Each Redis key-value pair is presented as a single row. Rows can be broken down into cells by using table definition files.
Redis string ,hash, sets, zsets, list value types are supported;
First, we need a model definition.
The model gives Calcite the necessary parameters to create an instance of the Redis adapter.
This query shows the result of the join query in a CSV format table csv_01 and a JSON format table json_02.
Here are a few details about the fields:
The keyDelimiter is used to split the value, the default is a colon, and the split value is used to map the field column. This only works for the CSV format.
The format key is used to specify the format of the data in Redis. Currently, it supports: "csv", "json", and "raw". The "raw" format keeps the original Redis key and value intact and only one field key is used for the query. The details are not described below.
The function of mapping is to map the columns of Redis to the underlying data. Since there is no concept of columns in Redis, the specific mapping method varies according to the format. For example, with "csv", we know that the CSV data will be formed after being parsed. The corresponding column mapping uses the index (subscript) of the underlying array. In the example above, EMPNO is mapped to index 0, NAME is mapped to index 1 and so on.
Currently the Redis adapter supports three formats: raw, JSON, and CSV.
Example: raw
The raw format maintains the original Redis key-value format with only one column key:
Example: JSON
The JSON format parses a Redis string value and uses the mapping to convert fields into multiple columns.
The schema contains mapping:
Example: CSV
The CSV format parses a Redis string value and combines the mapping in fields into multiple columns. The default separator is :.
The schema contains mapping:
Future plan:
More Redis features need to be further refined: for example HyperLogLog and Pub/Sub.