java - 如何将表导入本地文件系统?

标签 java hive hdfs hiveql

我正在尝试从配置单元中的表导出结果并使用此命令:

bline --hiveconf hive.mapred.mode=nonstrict --outputformat=csv2 -e "select * from db.table;">~/table.csv

(bline is an alias for beeline -u address + some options)

查询完成但随后给了我

error java.lang.OutOfMemoryError: GC overhead limit exceeded

我导出表是否正确,或者是否有更好的方法在 Hive 中导出表?

最佳答案

由于您的表是以文本格式存储的,您可以简单地使用get/getmerge 将文件从 HDFS 复制到本地文件系统


演示

hive

create table mytable (i int,s string,d date);

insert into mytable values 
    (1,'hello','2017-03-01')
   ,(2,'world','2017-03-02')
;

select * from mytable
;

mytable.i   mytable.s   mytable.d
1   hello   2017-03-01
2   world   2017-03-02

show create table mytable;

CREATE TABLE `mytable`(
  `i` int, 
  `s` string, 
  `d` date)
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  'hdfs://localhost:8020/user/hive/warehouse/mytable'
.
.
.

狂欢

hdfs dfs -getmerge /user/hive/warehouse/mytable mytable.txt

cat mytable.txt 

1hello2017-03-01
2world2017-03-02

附言 列之间有一个看不见的分隔符,字符 SOH,ascii 值为 1。

<mytable.txt tr $'\x01' ','
1,hello,2017-03-01
2,world,2017-03-02

关于java - 如何将表导入本地文件系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42561609/

相关文章:

java - 这些java代码与if-else有什么区别? : operator

java - 按时间间隔测试代码

amazon-s3 - Hive外部表: what if the table is accessed during the underlying directory is being updated

hadoop - 如何使用HDFS Shell访问两个或多个远程Hadoop文件系统?

algorithm - gzip 文件如何存储在 HDFS 中

Java hashmap 构建 <String, Integer>

java - 将对象从过滤器返回到资源

java - 使用java创建impala表并添加数据

hadoop - hive >插入覆盖表/本地目录不起作用

python - 如何仅将新索引附加到具有 HDFS 存储的表