> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-fbfa8bee.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> BSONEachRow 포맷 문서

# BSONEachRow

| 입력 | 출력 | 별칭 |
| -- | -- | -- |
| ✔  | ✔  |    |

<div id="description">
  ## 설명
</div>

`BSONEachRow` 포맷은 데이터 사이에 구분자 없이 연속된 Binary JSON(BSON) 문서 시퀀스로 데이터를 파싱합니다.
각 행은 하나의 문서로 포맷되며, 각 컬럼은 컬럼 이름을 키로 하는 BSON 문서의 단일 필드로 포맷됩니다.

<div id="data-types-matching">
  ## 데이터 유형 매핑
</div>

출력 시에는 ClickHouse 유형과 BSON 유형 사이에 다음과 같은 대응 관계를 사용합니다:

| ClickHouse 유형                                                                                 | BSON 유형                                                                                                            |
| --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| [Bool](/ko/reference/data-types/boolean)                                                      | `\x08` boolean                                                                                                     |
| [Int8/UInt8](/ko/reference/data-types/int-uint)/[Enum8](/ko/reference/data-types/enum)        | `\x10` int32                                                                                                       |
| [Int16/UInt16](/ko/reference/data-types/int-uint)/[Enum16](/ko/reference/data-types/enum)     | `\x10` int32                                                                                                       |
| [Int32](/ko/reference/data-types/int-uint)                                                    | `\x10` int32                                                                                                       |
| [UInt32](/ko/reference/data-types/int-uint)                                                   | `\x12` int64                                                                                                       |
| [Int64/UInt64](/ko/reference/data-types/int-uint)                                             | `\x12` int64                                                                                                       |
| [Float32/Float64](/ko/reference/data-types/float)                                             | `\x01` double                                                                                                      |
| [Date](/ko/reference/data-types/date)/[Date32](/ko/reference/data-types/date32)               | `\x10` int32                                                                                                       |
| [DateTime](/ko/reference/data-types/datetime)                                                 | `\x12` int64                                                                                                       |
| [DateTime64](/ko/reference/data-types/datetime64)                                             | `\x09` datetime                                                                                                    |
| [Decimal32](/ko/reference/data-types/decimal)                                                 | `\x10` int32                                                                                                       |
| [Decimal64](/ko/reference/data-types/decimal)                                                 | `\x12` int64                                                                                                       |
| [Decimal128](/ko/reference/data-types/decimal)                                                | `\x05` binary, `\x00` binary subtype, size = 16                                                                    |
| [Decimal256](/ko/reference/data-types/decimal)                                                | `\x05` binary, `\x00` binary subtype, size = 32                                                                    |
| [Int128/UInt128](/ko/reference/data-types/int-uint)                                           | `\x05` binary, `\x00` binary subtype, size = 16                                                                    |
| [Int256/UInt256](/ko/reference/data-types/int-uint)                                           | `\x05` binary, `\x00` binary subtype, size = 32                                                                    |
| [String](/ko/reference/data-types/string)/[FixedString](/ko/reference/data-types/fixedstring) | `\x05` binary, `\x00` binary subtype or \x02 string if setting output\_format\_bson\_string\_as\_string is enabled |
| [UUID](/ko/reference/data-types/uuid)                                                         | `\x05` binary, `\x04` uuid subtype, size = 16                                                                      |
| [Array](/ko/reference/data-types/array)                                                       | `\x04` array                                                                                                       |
| [Tuple](/ko/reference/data-types/tuple)                                                       | `\x04` array                                                                                                       |
| [Named Tuple](/ko/reference/data-types/tuple)                                                 | `\x03` document                                                                                                    |
| [Map](/ko/reference/data-types/map)                                                           | `\x03` document                                                                                                    |
| [IPv4](/ko/reference/data-types/ipv4)                                                         | `\x10` int32                                                                                                       |
| [IPv6](/ko/reference/data-types/ipv6)                                                         | `\x05` binary, `\x00` binary subtype                                                                               |

입력 시에는 BSON 유형과 ClickHouse 유형 사이에 다음과 같은 대응 관계를 사용합니다:

| BSON 유형                                  | ClickHouse 유형                                                                                                                                                                       |
| ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `\x01` double                            | [Float32/Float64](/ko/reference/data-types/float)                                                                                                                                   |
| `\x02` string                            | [String](/ko/reference/data-types/string)/[FixedString](/ko/reference/data-types/fixedstring)                                                                                       |
| `\x03` document                          | [Map](/ko/reference/data-types/map)/[Named Tuple](/ko/reference/data-types/tuple)                                                                                                   |
| `\x04` array                             | [Array](/ko/reference/data-types/array)/[Tuple](/ko/reference/data-types/tuple)                                                                                                     |
| `\x05` binary, `\x00` binary subtype     | [String](/ko/reference/data-types/string)/[FixedString](/ko/reference/data-types/fixedstring)/[IPv6](/ko/reference/data-types/ipv6)                                                 |
| `\x05` binary, `\x02` old binary subtype | [String](/ko/reference/data-types/string)/[FixedString](/ko/reference/data-types/fixedstring)                                                                                       |
| `\x05` binary, `\x03` old uuid subtype   | [UUID](/ko/reference/data-types/uuid)                                                                                                                                               |
| `\x05` binary, `\x04` uuid subtype       | [UUID](/ko/reference/data-types/uuid)                                                                                                                                               |
| `\x07` ObjectId                          | [String](/ko/reference/data-types/string)/[FixedString](/ko/reference/data-types/fixedstring)                                                                                       |
| `\x08` boolean                           | [Bool](/ko/reference/data-types/boolean)                                                                                                                                            |
| `\x09` datetime                          | [DateTime64](/ko/reference/data-types/datetime64)                                                                                                                                   |
| `\x0A` null value                        | [NULL](/ko/reference/data-types/nullable)                                                                                                                                           |
| `\x0D` JavaScript code                   | [String](/ko/reference/data-types/string)/[FixedString](/ko/reference/data-types/fixedstring)                                                                                       |
| `\x0E` symbol                            | [String](/ko/reference/data-types/string)/[FixedString](/ko/reference/data-types/fixedstring)                                                                                       |
| `\x10` int32                             | [Int32/UInt32](/ko/reference/data-types/int-uint)/[Decimal32](/ko/reference/data-types/decimal)/[IPv4](/ko/reference/data-types/ipv4)/[Enum8/Enum16](/ko/reference/data-types/enum) |
| `\x12` int64                             | [Int64/UInt64](/ko/reference/data-types/int-uint)/[Decimal64](/ko/reference/data-types/decimal)/[DateTime64](/ko/reference/data-types/datetime64)                                   |

다른 BSON 타입은 지원되지 않습니다. 또한 서로 다른 정수 타입 간 변환도 수행합니다.
예를 들어 BSON `int32` 값은 ClickHouse의 [`UInt8`](/ko/reference/data-types/int-uint)로 삽입할 수 있습니다.

`Int128`/`UInt128`/`Int256`/`UInt256`/`Decimal128`/`Decimal256`와 같은 큰 정수와 Decimal 값은 `\x00` binary subtype의 BSON Binary 값에서 파싱할 수 있습니다.
이 경우 이 포맷은 binary 데이터의 크기가 예상되는 값의 크기와 같은지 검증합니다.

<Note>
  이 포맷은 Big-Endian 플랫폼에서 올바르게 작동하지 않습니다.
</Note>

<div id="example-usage">
  ## 사용 예시
</div>

<div id="inserting-data">
  ### 데이터 삽입
</div>

다음 데이터가 포함된 BSON 파일 `football.bson`을 사용합니다:

```text theme={null}
    ┌───────date─┬─season─┬─home_team─────────────┬─away_team───────────┬─home_team_goals─┬─away_team_goals─┐
 1. │ 2022-04-30 │   2021 │ Sutton United         │ Bradford City       │               1 │               4 │
 2. │ 2022-04-30 │   2021 │ Swindon Town          │ Barrow              │               2 │               1 │
 3. │ 2022-04-30 │   2021 │ Tranmere Rovers       │ Oldham Athletic     │               2 │               0 │
 4. │ 2022-05-02 │   2021 │ Port Vale             │ Newport County      │               1 │               2 │
 5. │ 2022-05-02 │   2021 │ Salford City          │ Mansfield Town      │               2 │               2 │
 6. │ 2022-05-07 │   2021 │ Barrow                │ Northampton Town    │               1 │               3 │
 7. │ 2022-05-07 │   2021 │ Bradford City         │ Carlisle United     │               2 │               0 │
 8. │ 2022-05-07 │   2021 │ Bristol Rovers        │ Scunthorpe United   │               7 │               0 │
 9. │ 2022-05-07 │   2021 │ Exeter City           │ Port Vale           │               0 │               1 │
10. │ 2022-05-07 │   2021 │ Harrogate Town A.F.C. │ Sutton United       │               0 │               2 │
11. │ 2022-05-07 │   2021 │ Hartlepool United     │ Colchester United   │               0 │               2 │
12. │ 2022-05-07 │   2021 │ Leyton Orient         │ Tranmere Rovers     │               0 │               1 │
13. │ 2022-05-07 │   2021 │ Mansfield Town        │ Forest Green Rovers │               2 │               2 │
14. │ 2022-05-07 │   2021 │ Newport County        │ Rochdale            │               0 │               2 │
15. │ 2022-05-07 │   2021 │ Oldham Athletic       │ Crawley Town        │               3 │               3 │
16. │ 2022-05-07 │   2021 │ Stevenage Borough     │ Salford City        │               4 │               2 │
17. │ 2022-05-07 │   2021 │ Walsall               │ Swindon Town        │               0 │               3 │
    └────────────┴────────┴───────────────────────┴─────────────────────┴─────────────────┴─────────────────┘
```

데이터를 삽입하세요:

```sql theme={null}
INSERT INTO football FROM INFILE 'football.bson' FORMAT BSONEachRow;
```

<div id="reading-data">
  ### 데이터 읽기
</div>

`BSONEachRow` 포맷으로 데이터를 읽습니다:

```sql theme={null}
SELECT *
FROM football INTO OUTFILE 'docs_data/bson/football.bson'
FORMAT BSONEachRow
```

<Tip>
  BSON은 터미널에서 사람이 읽을 수 있는 형태로 표시되지 않는 바이너리 형식입니다. BSON 파일로 출력하려면 `INTO OUTFILE`을 사용하세요.
</Tip>

<div id="format-settings">
  ## 포맷 설정
</div>

| 설정                                                                                                                                                                                    | 설명                                                     | 기본값     |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ | ------- |
| [`output_format_bson_string_as_string`](/ko/reference/settings/formats#output_format_bson_string_as_string)                                                                           | String 컬럼에 대해 Binary 대신 BSON String 타입을 사용합니다.         | `false` |
| [`input_format_bson_skip_fields_with_unsupported_types_in_schema_inference`](/ko/reference/settings/formats#input_format_bson_skip_fields_with_unsupported_types_in_schema_inference) | BSONEachRow 포맷의 스키마 추론 중 지원되지 않는 타입의 컬럼을 스키핑하도록 허용합니다. | `false` |
