栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

HIVE 自定义字段插入数据

HIVE 自定义字段插入数据

HIVE 自定义字段插入数据

环境介绍只插入自定义字段(单条数据插入)只插入自定义字段(多条数据插入)

环境介绍

① 环境说明

HIVE 2.1.0 + Hadoop 2.7.5

② 文章参考

HIVE INSERT 说明

只插入自定义字段(单条数据插入)

① 非分区表的插入方式

-- 建表语句
create table if not exists user_card_info_temp
(
    user_id   string comment '用户ID',
    user_name string comment '用户姓名',
    card_id   string comment '卡券ID',
    card_name string comment '卡券名称'
)
comment '用户卡券明细表'
stored as orc tblproperties ('orc.compress'='SNAPPY')
;
-- 自定义字段插入格式
INSERT INTO TABLE tablename (COL_NAME1, COL_NAME2) 
VALUES values_row [, values_row ...]

-- 插入语句示例,只插入 user_id、user_name 字段
INSERT INTO TABLE user_card_info_temp (user_id, user_name) 
VALUES
('007','Jay')
;

② 分区表自定义字段的插入方式

-- 建表语句
create table if not exists card_info_temp
(
    card_id     string comment '卡券ID',
    card_name   string comment '卡券名称',
    expire_time string comment '有效期',
    start_time  string comment '开始日期'
)
comment '卡券配置表'
partitioned by (ds string)
stored as orc tblproperties ('orc.compress'='SNAPPY')
;
-- 自定义字段插入格式
INSERT INTO TABLE tablename [PARTITION (partcol1[=val1], partcol2[=val2] ...)] (COL_NAME1, COL_NAME2) 
VALUES values_row [, values_row ...]

-- 插入语句示例,只插入 user_id、user_name 字段
INSERT INTO TABLE card_info_temp partition(ds = '20220223') (card_id, card_name) 
VALUES
('007','七日收益券')
;

只插入自定义字段(多条数据插入)

① 非分区表的插入方式

INSERT INTO TABLE user_card_info_temp (user_id, user_name) 
VALUES
('008','kyle'), ('009','lisa'), ('010','jack')
;

② 分区表插入

INSERT INTO TABLE card_info_temp partition(ds = '20220223') (card_id, card_name) 
VALUES
('008','高额收益券'),('009','免息收益券')
;
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/754009.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号