MaxCompute Studio可以将CSV、TSV等格式的本地数据文件导入到MaxCompute表中,也可将MaxCompute中表数据导出到本地文件。Studio通过MaxCompute平台提供的批量数据通道功能完成数据的导入导出。

前提条件

  • 导入导出数据采用MaxCompute Tunnel服务,因此要求Studio中添加的MaxCompute Project必须开通或配置了Tunnel服务。
  • 导入导出必须具备相应表操作权限。

导入数据

  1. 打开项目空间浏览器(Project Explorer)窗口,右键单击表名,选择Import data Into table
  2. 在弹出的Importing data to result_tabl对话框中,选择导入数据文件的路径、列分隔符(可自定义输入)、大小限制、错误容忍行数等参数,单击OK
  3. 提示Import Data Success,表示数据导入成功,可在表中查看导入的数据。

导出数据

  1. 启动导出表数据有两种方式:
    • 在表名上右键,选择Export Data From Table
      如果您导出的是分区表,在导出时可输入分区值。
    • 在表详细页面的Data Preview中右键单击字段属性,选择Export Data From Table
  2. 在弹出的Exporting data from result_tabl对话框中,选择导出数据文件的保存路径、列分隔符(可自定义输入)、大小限制、错误容忍行数等,填写完成后单击OK
  3. 提示Export Data Success,表示数据导出成功,可在目标文件中看到导出的数据。

新类型导入导出

只需按照约定格式生成文本并存储为CSV或TSV格式,就可通过studio导入到表中。

下面将详细介绍各个数据类型的转换规则。
  • 基本类型
    • TINYINT、SMALLINT、 INT、BIGINT:直接存储为整型字符串,数值超过类型边界会报错。
    • FLOAT、DOUBLE:存储小数字符串或浮点形式,如:2.342 1E+7。
    • VARCHAR:直接存储为字符串,超过上限会自动截断,不会报错。
    • STRING:直接存储为字符串。
    • DECIMAL:支持整形或浮点型的字符串。
    • BINARY:需要将二进制数据编码为base64 string。
    • DATETIME:需import dialog中指定的format格式保持一致,格式不匹配将报错。
    • TIMESTAMP:需要按照yyyy-[m]m-[d]d hh\:mm\:ss[.f...]格式存储为字符串。
    • BOOLEAN:true or false字符串。
  • 复合类型
    • ARRAY:需存储为JSON数组,数组元素按照本文约定规则转换成字符串,数组元素支持任意类型。
    • MAP:需存储为JSON对象,map key、value按照本文约定规则转换为字符串,value支持任意类型嵌套。
    • STRUCT:需存储为JSON对象, struct字段名为string,转换为JSON对象的key, struct字段值转换为JSON对象的value,字段值以本文定义规则转换。
示例
  • array类型
    对于如下所示表结构。
    列名 列数据类型
    c_1 ARRAY<TINYINT>
    c_2 ARRAY<INT>
    c_3 ARRAY<FLOAT>
    c_4 ARRAY<DATETIME>
    c_6 ARRAY<TIMESTAMP>
    c_7 ARRAY<STRING>
    可通过下面所示CSV格式导入数据。
    
    c_1,c_2,c_3,c_4,c_6,c_7
    "[""1"",""2"",""3""]","[""1"",""2"",""3"",""4""]","[""1.2"",""2.0""]","[""2017-11-11 00:00:00"",""2017-11-11 00:00:00"",""2017-11-11 00:00:00""]","[""2017-11-11 00:00:00.123456789"",""2017-11-11 00:00:00.123456789"",""2017-11-11 00:00:00.123456789""]","[""aaa"",""bbb"",""ccc""]"
    "[""1"",""2"",""3""]","[""1"",""2"",""3"",""4""]","[""1.2"",""2.0""]","[""2017-11-11 00:00:00"",""2017-11-11 00:00:00"",""2017-11-11 00:00:00""]","[""2017-11-11 00:00:00.123456789"",""2017-11-11 00:00:00.123456789"",""2017-11-11 00:00:00.123456789""]","[""aaa"",""bbb"",""ccc""]"
    "[""1"",""2"",""3""]","[""1"",""2"",""3"",""4""]","[""1.2"",""2.0""]","[""2017-11-11 00:00:00"",""2017-11-11 00:00:00"",""2017-11-11 00:00:00""]","[""2017-11-11 00:00:00.123456789"",""2017-11-11 00:00:00.123456789"",""2017-11-11 00:00:00.123456789""]","[""aaa"",""bbb"",""ccc""]"
    说明 CSV格式需要对双引号进行转义,通过两个双引号来表示双引号,具体可参考CSV格式规范。
  • map类型
    对于如下所示表结构。
    列名 列数据类型
    c_1 MAP<TINYINT,STRING>
    c_2 MAP<STRING,INT>
    c_3 MAP<FLOAT,STRING>
    c_4 MAP<STRING,DATETIME>
    c_5 MAP<STRING,STRING>
    c_6 MAP<TIMESTAMP,STRING>
    可通过下面所示CSV格式导入数据。
    
    c_1,c_2,c_3,c_4,c_5,c_6
    "{1:""2345""}","{""123"":""2"",""3"":""4""}","{2.0:""223445"",1.2:""1111""}","{""aaa"":""2017-11-11 00:00:00"",""ccc"":""2017-11-11 00:00:00"",""bbb"":""2017-11-11 00:00:00""}","{""ckey"":""cvalue""}","{""2017-11-11 01:00:00.123456789"":""dddd"",""2017-11-11 00:00:00.123456789"":""aaa"",""2017-11-11 00:01:00.123456789"":""ddd""}"
    "{1:""2345""}","{""123"":""2"",""3"":""4""}","{2.0:""223445"",1.2:""1111""}","{""aaa"":""2017-11-11 00:00:00"",""ccc"":""2017-11-11 00:00:00"",""bbb"":""2017-11-11 00:00:00""}","{""ckey"":""cvalue""}","{""2017-11-11 01:00:00.123456789"":""dddd"",""2017-11-11 00:00:00.123456789"":""aaa"",""2017-11-11 00:01:00.123456789"":""ddd""}"
    "{1:""2345""}","{""123"":""2"",""3"":""4""}","{2.0:""223445"",1.2:""1111""}","{""aaa"":""2017-11-11 00:00:00"",""ccc"":""2017-11-11 00:00:00"",""bbb"":""2017-11-11 00:00:00""}","{""ckey"":""cvalue""}","{""2017-11-11 01:00:00.123456789"":""dddd"",""2017-11-11 00:00:00.123456789"":""aaa"",""2017-11-11 00:01:00.123456789"":""ddd""}"
  • struct类型
    对于如下所示表结构。
    列名 列数据类型
    c_struct <RUCT<x:INT,y:VARCHAR(256),z:STRUCT<a:TINYINT,b:STRING>>
    可通过下面所示CSV格式导入数据。
    
    c_struct
    "{""x"":""1000"",""y"":""varchar_test"",""z"":{""a"":""123"",""b"":""stringdemo""}}"
    "{""x"":""1000"",""y"":""varchar_test"",""z"":{""a"":""123"",""b"":""stringdemo""}}"