2012-08-10 35 views
2

我将DynamoDB表导出为s3作为备份(通过EMR)。当我导出时,我将数据存储为lzo压缩文件。我的配置单元查询在下面,但基本上我遵循了“使用数据压缩将Amazon DynamoDB表导出到Amazon S3存储桶”http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/EMR_Hive_Commands.html将s3中的压缩(lzo)数据导入配置单元

我现在想做相反的操作 - 取出我的LZO文件并获取他们回到一个蜂巢表。你怎么做到这一点?我期待看到一些hive configuration property的输入,但没有。我搜索了一下,发现了一些提示,但没有明确的说明,也没有什么可行的。

文件中S3的格式为:S3:// [mybucket] /backup/year=2012/month=08/day=01/000000.lzo

这里是我的HQL,做出口:

SET dynamodb.throughput.read.percent=1.0; 
SET hive.exec.compress.output=true; 
SET io.seqfile.compression.type=BLOCK; 
SET mapred.output.compression.codec = com.hadoop.compression.lzo.LzopCodec;  

CREATE EXTERNAL TABLE hiveSBackup (id bigint, periodStart string, allotted bigint, remaining bigint, created string, seconds bigint, served bigint, modified string) 
STORED BY 'org.apache.hadoop.hive.dynamodb.DynamoDBStorageHandler' 
TBLPROPERTIES ("dynamodb.table.name" = "${DYNAMOTABLENAME}", 
"dynamodb.column.mapping" = "id:id,periodStart:periodStart,allotted:allotted,remaining:remaining,created:created,seconds:seconds,served:served,modified:modified"); 

CREATE EXTERNAL TABLE s3_export (id bigint, periodStart string, allotted bigint, remaining bigint, created string, seconds bigint, served bigint, modified string) 
PARTITIONED BY (year string, month string, day string) 
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' 
LOCATION 's3://<mybucket>/backup'; 

INSERT OVERWRITE TABLE s3_export 
PARTITION (year="${PARTITIONYEAR}", month="${PARTITIONMONTH}", day="${PARTITIONDAY}") 
SELECT * from hiveSBackup; 

任何想法如何从S3,解压缩到蜂巢表?

回答

5

Hive on EMR可以直接从S3读取数据,不需要导入任何内容。你只需要创建一个外部表并告诉它数据在哪里。 它也有lzo支持设置。如果文件以.lzo扩展名结尾,则Hive将自动使用lzo进行解压缩。因此,要将s3中的lzo数据导入到配置单元中,您只需创建一个指向lzo压缩数据s3的外部表,并且配置单元在每次运行查询时都会对其进行解压缩。与您在“导出”数据时完全一样。那s3_export表,你也可以从中读取。

如果要将其导入到非外部表中,只需将覆盖插入到一个新表中,然后从外部表中进行选择。

除非我误解了你的问题,你打算询问关于导入到发电机,而不仅仅是一个配置单元表?

This is what I've been doing 
SET hive.exec.compress.output=true; 
SET io.seqfile.compression.type=BLOCK; 
SET mapred.output.compression.codec = com.hadoop.compression.lzo.LzopCodec; 

CREATE EXTERNAL TABLE users 
(id int, username string, firstname string, surname string, email string, birth_date string) 
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' 
STORED AS TEXTFILE 
LOCATION 's3://bucket/someusers'; 

INSERT OVERWRITE TABLE users 
SELECT * FROM someothertable; 

我结束了下S3一堆文件://桶/与.lzo扩展其是由蜂巢可读someusers。

您只需在尝试写入压缩数据时设置编码解码器,读取它即可自动检测压缩。

+0

你有一个完整的示例hql脚本,它的工作原理?我试过你提到的没有成功。我的数据再次分区。我只是想导入蜂巢,而不是发电机。 – rynop 2012-09-18 15:44:10

+0

编辑我的答案添加一个例子。 – Tim 2012-09-18 16:47:42