hive操作数据库实验

您所在的位置:网站首页 hive数据操作 hive操作数据库实验

hive操作数据库实验

2023-09-18 17:17| 来源: 网络整理| 查看: 265

任务一、hive创建数据库(10分) 创建一个数据库,以你的用户名命名,创建成功后使用use命令切换为该库,并执行set hive.cli.print.current.db=true;截图作为答案(3分)

1)创建数据库命令截图:(2分)

create database huangjie; use huangjie;

在这里插入图片描述

2)执行命令结果截图:(1分)

set hive.cli.print.current.db=true;

在这里插入图片描述

在HIVE中创建需要的表,并写出建表语句,表结构如下:(3分)

(1).产品表(product) 字段字段----------字段描述---------字段类型 product_id--------产品ID------------String product_name—产品名称---------String unit_price---------产品单价---------decimal(20,3) inventory----------产品库存---------decimal(20,3) (2)销售表(salse) 字段----------------字段描述---------字段类型 order_id-----------订单ID------------String product_id--------产品ID------------String customer_id------客户ID------------String year-----------------年-----------------Int month--------------月------------------Int day------------------日------------------Int freight_charges–运费---------------decimal(20,3) unit_price----------单价---------------decimal(20,3) quantity-------------销售数量--------decimal(20,3)

1) 创建product表 语句截图:(1分)

create table product( product_id string comment '产品ID', product_name string comment '产品名称', unit_price decimal(20,3) comment '产品单价', inventory decimal(20,3) comment '产品库存') row format delimited fields terminated by '|';

在这里插入图片描述 在这里插入图片描述

2) 创建salse表 语句截图:(1分)

create table salse( order_id string comment '订单ID', product_id string comment '产品ID', customer_id string comment '客户ID', year int comment '年', month int comment '月', day int comment '日',freight_charges decimal(20,3) comment '运费', unit_price decimal(20,3) comment '单价', quantity decimal(20,3) comment '销售数量') row format delimited fields terminated by '|';

在这里插入图片描述 在这里插入图片描述

3)创建成功,执行show tables;截图;(1分)

show tables;

在这里插入图片描述

将数据加载到表中,写出加载数据的语句(4分) 数据文件名称分别与表名称对应,(字段分隔符为|),注意,linux系统和hive默认不支持中文,要自己设置成utf-8编码才可以支持中文。 导入product表 语句截图:(1分)

ac097T42vi13|aaa_a_123|Tom|2021|5|15|12.5|123.45|2 d7b5js7l9da5|aaa_a_123|Juery|2021|5|16|12.5|123.45|1 0h48ne49p4f5|aaa_b_456|Tony|2021|5|23|11.1|233.49|1 39fnd93de8dn|aaa_c_456|Timy|2021|5|24|10.67|2233.49|5

aaa_a_123|高等数学|123.45|100 aaa_b_456|考研英语|233.49|80 aaa_c_456|考研政治|2233.49|8000

load data local inpath '/opt/data/product.txt' into table product;

在这里插入图片描述

2)导入salse表 语句截图:(1分)

load data local inpath '/opt/data/salse.txt' into table salse;

在这里插入图片描述

3)执行 select * from product 并截图(其中table_name 为前面创建的表名)(1分)

select * from product;

在这里插入图片描述

4)执行 select * from salse并截图(1分)

select * from salse;

在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3