基本数据类型
- 自动向上转型:任何整数类型都可以隐式地转换为一个范围更广的类型,如TINYINT可以转换成INT,INT可以转换成BIGINT。
- 所有整数类型、FLOAT和STRING类型都可以隐式地转换成DOUBLE。
- TINYINT、SMALLINT、INT都可以转换为FLOAT。
- BOOLEAN类型不可以转换为任何其它的类型。
CAST(‘1’ AS INT):将把字符串’1’ 转换成整数1;如果强制类型转换失败,如执行CAST(‘X’ AS INT),表达式返回空值 NULL。
示例: 待导入的数据zhangsan,xiaoming_xiaohua,tom:18_jerry:19,da xing_beijing lisi,xiaowei_xiaojian,lily:18_marry:19,chang ping_beijing
分析数据格式
{
"name": "zhangsan",
"friends": ["lisi" , "wanger"] , //列表Array,
"children": { //键值Map,
"tom": 18 ,
"jerry": 19
}
"address": { //结构Struct,
"street": "changping" ,
"city": "beijing"
}
}
第一步:根据数据格式创建表
HQL语句:
create table tb_user( --此处表名不能叫user,否则会报错
name string,
friends array,
children map,
address struct
)
row format delimited fields terminated by ','
collection items terminated by '_'
map keys terminated by ':'
lines terminated by '\n';
- select * from tb_user
- select friends[1] friend,children[‘tom’],address.street street from tb_user where name=‘zhangsan’;