DML主要就是操作数据了,因为数据存到了DML中所以,删除等操作用的很少,主要就是导数据:
导入数据2种:
第一种:直接目录导入
1、从本地导入数据到hive中:
load data local inpath ‘/~/~/~/data.txt’ overwrite into table psn1;
注意:我如果再次执行上面的语句(原始文件名字一样),它会在psn1目录下面,自动生成一个data_copy的文件而,不会覆盖掉data。
2、将hdfs中的数据导入到hive中:
load data inpath '/data' into table psn1;
注意:我hdfs上的这个data数据此时刷新的话,会在原有目录中消失掉,因为,执行完上面的代码后,它其实是将这个data移动到了我psn1(hdfs中)这个目录下面了
第二种:先查询后导入
from psn1 insert into table psn2 select id,name,likes,address
这段sql的意思是:
我读取psn1这个表里面的id,name,like,address等字段数据,并写入到psn2这个表中。
这种将from写在前面的方式什么时候用?
如下:
1、我想要读取我psn1这张表中的数据。
2、存到jgtbl这张表中,该表有2个字段分别是(id int,value:String)
3、存入的数据是这样的格式:
1,值
2,值
则如下操作