创建 hive外部表加载text数据文件
CREATE EXTERNAL TABLE `default`.`dim_dj_logs_all_event_info`(
`id` INT COMMENT 'id',
`pt_id` int COMMENT '平台id',
`url_path` string COMMENT '页面路径',
`name` string COMMENT '页面url名字',
`event_id` STRING COMMENT '事件id',
`event_name` STRING COMMENT '事件名称',
`event_type` string COMMENT '事件类型',
`new_name` string COMMENT '',
`new_event_name` string COMMENT ''
)COMMENT '全部事件维度表'
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
WITH SERDEPROPERTIES (
'field.delim'='\t',
'serialization.format'='\t')
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'hdfs://CDP-1/user/bj/hive/dj/dim/event/dim_dj_logs_all_event_info'
TBLPROPERTIES (
'bucketing_version'='2',
'transient_lastDdlTime'='1695266831') ;
-- 数据文件 all_event_data.txt
201 3 pages/index/index 首页 event_homepage_view 首页页面加载 MPViewScreen 首页 进入
202 3 pages/index/index 首页 event_homepage_leave 首页页面离开 MPPageLeave 首页 离开
203 3 pages/my/index 我的 event_my_view 我的页面加载 MPViewScreen 我的 进入
204 3 pages/my/index 我的 event_my_leavel 我的页面离开 MPPageLeave 我的 离开
205 3 pages/recent/index 追剧 event_binge-watch_view 追剧页面加载 MPViewScreen 追剧 进入
206 3 pages/recent/index 追剧 event_binge-watch_leave 追剧页面离开 MPPageLeave 追剧 离开
207 3 pages/theater/index 剧场 event_theater_view 剧场页面加载 MPViewScreen 剧场 进入
208 3 pages/theater/index 剧场 event_theater_leave 剧场页面离开 MPPageLeave 剧场 离开
209 3 pages/square/index 广场 event_forum_view 广场页面加载 MPViewScreen 广场 进入
210 3 pages/square/index 广场 event_forum_leave 广场页面离开 MPPageLeave 广场 离开
-- 将linux上的文件上传到 hdfs文件系统
hdfs dfs -put /home/XX/bj/hive/dj/dim/event/all_event_data.txt /user/bj/hive/dj/dim/event/dim_dj_logs_all_event_info/
这里建的是外部分区表
字段 database 、table 、type 是关键字用 瓢号引上
CREATE EXTERNAL TABLE ods_kyy_db_rt.ods_xx_db_binlog_rt(
`database` string COMMENT '',
`table` string COMMENT '',
`type` string COMMENT '',
`ts` bigint COMMENT '',
`xid` bigint COMMENT '',
`xoffset` bigint COMMENT '',
`commit` boolean COMMENT '',
`primary_key` string COMMENT '',
`primary_key_columns` string COMMENT '',
`data` string COMMENT '',
`old` string COMMENT '')
COMMENT 'ods层binlog日志数据表'
PARTITIONED BY (
`dt` string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
WITH SERDEPROPERTIES (
'field.delim'='',
'serialization.format'='')
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION
'oss://bigdata-oss-xx/user/hive/warehouse/ods_xx_db.db/offline/ods_xx_db_binlog'
hive sql 创建内部表,加载数据文件orc文件
-- 1) 指定数据文件之间的分隔符
CREATE EXTERNAL TABLE if not exists ${dwdName}.dwd_dp_db_user_order_chain(
id int COMMENT '',
user_id bigint COMMENT '',
oreder_money double COMMENT '订单金额',
created_at string COMMENT '',
updated_at string COMMENT '',
deleted_at string COMMENT '',
start_time string comment '数据生效时间',
end_time string comment '数据失效时间'
)
COMMENT '用户订单拉链表'
partitioned by(dt string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.orc.OrcSerde'
WITH SERDEPROPERTIES (
'field.delim'='\001', -- 这里也可以使用SOH(转移字符)
'serialization.format'=''
)
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
'${hiveWarehousePath}/dwd/dwd_dp_db_user_order_chain'
TBLPROPERTIES ('orc.compress'='snappy') -- 压缩方式使用snappy
-- 2) 不指定数据之间分隔符
CREATE EXTERNAL TABLE if not exists ${dwdName}.dwd_dp_db_user_order_chain(
id int COMMENT '',
user_id bigint COMMENT '',
oreder_money double COMMENT '订单金额',
created_at string COMMENT '',
updated_at string COMMENT '',
deleted_at string COMMENT '',
start_time string comment '数据生效时间',
end_time string comment '数据失效时间'
)
COMMENT '用户订单拉链表'
partitioned by(dt string)
STORED AS ORC
LOCATION
'${hiveWarehousePath}/dwd/dwd_dp_db_user_order_chain'
TBLPROPERTIES('orc.compress'='snappy')
以上两种方式创建的加载orc数据文件的hive内部表,均可以创建成功。
通过 :
show create table ${dwdName}.dwd_dp_db_user_order_chain
查询建表数据结构:
1表结构有数据分割符参数
2表结构没有数据分割符参数