HIVE的常用操作-建库和表-插入数据

article/2025/10/1 4:02:59

hive的安装(远程模式)   点击打开链接

使用hive
-----------------------

启动hadoop

启动hive

创建数据库:

create database myhive;

查看数据库:

hive (default)> show databases;
OK
database_name
default
myhive

数据准备:employees.txt

1201	Gopal	45000	Technical manager
1202	Manisha	45000	Proof reader
1203	Masthanvali	40000	Technical writer
1204	Krian	40000	Hr Admin
1205	Kranthi	30000	Op Admin

在myhive库中创建表

    use myhive;

hive (myhive)> create table myhive.employee (eud int,name String,salary String,destination String) COMMENT 'Employee table' ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' STORED AS TEXTFILE;
OK
Time taken: 0.109 seconds

向hive中加载数据 (local模式)   查询数据

hive (myhive)> load data local inpath '/home/hadoop/data/employees.txt' into table employee;
Loading data to table myhive.employee
OK
Time taken: 0.288 seconds
hive (myhive)> select * from employee;
OK
employee.eud	employee.name	employee.salary	employee.destination
1201	Gopal	45000	Technical manager
1202	Manisha	45000	Proof reader
1203	Masthanvali	40000	Technical writer
1204	Krian	40000	Hr Admin
1205	Kranthi	30000	Op Admin
Time taken: 0.128 seconds, Fetched: 5 row(s)

加载数据到hive  (实际加载到hdfs)


非local模式把数据加载到hive

数据准备:    data.txt

1206	tom	5000	Proof reader
1207	liming	40000	Technical writer
[hadoop@master data]$ hadoop fs -mkdir /data
[hadoop@master data]$ hadoop fs -put ./data.txt /data

hive (myhive)> load data  inpath '/data/data.txt' into table employee1;
Loading data to table myhive.employee1
OK
Time taken: 0.274 seconds
hive (myhive)> select * from employee1;
OK
employee1.eud	employee1.name	employee1.salary	employee1.destination
1206	tom	5000	Proof reader
1207	liming	40000	Technical writer
Time taken: 0.103 seconds, Fetched: 2 row(s)

在local模式的情形中进行如下操作

[hadoop@master data]$ hadoop fs -put ./data.txt /user/hive/warehouse/myhive.db/employee
[hadoop@master data]$ hadoop fs -cat  /user/hive/warehouse/myhive.db/employee/data.txt
1206	tom	5000	Proof reader
1207	liming	40000	

在同一路径数据文本格式相同数据加载成功(并非需要load data..............)进行数据的加载

hive (myhive)> select * from employee;
OK
employee.eud	employee.name	employee.salary	employee.destination
1206	tom	5000	Proof reader
1207	liming	40000	Technical writer
1201	Gopal	45000	Technical manager
1202	Manisha	45000	Proof reader
1203	Masthanvali	40000	Technical writer
1204	Krian	40000	Hr Admin
1205	Kranthi	30000	Op Admin
Time taken: 0.162 seconds, Fetched: 7 row(s)

向employee表中插入数据 -mapreduce-job        

**  (HIVE:    支持插入, 不支持删除和更新

hive (myhive)> insert into employee(eid,name) values(1208,'jack')

             > ;
FAILED: SemanticException 1:21 'eid' in insert schema specification is not found among regular columns of myhive.employee nor dynamic partition columns.. Error encountered near token 'name'
hive (myhive)> insert into employee(eid,name) values(1208,'jack');
FAILED: SemanticException 1:21 'eid' in insert schema specification is not found among regular columns of myhive.employee nor dynamic partition columns.. Error encountered near token 'name'
hive (myhive)> insert into employee(eud,name) values(1208,'jack');
WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
Query ID = hadoop_20180629105054_e4e30a0f-92b7-42b5-8ecb-3a5fe41d516b
Total jobs = 3
Launching Job 1 out of 3
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_1530235955590_0001, Tracking URL = http://master:8088/proxy/application_1530235955590_0001/
Kill Command = /usr/local/soft/hadoop-2.7.3/bin/hadoop job  -kill job_1530235955590_0001
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2018-06-29 10:51:11,738 Stage-1 map = 0%,  reduce = 0%
2018-06-29 10:51:22,753 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.59 sec
MapReduce Total cumulative CPU time: 2 seconds 590 msec
Ended Job = job_1530235955590_0001
Stage-4 is selected by condition resolver.
Stage-3 is filtered out by condition resolver.
Stage-5 is filtered out by condition resolver.
Moving data to directory hdfs://master:9000/user/hive/warehouse/myhive.db/employee/.hive-staging_hive_2018-06-29_10-50-54_840_2892277479385925233-1/-ext-10000
Loading data to table myhive.employee
MapReduce Jobs Launched: 
Stage-Stage-1: Map: 1   Cumulative CPU: 2.59 sec   HDFS Read: 4375 HDFS Write: 87 SUCCESS
Total MapReduce CPU Time Spent: 2 seconds 590 msec
OK
_col0	_col1	_col2	_col3


hadoop fs -lsr /user/




简单操作    (在hive中执行shell命令      本地)

hive (myhive)> !ls /home/hadoop/data;
1901
1902
data.txt
employees.txt
hive (myhive)> !cat data.txt;
cat: data.txt: 没有那个文件或目录
Command failed with exit code = 1
hive (myhive)> !cat /home/hadoop/data/data.txt;
1206	tom	5000	Proof reader
1207	liming	40000	Technical 

其他的shell命令在hive中的用法与上面的相同


(在hive中执行shell命令      HDFS)

hive (default)> dfs -ls /;
Found 7 items
drwxr-xr-x   - hadoop supergroup          0 2018-06-29 10:58 /data
drwxr-xr-x   - hadoop supergroup          0 2018-06-26 22:27 /hbase
drwxr-xr-x   - hadoop supergroup          0 2018-06-27 20:52 /home
drwxr-xr-x   - hadoop supergroup          0 2018-06-24 20:54 /input
drwxr-xr-x   - hadoop supergroup          0 2018-06-28 22:54 /mapreduce
drwx------   - hadoop supergroup          0 2018-06-29 10:50 /tmp
drwxr-xr-x   - hadoop supergroup          0 2018-06-25 15:49 /user


http://chatgpt.dhexx.cn/article/ob4aSLYK.shtml

相关文章

Hive三种建表语句详解

转载自:https://blog.csdn.net/qq_36743482/article/details/78383964 注:hive其他语法在hive官网有说明,建议初学者,去官网学习一手的资料, 官网:https://cwiki.apache.org/confluence/display/Hive/Home#…

关于hive建表查询语句小记

库相关操作 创建数据库 CREATE DATABASE [IF NOT EXISTS] database_name [COMMENT database_comment] [LOCATION hdfs_path] [WITH DBPROPERTIES (property_nameproperty_value, ...)]; IF NOT EXISTS 也就是没有重复库就创建,有重复就不执行建库 保证了建库…

hive、pg库,建表语句及查询表结构语句

1、hive hive 建表语句 DROP TABLE IF EXISTS tmp_001; CREATE TABLE tmp_001 (etl_time timestamp comment , day_id double comment , subs_id string comment , msisdn int comment ) comment partitioned by…

3、Hive数据仓库——建表语句

文章目录 Hive基本操作Hive查看SQL解析计划Hive建表建表1:全部使用默认建表方式 Hive 内部表 (Managed tables)指定location (这种方式也比较常用)formatted 查看该表的结构化数据,但并不列出表中的数据将本地数据上传到HDfS上 Hi…

HIVE的三种建表方式

目录 一、直接建表二、as (直接使用查询结果插入到一张新表)三、like(复制表结构) 一、直接建表 中括号里面的均为可选项 CREATE [EXTERNAL] TABLE [IF NOT EXISTS] table_name[(col_name data_type [COMMENT col_comment], ...…

Hive学习3:Hive三种建表语句详解

注:hive其他语法在hive官网有说明,建议初学者,去官网学习一手的资料, 官网:https://cwiki.apache.org/confluence/display/Hive/Home#Home-UserDocumentation Create Table 官网说明 Hive建表方式共有三种&#xff…

Hive_ Hive 建表语句详解

参考文章: https://blog.csdn.net/qq_36743482/article/details/78383964 最近博主在编写一个每天定时创建Hive 分区的脚本,其中需要创建Hive表, 开始的时候我以为创建Hive 表的语句顺序是比较宽松的,经过测试发现不然&#xf…

Hive建表语句详解--CREATE TABLE

创建表的三种方法 Hive创建表的方式(默认路径/user/hive/warehouse,也可以location指定,主要针对external表) 1、使用create命令创建一个新表,带分区 CREATE TABLE mydb.dept( dept_no int, addr string, tel string) par…

【Hive】Hive 创建表

学习笔记—Hive创建表 1. Hive语句的特点 HQL 语言大小写不敏感,但内容分大小写(where ,if/ case when,如:数据表内容某人名叫Tom,则条件后不能写tom,HDFS 路径名(NameNode)分大小写…

hive建表语句

目录 一、建表语句1、创建内部表2、创建外部表3、建表高阶语句 CTAS 和 WITH4、向临时表中插入原表中的数据5、创建分区表 一、建表语句 1、创建内部表 建表: CREATE TABLE phone_info(id int,name String,storage String,price double) ROW FORMAT DELIMITED //…

c语言void* arg,void * arg什么意思

许多初学者对C/C++语言中的void及void指针类型不甚理解,因此在使用上出现了一些错误。本文将对void关键字的深刻含义进行解说,并详述void及void指针类型的使用方法与技巧。 2.void的含义 void的字面意思是“无类型”,void *则为“无类型指针”,void *可以指向任何类型的数据…

什么是arguments

什么是arguments 形参:函数定义的参数实参:函数调用时实际传递的参数。参数匹配是从左向右进行匹配。如果实参个数少于形参,后面的参数对应赋值undefined。实参的个数如果多于形参的个数,可以通过arguments访问。【案例】模拟封装…

python函数参数*arg和**args的用法

import numpy as np """ 做饭函数,表示午饭有什么,foods表示一个元组 """ def make_meals(*foods):for item in foods:print(今天午饭有,item)def dictionary(**dic):for key,value in dic.items():print(英文名(key) , key , &…

什么是:arguments

在调用函数时,浏览器每次都会传递进两个隐含的参数: 1.函数的上下文对象this 2.封装实参的对象arguments 什么是:arguments 1.arguments是一个类数组对象,它也可以通过索引来操作数据,也可以获取长度 在调用函数时,我们所传递的实…

python中的arg,*args,args,**kwargs,kwargs的关系和区别

arg就是指一个参数 def func(arg):print(arg)func(2) *args 是用来将参数打包成元组给函数调用的,args即是传给函数的参数所构成的元组 def func(arg, *args):print(arg, *args)func(1, 2, 3, 4, 5, 6, 7)**kwargs是用来将关键字参数打包成字典给函数调用的&#…

Python *arg与**kwarg区别

*arg 与 **kwargs介绍 args 是 arguments 的缩写,表示位置参数;kwargs 是 keyword arguments 的缩写,表示关键字参数。这其实就是 Python 中可变参数的两种形式,并且*args 必须放在 **kwargs的前面,因为位置参数在关键…

argc,argv是什么

来源:微信公众号「编程学习基地」 文章目录 argc,argv是什么如何解析程序参数“选项”是什么?"选项字符串"是什么解析参数 argc,argv是什么 如果你是一个 Linux 开发者,那么你一定需要给应用程序传递参数。…

数学符号arg的含义

argument of the maximum/minimum arg max f(x): 当f(x)取最大值时,x的取值 arg min f(x):当f(x)取最小值时,x的取值 表示使目标函数取最小值时的变量值 From Wikipedia In mathematics, arg max (or argmax) stands for the argument of…

arg和*argv[]是什么?

我们知道main函数的标准原型应该是int main(int argc, char *argv[]);。argc是命令行参数的个数,argv是一个指向指针的指针。那为什么要写成char *argv[]而不写成char argv呢?这样写给表示argv不是指向单个指针,而是指向一个指针数组的首元素…

数学符号arg含义

argument of the maximum/minimum arg max f(x): 当f(x)取最大值时,x的取值 arg min f(x):当f(x)取最小值时,x的取值 表示使目标函数取最小值时的变量值 From Wikipedia In mathematics, arg max (or argmax) stands for the argument of…