Spark SQL Hive Support Demo

Source: Internet
Author: User

Premise:

1, spark1.0 Package compile time to specify the support hive:./make-distribution.sh--hadoop 2.3.0-cdh5.0.0--with-yarn --with-hive --tgz

2, installation finished spark1.0;

3. Install the CDH version of hive corresponding to Hadoop;

Spark SQL supports hive cases:

1. Copy the Hive-site.xml configuration file to $spark_home/conf

Hive-site.xml file contents are as follows:

<?xml version= "1.0"? ><?xml-stylesheet type= "text/xsl" href= "configuration.xsl"?><configuration>    <property>      <name>javax.jdo.option.ConnectionURL</name>      <value>jdbc:mysql: //hadoop000 :3306/hive?createdatabaseifnotexist=true</value>    </property>    <property>      <name>javax.jdo.option.ConnectionDriverName</name>      <value>com.mysql.jdbc.Driver</value>    </property>    <property>      <name> javax.jdo.option.connectionusername</name>      <value>root</value>    </property>    <property>      <name>javax.jdo.option.ConnectionPassword</name>      <value> Root</value>    </property></configuration>

2. Start Spark:spark-shell

The case comes from Spark's official document: http://spark.apache.org/docs/latest/sql-programming-guide.html

//Create HivecontextVal Hivecontext =NewOrg.apache.spark.sql.hive.HiveContext (SC)//Implicit conversionsImporthivecontext._//Creating hive TablesHQL ("CREATE TABLE IF not EXISTS hive.kv_src (key INT, value STRING)")//load data into hive tableHQL ("LOAD DATA LOCAL inpath '/home/spark/app/spark-1.0.0-bin-2.3.0-cdh5.0.0/examples/src/main/resources/kv1.txt ' Into TABLE hive.kv_src ")//Query by HQLHQL ("From Hive.kv_src SELECT key, Value"). Collect (). foreach (println)

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.