# TaJsonFileWriter 插件
# 一、介绍
TaJsonWriter 提供了向本地文件写入 TE JSON 格式的文件。TaJsonWriter 服务于需要把 TE 集群数据还原成 json 文本的用户。
# 二、功能与限制
TaJsonWriter 实现了从 DataX 协议转为 TE JSON 格式的本地文件功能,TaJsonWriter 如下几个方面约定:
- 支持且仅支持写入 TE 格式的 json 文本文件。
 - 支持多线程写入,每个线程写入不同子文件。
 
# 三、功能说明
# 3.1 配置样例
{
  "job": {
    "setting": {
      "speed": {
        "channel": 1
      }
    },
    "content": [
      {
        "reader": {
          "name": "streamreader",
          "parameter": {
            "column": [
              {
                "value": 123123,
                "type": "long"
              },
              {
                "value": "123123",
                "type": "string"
              },
              {
                "value": "login",
                "type": "string"
              },
              {
                "value": "2019-08-16 08:08:08",
                "type": "date"
              },
              {
                "value": "2019-08-16 08:08:08",
                "type": "date"
              },
              {
                "value": "2222",
                "type": "string"
              },
              {
                "value": "2019-08-16 08:08:08",
                "type": "date"
              },
              {
                "value": "test",
                "type": "bytes"
              },
              {
                "value": true,
                "type": "bool"
              }
            ],
            "sliceRecordCount": 100
          }
        },
        "writer": {
          "name": "ta-json-writer",
          "parameter": {
            "type": "event",
            "path": "/data/export/ta_datafile/",
            "filename": "test",
            "column": [
              {
                "index": "0",
                "colTargetName": "#user_id"
              },
              {
                "index": "1",
                "colTargetName": "#distinct_id"
              },
              {
                "index": "2",
                "colTargetName": "#event_name"
              },
              {
                "index": "3",
                "colTargetName": "#time",
                "type": "date",
                "dateFormat": "yyyy-MM-dd HH:mm:ss.SSS"
              },
              {
                "index": "4",
                "colTargetName": "#event_time",
                "type": "string"
              },
              {
                "index": "5",
                "colTargetName": "#account_id",
                "type": "string"
              },
              {
                "index": "6",
                "colTargetName": "timetest",
                "type": "date",
                "dateFormat": "yyyy-MM-dd HH:mm:ss.SSS"
              },
              {
                "index": "6",
                "colTargetName": "timetest2",
                "type": "date",
                "dateFormat": "yyyy-MM-dd HH:mm:ss"
              },
              {
                "index": "7",
                "colTargetName": "os_1",
                "type": "string"
              },
              {
                "index": "7",
                "colTargetName": "os_2",
                "type": "string"
              },
              {
                "index": "8",
                "colTargetName": "booleantest",
                "type": "boolean"
              },
              {
                "index": "0",
                "colTargetName": "testNumber",
                "type": "number"
              },
              {
                "colTargetName": "add_clo",
                "value": "123123",
                "type": "string"
              }
            ]
          }
        }
      }
    ]
  }
}
# 3.2 参数说明
- path 
- 描述:本地文件系统的路径信息,TaJsonWriter 会写入 Path 目录下属多个文件。
 - 必选:是
 - 默认值:无
 
 
fileName
- 描述:TaJsonWriter 写入的文件名,该文件名会添加随机的后缀作为每个线程写入实际文件名。
 - 必选:是
 - 默认值:无
 - writeMode 
- 描述:TaJsonWriter 写入前数据清理处理模式:
- truncate,写入前清理目录下一 fileName 前缀的所有文件。 - append,写入前不做任何处理,DataX TAJsonWriter 直接使用 filename 写入,并保证文件名不冲突。 - nonConflict,如果目录下有 fileName 前缀的文件,直接报错。
- 必选:是
 
 
 - truncate,写入前清理目录下一 fileName 前缀的所有文件。 - append,写入前不做任何处理,DataX TAJsonWriter 直接使用 filename 写入,并保证文件名不冲突。 - nonConflict,如果目录下有 fileName 前缀的文件,直接报错。
 - 默认值:append
 
 - 描述:TaJsonWriter 写入前数据清理处理模式:
 - encoding 
- 描述:读取文件的编码配置。
 - 必选:否
 - 默认值:utf-8
 
 - column 
- 描述:读取字段列表,type 指定数据的类型,index 指定当前列来对应 reader 的第几列(以 0 开始),value 指定当前类型为常量,不从 reader 读取数据,而是根据 value 值自动生成对应的列。
 
 
用户可以指定 Column 字段信息,配置如下:
[
  {
    "type": "Number",
    "colTargetName": "test_col", //生成数据对应的列名
    "index": 0 //从reader到datax传输第一列获取Number字段
  },
  {
    "type": "string",
    "value": "testvalue",
    "colTargetName": "test_col" //从TaDataWriter内部生成testvalue的字符串字段作为当前字段
  },
  {
    "index": 0,
    "type": "date",
    "colTargetName": "testDate",
    "dateFormat": "yyyy-MM-dd HH:mm:ss.SSS"
  }
]
# 3.3 类型转换
类型是 TaJsonFileWriter 定义:
| DataX 内部类型 | TaJsonWriter 数据类型 | 
|---|---|
| Int | Number | 
| Long | Number | 
| Double | Number | 
| String | String | 
| Boolean | Boolean | 
| Date | Date | 
