一、初识HIVE
在安装并配置好环境变量的环境中运行 hive命令进入shell程序交互模式
show tables;展示所有表
hive -f script.q(非交互模式下运行编写好的脚本)类似的hive -e 'select * from table';
1.创建一个test表,有3列,在文件中每行数据的列是由逗号“,”分割的
create table test (field1 STRING,field2 INT,fied3 INT) rowformat delimited fields terminated by ','
2.将本地文件系统的文件复制到hive仓库对应的表目录中,下面例子是本地文件目录fs.default.name=file:///上的操作
表存储在仓库中的目录中,仓库目录由hive.metastore.warehouse.dir=/usr/hive/warehouse/参数决定,表就以表明作为目录存放在仓库根目录下。overwrite代表将表目录清空再放入需要的文件,如果不写就是复制替换。
load data local inpath '/root/mydir/test.txt' overwrite into table test;
ls /usr/hive/warehouse/test/可以看到我们之前在inpath后的文件test.txt
3.用hive进行查询
select * from test where field1 = 'hellokitty' and (field2 <10 or field3>10) group by filed2;
这里只是一个随意的案例,就是告诉大家跟sql语句简直就是一模一样,在这条语句发送后hive就将它转换成mapreduce作业然后将执行结果展示出来。