hive -e "SQL query" > xxx.csv
sed -i 's/\t/,/g' xxx.csv
2. Hive导入.csv文件建表
注意:
为了配合csv文件,建表的时候,最后一行的row format delimited fields terminated by ‘,’;必须要有,否则列会出问题
(这牵涉到csv和tsv等问题)
所以,在Hive下完整的删表建表导数据的流程如下:
drop table if exists table_name;CREATE EXTERNAL TABLE beike.beike_ershoufang ( details_name string,
postition_url string ,
house_url string,
house_id string,
house_info string,
follew_info string,
subway string,
total_price float,
total_price_danwei string,
unit_price float,
district string,
city_name string,
fetchtime timestamp
)COMMENT '贝壳二手房'PARTITIONED BY (dt STRING, cd3 STRING)row format delimited fields terminated by ',';load data local inpath '/home/andrew/output.csv'into table beike.beike_ershoufang PARTITION(dt='2017-03-31' ,cd3='1389');;
3. Hive看包括行数在内的信息
show tblproperties table_name;desc formatted table_name;
4. Hive一次写入一个表的多个分区的数据
set hive.exec.dynamic.partition=true;set hive.exec.dynamic.partition.mode=nonstrict;insert overwrite table table1 partition(partition_column)select col1, col2,..., partition_column from table1;
5. Hive一次写入大量分区
set hive.exec.max.dynamic.partitions=100000;
--每一个mapreduce job允许创建的分区的最大数量,如果超过了这个数量就会报错
set hive.exec.max.dynamic.partitions.pernode=100000;
--hive.exec.max.created.files :所有的mapreduce job允许创建的文件的最大数量
set hive.exec.max.created.files=10000;