1.如何创建hive表
CREATE TABLE MOD_SWCK_INFO(
BILL_MONTH STRING,
CITY_NAME STRING,
CITY_CODE STRING,
COUNTY_NAME STRING,
COUNTY_CODE STRING,
CHN_ID STRING,
CHN_NAME STRING,
CHN_TYPE STRING,
LOGIN_ID STRING,
LOGIN_NAME STRING,
DEAL_TYPE STRING,
GOODS_TYPE STRING,
TERM_BRAND_CODE STRING,
TERM_BRAND_NAME STRING,
TERM_TYPE_CODE STRING,
TERM_TYPE_NAME STRING,
CARD_TYPE STRING,
CARD_TYPE_NAME STRING,
SIM_MEMORY STRING,
CARD_VALUE STRING,
TERM_ESN STRING,
TRADE_ID STRING,
USER_ID STRING,
DEAL_TIME STRING,
OUTBOUND_TIME STRING
)
PARTITIONED BY
(`YEAR` STRING,
`MONTH` STRING,
`DAY` STRING,
`DB_TYPE` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '^';
插入数据:
INSERT OVERWRITE TABLE MOD_SWCK_INFO PARTITION(YEAR,MONTH,DAY,DB_TYPE)
SELECT
ps: 将数据插入表中最好先建立临时表
2.我们在做hive的表的时候,如果我们要保留几位小数,首先想到的就是round函数,但是,如果我们计算的指标数据量很大,那么就会出现科学计数法,往往我们不需要用科学计数法,我们可以用cast( zhibiao as decimal(n,m)) n是总的位数,m是需要保留的小数位数
3.hive修改 表/分区语句
链接:https://blog.csdn.net/zhangzhongzhong/article/details/65632583
alter table rpt_jh_khzl drop partition(year='2018',month='12',day='01');
alter table rpt_jh_khzl add partition(year='2018',month='12',day='01',db_type='QH') location '2018/12/01/QH';
4.hive修改表中字段的位置
增加字段
ALTER TABLE audit_temp ADD COLUMNS(other STRING);
修改字段位置
ALTER TABLE audit_temp CHANGE COLUMN other other STRING AFTER hav_coin;
这两步顺序执行