# MessagePack Parser関数

Treasure DataのData Connector用`msgpack` Parserプラグインは、MessagePackデータを解析します。以下のオプションを使用できます:

| **オプション** | **説明** |
|  --- | --- |
| `row_encoding` | 行のタイプ。"array"または"map" (enum、デフォルト: map) |
| `file_encoding` | ファイルに大きな配列が含まれている場合は"array"を設定します。それ以外で、ファイルに一連の行が含まれている場合は"sequence"を設定します (enum、デフォルト: sequence) |
| `columns` | カラム (スキーマ、必須) |


`columns`オプションは、カラムのリストを宣言します。このMessagePack Parserプラグインは、ヘッダー行を無視します。

| **オプション** | **説明** |
|  --- | --- |
| `index` | カラムのインデックス番号 (オプション) |
| `name` | カラムの名前 |
| `type` | カラムのタイプ (以下を参照) |


**boolean** : trueまたはfalse
**long** : 64ビット符号付き整数
**double** : 64ビット浮動小数点数
**string** : 文字列
**timestamp** : ナノ秒精度の日時
**json** : JSONデータ
`format`| typeがtimestampの場合のタイムスタンプの形式

## 設定

`parser`セクションを設定できます。例:

```yaml
in:
...
  parser:
    type: msgpack
    row_encoding: map
    file_encoding: sequence
    columns:
      - {index: 0, name: id, type: long}
      - {index: 1, name: name, type: string}
      - {index: 2, name: price, type: double}
      - {index: 3, name: tag, type: string}
      - {index: 4, name: timestamp, type: timestamp, format: '%Y-%m-%d'}
out:
...
```

## CSVファイルから生成されたMessagePackの例

```csv
id,name,price,tag,timestamp
1,"A green door",11.50,"green","2016-01-02"
2,"A blue door",12.50,"blue","2016-01-03"
3,"A red door",13.50,"red","2016-01-04"
4,"A pink door",14.50,"pink","2016-01-05"
5,"A white door",15.50,"white","2016-01-06"
6,"A black door",16.50,"black","2016-01-07"
7,"A yellow door",17.50,"yellow","2016-01-08"
8,"A purple door",18.50,"purple","2016-01-09"
```

```yaml
in:
...
parser:
   type: msgpack
   row_encoding: map
   file_encoding: sequence
   columns:
     - {index: 0, name: id, type: long}
     - {index: 1, name: name, type: string}
     - {index: 2, name: price, type: double}
     - {index: 3, name: tag, type: string}
     - {index: 4, name: timestamp, type: timestamp, format: '%Y-%m-%d'}
filters: []
out: {mode: append}
exec: {}
```

`preview`コマンドで解析されたMessagePackデータを表示できます。

```bash
$ td connector:preview load.yml
```

```bash
+---------+-----------------+--------------+------------+---------------------------+
| id:long | name:string     | price:double | tag:string | timestamp:timestamp       |
+---------+-----------------+--------------+------------+---------------------------+
| 1       | "A green door"  | 11.5         | "green"    | "2016-01-02 00:00:00 UTC" |
| 2       | "A blue door"   | 12.5         | "blue"     | "2016-01-03 00:00:00 UTC" |
| 3       | "A red door"    | 13.5         | "red"      | "2016-01-04 00:00:00 UTC" |
| 4       | "A pink door"   | 14.5         | "pink"     | "2016-01-05 00:00:00 UTC" |
| 5       | "A white door"  | 15.5         | "white"    | "2016-01-06 00:00:00 UTC" |
| 6       | "A black door"  | 16.5         | "black"    | "2016-01-07 00:00:00 UTC" |
| 7       | "A yellow door" | 17.5         | "yellow"   | "2016-01-08 00:00:00 UTC" |
| 8       | "A purple door" | 18.5         | "purple"   | "2016-01-09 00:00:00 UTC" |
+---------+-----------------+--------------+------------+---------------------------+
```

データに時刻カラムがない場合は、`add_time` Filterオプションを使用して追加できます。詳細については、[add_time Filterプラグイン](/products/customer-data-platform/integration-hub/batch/import/filter/add_time-filter-function)を参照してください。

```bash
$ td connector:issue load.yml --database <database name> --table <table name>  --time-column timestamp --auto-create-table
```