Import Mongodb data to hive method one

Source: Internet
Author: User
Tags mongodb
How to import MongoDB data into hive.
Principle:
By default, any table created in Hive is hdfs-based; That's, the metadata and underlying rows of data associated with the table are stored in HDFS. Mongo-hadoop now supports the creation of mongodb-based Hive tables and bson-based tables. Both mongodb-based Hive tables and bson-based Hive tables can be:
Queried just like hdfs-based Hive tables. Combined with hdfs-based Hive tables in joins and Sub-queries
The explanation here is to first create a hive-base table in the hive, only schema information, the actual data exists in MongoDB.
Pre-Preparation: 1. Download or build source code to generate the jar package. Mongodb-hadoop-core, mongodb-hadoop-hive jar package. 2. Get Mongdb-java-driver. 3. Add to Hive. ADD Jar/path-to/mongo-hadoop-hive-<version>.jar
Start, build a table:
CREATE TABLE individuals (id int, name STRING, age INT, Work struct<title:string, hours:int>) STORED by ' C Om.mongodb.hadoop.hive.MongoStorageHandler ' with serdeproperties (' mongo.columns.mapping ' = ' {' id ': ' _id ', ' Work.title ":" Job.position "}") tblproperties (' mongo.uri ' = ' mongodb://localhost:27017/test.persons ');

Ok. The appearance has been created well. Next, you can query the MongoDB data in hive. Start query:
SELECT name, age from individuals WHERE ID > 100;
============= I'm a split line ==============================
You can then use the CREATE TABLE select * ... To build the table. or create table first. Then insert INTO ... SELECT * ...
Both of these can migrate MongoDB data to hive.






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.