Querying MongoDB data in Zepplin using spark SQL

Source: Internet
Author: User

1. Download Zepplin

Go to the official website and download the full tar package.

2. Unzip
tar zxvf zeppelin-0.7. 3. tgz
3. Modify the Configuration

New configuration file

CP zeppelin-env. sh. Template zeppelin-env. SH

Modifying a configuration file

VI zeppelin-env. SH

# Set the Java home path

Export JAVA_HOME=/USR/LIB/JVM/JAVA-1.8.0-OPENJDK-1.8.0.141-1.B16.EL7_3.X86_64/JRE

# Set Spark Master Address

Export master=spark://10.100.12.16:7077

# Set Spark Home path

Export spark_home=/opt/spark/

# set Spark MongoDB Connector, note: Here is 2.2.2 version

Export spark_submit_options= "--packages org.mongodb.spark:mongo-spark-connector_2.11:2.2.2"

4. Start Zepplin
Bin/zeppelin-daemon. SH start
5. Use the browser to enter Zepplin backstage: http://localhost:8080

6. Click Notebook to create a new query.

7. Write Scala Query code

ImportCom.mongodb.spark.config.ReadConfigImportcom.mongodb.spark.sql._val config=SqlContext.sparkContext.getConf.set ("Spark.mongodb.keep_alive_ms", "15000"). Set ("Spark.mongodb.input.uri", "mongodb://10.100.12.14:27017"). Set ("Spark.mongodb.input.database", "BI"). Set ("Spark.mongodb.input.collection", "usergroupmapping") Val Readconfig=readconfig (config) Val objusergroupmapping=SqlContext.read.format ("Com.mongodb.spark.sql"). MONGO (Readconfig) Objusergroupmapping.printschema () Val tbusergroupmapping=objusergroupmapping.todf () tbusergroupmapping.registertemptable ("Usergroupmapping")
8. Returning Query Results

Querying MongoDB data in Zepplin using spark SQL

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.