1、为什么创建的表,数据导入后为什么只在一个列内呢?
DROP tabledev.dev_risk_hitstrategy_zidian;CREATETABLE IF NOT EXISTS dev.dev_risk_hitstrategy_zidian(NUMBER INT,hitstrategy STRING,hitstrategy_name VARCHAR(255))
因为没有加分列符号,需要在建表语句后加上分列的语句,注意分列符号要写对,否则结果也会不正确。
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
2、从一个json串中获取所需的内容,但当关联表时,报错格式无法匹配
SELECTaa.hitStrategy,bb.hitstrategy_name,from(SELECTjson_extract(e, '$.hitStrategy') AShitStrategyFROMrisk_prism_hit_logGROUPBYjson_extract(e, '$.hitStrategy'),)aaleftjoin(SELECThitstrategy,hitstrategy_namefromdev_risk_hitstrategy_zidian)bbon aa.hitstrategy=bb.hitstrategy
报错内容如下:
Query 20200727_060529_02587_98ijp failed: line 32:18: '=' cannot be applied to json, varchar
原因:json格式和varchar格式不同无法进行比较,需要进行格式转换,可采用将json转为varchar
SELECTaa.hitStrategy,bb.hitstrategy_name,from(SELECTcast(json_extract(e,'$.hitStrategy')as varchar) AShitStrategyFROMrisk_prism_hit_logGROUPBYjson_extract(e, '$.hitStrategy'),)aaleftjoin(SELECThitstrategy,hitstrategy_namefromdev_risk_hitstrategy_zidian)bbon aa.hitstrategy=bb.hitstrategy
3、hive使用insert inot插入数据时,遇到中文时会显示为乱码
insert into dev.dev_risk_hitstrategy_zidian values(111,'EEE','赔付策略')
Hive不能直接使用values,需要使用select,例如:
1)将cite表中的数据复制一份,然后插入到原表中去
insert into table cite select * fromcite;
2)用tt表查出来的数据覆盖掉cite表格中已经存在的数据
insert overwrite table cite select *from tt;
3)使用decode函数
报错的:
insert into table(create_time ='20190616') values ('1','strategy','逆向赔付');
正确执行的:
insert into table(create_time='20190616') select '1','strategy',decode(binary('逆向赔付'),'utf-8');
文章转载自五六六七七,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




