基本数据类型
MaxCompute 1.0数据类型:bigint、double、decimal、string、datetime、boolean
MaxCompute 2.0新增数据类型:tinyint、smallint、int、float、varchar、binary、timestamp、date、char
如果需要使用新增数据类型,需要先打开使用新数据类型的开关
- Session级别:需要在待执行的语句前加上如下命令,并与该语句一起提交执行。
set odps.sql.type.system.odps2=true
- Project级别:需要由Project的Owner在命令行对需要开启新数据类型的Project执行如下命令
新数据类型使用注意事项参见:setproject odps.sql.type.system.odps2=true;
https://help.aliyun.com/document_detail/27821.html?spm=a2c4g.11174283.6.634.7436590ekr7CF0
复杂数据类型
MaxCompute 2.0支持array、map、struct三种复杂数据类型
类型 | 定义方法 | 构建方法 | 访问示例 |
---|---|---|---|
array | - array - array |
- array(1,2,3) - array(array(1,2),array(3,4)) |
- a[1] - a[x][y] |
map | - map - map |
- map(“k1”,”v1”,”k2”,”v2”) - map(1S,array(‘a’,’b’),2S,array(‘c’,’d’)) |
- m[‘k1’] - m[2Y][id] |
struct | - struct - struct |
- named_struct(‘x’,1,’y’,2) - named_struct(‘field1’,100L,’field2’,array(1,2),’field3’,map(1,100,2,200)) |
- s.x - s.b[1] |
建表,插入语句示例如下:
PyODPS数据类型设置
如果使用execute_sql方式,可以执行
o.execute_sql('set odps.sql.type.system.odps2=true;query_sql', hints={"odps.sql.submit.mode" : "script"})
如果通过Dataframe打开新数据类型,例如execute、persist、to_pandas等方法,可以通过hints参数设置,如
user.persist('copy_table',hints={'odps.sql.type.system.odps2':'true'}
但该方法仅能对单个作业生效。
如果需要通过Dataframe调用,且需要全局生效,需要使用参数
options.sql.use_odps2_extension=True