hive创建表

  • 正常创建表:create table test(id int, name string, age string, tel string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' STORED AS TEXTFILE;
  • load命令可以将hdfs上和本地文件系统中的文件添加hive表中,注意确保列分隔符和创建表的分隔符一样
    • test.txt文件:
                    1 name1 10 1131
                    2 name2 11 1110
    • hdfs[这种方式是移动hdfs文件到hive仓库中,加载后hdfs中就不存在源文件了]:load data inpath '/home/test/test.txt' into table test
    • 本地:load data local inpath '/home/test/test.txt' into table test
  • 从别的表中查询出相应的数据并导入到Hive表中:
    • 创建表:create table test(id int, name string,tel string) partitioned by (age int) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' STORED AS TEXTFILE;
    • 导入数据:insert into table test partition (age='25') select id, name, tel from wyp
  • 创建表时关联HDFS数据,注意location后为hdfs的文件目录create external table test(id int, name string,  age string, tel string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' location '/aaa/';
  • 实际上外表不光可以指定hdfs的目录,本地的目录也是可以的。
    比如:
    create external table test(id int, name string,  age string, tel string)
    ROW FORMAT DELIMITED
    FIELDS TERMINATED BY '\t'
    LOCATION 'file:home/hjl/lwx/';

版权声明:本文为xiaolinzi007原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。