BSONEachRow
| Input | Output | Alias | 
|---|---|---|
| ✔ | ✔ | 
Description
The BSONEachRow format parses data as a sequence of Binary JSON (BSON) documents without any separator between them.
Each row is formatted as a single document and each column is formatted as a single BSON document field with the column name as a key.
Data Types Matching
For output it uses the following correspondence between ClickHouse types and BSON types:
| ClickHouse type | BSON Type | 
|---|---|
| Bool | \x08boolean | 
| Int8/UInt8/Enum8 | \x10int32 | 
| Int16/UInt16/Enum16 | \x10int32 | 
| Int32 | \x10int32 | 
| UInt32 | \x12int64 | 
| Int64/UInt64 | \x12int64 | 
| Float32/Float64 | \x01double | 
| Date/Date32 | \x10int32 | 
| DateTime | \x12int64 | 
| DateTime64 | \x09datetime | 
| Decimal32 | \x10int32 | 
| Decimal64 | \x12int64 | 
| Decimal128 | \x05binary,\x00binary subtype, size = 16 | 
| Decimal256 | \x05binary,\x00binary subtype, size = 32 | 
| Int128/UInt128 | \x05binary,\x00binary subtype, size = 16 | 
| Int256/UInt256 | \x05binary,\x00binary subtype, size = 32 | 
| String/FixedString | \x05binary,\x00binary subtype or \x02 string if setting output_format_bson_string_as_string is enabled | 
| UUID | \x05binary,\x04uuid subtype, size = 16 | 
| Array | \x04array | 
| Tuple | \x04array | 
| Named Tuple | \x03document | 
| Map | \x03document | 
| IPv4 | \x10int32 | 
| IPv6 | \x05binary,\x00binary subtype | 
For input it uses the following correspondence between BSON types and ClickHouse types:
| BSON Type | ClickHouse Type | 
|---|---|
| \x01double | Float32/Float64 | 
| \x02string | String/FixedString | 
| \x03document | Map/Named Tuple | 
| \x04array | Array/Tuple | 
| \x05binary,\x00binary subtype | String/FixedString/IPv6 | 
| \x05binary,\x02old binary subtype | String/FixedString | 
| \x05binary,\x03old uuid subtype | UUID | 
| \x05binary,\x04uuid subtype | UUID | 
| \x07ObjectId | String/FixedString | 
| \x08boolean | Bool | 
| \x09datetime | DateTime64 | 
| \x0Anull value | NULL | 
| \x0DJavaScript code | String/FixedString | 
| \x0Esymbol | String/FixedString | 
| \x10int32 | Int32/UInt32/Decimal32/IPv4/Enum8/Enum16 | 
| \x12int64 | Int64/UInt64/Decimal64/DateTime64 | 
Other BSON types are not supported. Additionally, it performs conversion between different integer types.
For example, it is possible to insert a BSON int32 value into ClickHouse as UInt8.
Big integers and decimals such as Int128/UInt128/Int256/UInt256/Decimal128/Decimal256 can be parsed from a BSON Binary value with the \x00 binary subtype.
In this case, the format will validate that the size of the binary data equals the size of the expected value.
This format does not work properly on Big-Endian platforms.
Example Usage
Format Settings
| Setting | Description | Default | 
|---|---|---|
| output_format_bson_string_as_string | Use BSON String type instead of Binary for String columns. | false | 
| input_format_bson_skip_fields_with_unsupported_types_in_schema_inference | Allow skipping columns with unsupported types while schema inference for format BSONEachRow. | false | 
