CDH简单的hive示例

版权声明:本文为博主大壮原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33792843/article/details/90207077


首先准备hive数据,这个例子ok之后,我们要开始数据仓库建设了,我们分4层即可,ods数据准备层、dw数据明细层、dm数据集市、st数据应用层

构建数据仓库


create database test;

show databases;


准备数据(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


create table test.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;


1.local 模式加载数据

        用hive:
        load data local inpath '/var/lib/hadoop-hdfs/employees.txt' into table employee;
        select * from employee;

        然后hadoop数据查看。


        hadoop fs -lsr /user/hive/warehouse/test.db/

        hadoop fs -text /user/hive/warehouse/test.db/employee/employees.txt


2.非local模式加载数据

        hadoop fs -mkdir /data
        hadoop fs -put ./data.txt /data

        用hive命令行:
        load data  inpath '/data/data.txt' into table employee1;

        select * from employee1;


3.在local模式下执行以下操作也可以直接建表的

        这样也可以直接建表的
        [hadoop@master data]$ hadoop fs -put ./data.txt /user/hive/warehouse/test.db/employee2
        [hadoop@master data]$ hadoop fs -cat  /user/hive/warehouse/test.db/employee2/data.txt

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

猜你喜欢

转载自blog.csdn.net/qq_33792843/article/details/90207077