Monday 20 October 2014

Hive Connection with MongoDB

Hive Connection with MongoDB

Do the processing by hive and store the result into MongoDB.


Download the below jars form 'https://github.com/yc-huang/Hive-mongo/tree/master/release'

ADD JAR /home/hadoop/work/Hive-mongo-master/release/hive-mongo-0.0.2.jar;
ADD JAR /home/hadoop/work/Hive-mongo-master/release/hive-mongo-0.0.2-jar-with-dependencies.jar;
ADD JAR /home/hadoop/work/hive-0.10.0/lib/hive-metastore-0.10.0.jar;
ADD JAR /home/hadoop/work/guava-r06.jar;
ADD JAR /home/hadoop/work/mongo-java-driver-2.6.3.jar;

create table if not exists mongo_test(id int, name String, age int) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

load data local inpath '/home/hadoop/work/mongodata.txt' into table mongo_test;

create external table mongotable(id int, name string, age int)
stored by "org.yong3.hive.mongo.MongoStorageHandler"
with serdeproperties ( "mongo.column.mapping" = "_id,name,age" )
tblproperties ( "mongo.host" = "localhost", "mongo.port" = "27017",
"mongo.db" = "db", "mongo.collection" = "ravi" );

insert overwrite table mongotable select id, name, age from mongo_test;

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...