微信小程序 uniapp+vue餐厅美食就餐推荐系统

阅读 10

2024-02-28

文章中对hive表中导入数据 方法目录

 方式一:通过load方式加载数据

 方式二:直接向分区表中插入数据

 方式三:查询语句中创建表并加载数据(as select)

 方式四:创建表时通过location指定加载数据路径

    1. 创建表,并指定在hdfs上的位置

     2. 上传数据到hdfs上

    3. 查询数据

方式五:export导出 与 import导入 hive表数据(内部非分区表操作)


准备数据

-- 创建 db_myhive_5
create database db_myhive_5;

use db_myhive_5;

-- 创建表
create table tb_score(
    s_id string,
    c_id string,
    score int
)
partitioned by (month string)
row format delimited fields terminated by '\t';

 方式一:通过load方式加载数据

load data local inpath '/export/data/hive_data/score.txt' overwrite into table tb_score partition(month='202006');

 方式二:直接向分区表中插入数据

通过insert into方式加载数据

create table score3 like tb_score;

insert into table score3 partition(month ='202007') values ('001','002','100');

通过查询方式加载数据

create table score4 like score;

insert overwrite table score4 partition(month = '202006') select s_id,c_id,s_score from tb_score;

 方式三:查询语句中创建表并加载数据(as select)

将查询的结果保存到一张表当中去

create table score5 as select * from score;

 方式四:创建表时通过location指定加载数据路径
    1. 创建表,并指定在hdfs上的位置

create external table score6 (s_id string,c_id string,s_score int) 

row format delimited

fields terminated by '\t' 

location '/myscore6';

     2. 上传数据到hdfs上

hdfs dfs -mkdir -p /myscore6

hdfs dfs -put score.txt /myscore6;

    3. 查询数据

select * from score6;

方式五:export导出  import导入 hive表数据内部非分区操作

create table teacher2 like teacher;

export table teacher to  '/export/teacher';

import table teacher2 from '/export/teacher'

注意: import 导入时结尾不要增加 分号;

精彩评论(0)

0 0 举报