GreptimeTeam / greptimedb

An open-source, cloud-native, unified time series database for metrics, logs and events with SQL/PromQL supported. Available on GreptimeCloud.
https://greptime.com/
Apache License 2.0
4.36k stars 315 forks source link

Supports JSON format #3686

Open WenyXu opened 7 months ago

WenyXu commented 7 months ago

What problem does the new feature solve?

Supports inserting/querying JSON data.

What does the feature do?

Support for JSON data format will be divided into several stages:

  1. Add necessary data type support, including Lists and Nested data
  2. Supports inserting JSON data
  3. Supports querying JSON data
  4. Supports Schemaless JSON

Implementation challenges

See also:

WenyXu commented 7 months ago

As mentioned in https://github.com/apache/datafusion/issues/7845#issuecomment-2068061465, I was greatly inspired by JSONA and proposed a JSONA variant(Maybe we can call it JSONC, JSON for columnar storage formats😙) that may benefit from the high compression rates of columnar storage formats. BTW, If we decide to implement our own JSON storage implementation, It's definitely an excellent opportunity to evaluate various storage implementations of JSON in the OLAP scenario.

A naive proposal of JSONA variant.

For JSON [false, 10, {"k":"v"}, null] can be stored as the following struct.

Struct {
    Nodes: [StartArray, FALSE, Number, StartObject, Key, String, EndObject, NULL, EndArray]
    Offsets: [NULL, NULL, 0, NULL, 0, 0, NULL,…]
    Keys: ["k"]
    Strings: ["v"]
    Numbers: [10]
}

The Struct data can be efficiently encoded into compact files using the underlying file format. In our scenario, we use the Parquet as the underlying file format. For instance, the Nodes field can be represented as UINT8 and efficiently encoded using default dictionary encoding.