[01].加载学生表

  • 启动hive

    1. cd apache-hive-2.3.9-bin/bin
    1. cd apache-hive-2.3.9-bin/bin

    34.导入student表 - 图1

  • 使用默认数据库

    1. hive> use default;
    2. OK
    3. Time taken: 7.218 seconds
  • 查看表

    1. hive> show tables;
    2. OK
    3. student
    4. Time taken: 0.249 seconds, Fetched: 1 row(s)
  • 创建表格(使用制表符分割)

    1. hive> create table stu(id string,name string,stature int)row format delimited fields terminated by '\t';
    2. OK
    3. Time taken: 1.049 seconds
  • 将清洗过的数据加载入表中

    1. hive> load data inpath 'hdfs://master:8020/hiveoutput/part-r-00000' overwrite into table stu;
    2. Loading data to table default.student
    3. OK
    4. Time taken: 1.662 seconds
  • 查询一下

    1. hive> select * from stu;
    2. OK
    3. 1012 160 NULL
    4. 10012 Abel 170
    5. 1008 Kate 168
    6. 1007 Alice 163
    7. 1006 John 192
    8. 1005 Rob 177
    9. 1004 Jack 175
    10. 1003 Mary 172
    11. 1002 Lily 165
    12. 1001 Tom 180
    13. Time taken: 2.158 seconds, Fetched: 10 row(s)

    [02].加载课程表

  • 创建课程表

    1. hive> create table cos(id string,cos_name string,grade double)row format delimited fields terminated by '\t';
    2. OK
    3. Time taken: 0.371 seconds
  • 本地导入

    1. hive> load data local inpath '/opt/input/course.txt' overwrite into table cos;
    2. Loading data to table default.cos
    3. OK
    4. Time taken: 0.527 seconds
  • 查询

    1. hive> select * from cos;
    2. OK
    3. 1001 en 85.0
    4. 1001 ma 100.0
    5. 1002 en 72.0
    6. 1002 ma 90.0
    7. 1003 en 60.0
    8. 1003 ma 85.0
    9. 1004 en 95.0
    10. 1004 ma 80.0
    11. 1005 en 88.0
    12. 1005 ma 70.0
    13. 1006 en 78.0
    14. 1006 ma 86.0
    15. 1007 en 81.0
    16. 1007 ma 60.0
    17. 1008 en 68.0
    18. 1008 ma 85.0
    19. Time taken: 0.195 seconds, Fetched: 16 row(s)