Hive Project Development Environment Setup (Eclipse\myeclipse + Maven)

Source: Internet
Author: User

Write it in front.

Can be detailed reference, must go to see

HBase Development Environment Building (Eclipse\myeclipse + Maven) Zookeeper Project development environment (Eclipse\myeclipse + maven)

I am here, I believe, can see this blog friend, presumably there is a certain foundation. I wrote a lot of basic blog posts earlier. can be used to fill the ground.

Step One: Maven project, Project, File, New

Step two: Set up your own, myhbase project to be created, in which directory.

Step Three:

Step Four: Set yourself

Step five: Modify the JDK

omitted, very simple!

Step Six: Modify the Pom.xml configuration file

Website Maven Zookeeper configuration file content:

Address: http://www.mvnrepository.com/search?q=hive

1.

2.

3.

4.

5.

6.

For the time being, you can add it to yourself later.

The final pom.xml configuration file is

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
<modelVersion>4.0.0</modelVersion>

<groupId>zhouls.bigdata</groupId>
<artifactId>myHive</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>myHive</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!--https://mvnrepository.com/artifact/org.apache.hive/hive-exec--
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>1.2.1</version>
</dependency>
<!--Https://mvnrepository.com/artifact/org.apache.hive/hive-metastore--
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-metastore</artifactId>
<version>1.2.1</version>
</dependency>
<!--Https://mvnrepository.com/artifact/org.apache.hive/hive-common--
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-common</artifactId>
<version>1.2.1</version>
</dependency>
<!--Https://mvnrepository.com/artifact/org.apache.hive/hive-service--
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-service</artifactId>
<version>1.2.1</version>
</dependency>
<!--HTTPS://MVNREPOSITORY.COM/ARTIFACT/ORG.APACHE.HIVE/HIVE-JDBC--
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.2.1</version>
</dependency>
<!--Https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common--
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
</dependencies>
</project>

Of course, this is only a preliminary, the simplest, can be deleted by themselves later.

Reference: Implementation of the JDBC Interface for hive (Eclipse environment configuration)

Before using JDBC to link hive, the first thing to do is to turn on the Hive Listener user's connection. That is, before you run the code, you need to

Here's how to open the Hive service:

Hive--service hiveserver >/dev/null 2>/dev/null&

Step Seven: Here, let's show you some of the features of hive through a simple set of hive application instances.

Class name is Hivetestcase.java

Package zhouls.bigdata.myHive;


Import java.sql.Connection;
Import Java.sql.DriverManager;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.sql.Statement;

Import Org.apache.log4j.Logger;

/**
* Handle data through hive on eclipse
* @author Zhouls
* @time 2016\11\12 22:14
*/
public class Hivetestcase {

private static String drivername = "Org.apache.hadoop.hive.jdbc.HiveDriver";
private static String URL = "Jdbc:hive://192.168.80.11:10000/default";
private static String user = "";
private static String password = "";
private static String sql = "";
private static ResultSet Res;
Private static final Logger log = Logger.getlogger (Hivetestcase.class);

public static void Main (string[] args) {
try {
Class.forName (drivername); Registering the JDBC Driver
Connection conn = drivermanager.getconnection (URL, user, password);

By default, use port 10000, default database, user name password default
Connection conn = drivermanager.getconnection ("Jdbc:hive://192.168.181.128:10000/default", "", "" ");
Connection conn = drivermanager.getconnection ("Jdbc:hive://hadoopmaster:10000/default", "", "" ");
Of course, if the 3 node cluster, then hadoopmaster or HadoopSlave1 or HadoopSlave2 can do it. If hive is installed on each of them, it is sufficient to install only one.

statement used to execute SQL statements
Statement stmt = Conn.createstatement ();

Name of the table created
String tableName = "testhivedrivertable";

/** First step: Delete the **/before it exists
sql = "DROP table" + TableName;
Stmt.executequery (SQL);

/** Second Step: Create **/if not present
sql = "CREATE TABLE" + TableName +
"(userid int," +
"MovieID int," +
"Rating int," +
"City string," +
"Viewtime string)" +
"Row format delimited" +
"Fields terminated by ' \ t '" +
"Stored as textfile";

sql = "CREATE TABLE" + TableName + "(key int, value string) row format delimited fields terminated by ' \ t '";
Stmt.executequery (SQL);

Perform a "Show tables" operation
sql = "Show tables '" + tableName + "'";
System.out.println ("Running:" + sql);
res = stmt.executequery (SQL);
System.out.println ("Execute" Show tables "Run Result:");
if (Res.next ()) {
System.out.println (res.getstring (1));
}

Perform the describe table operation
sql = "describe" + tableName;
System.out.println ("Running:" + sql);
res = stmt.executequery (SQL);
System.out.println ("Execute" describe table "Run result:");
while (Res.next ()) {
System.out.println (res.getstring (1) + "\ T" + res.getstring (2));
}

Perform the "Load data into table" operation
String filepath = "/home/hadoop/file/test2_hive.txt";
sql = "Load data local inpath '" + filepath + "' into table" + tableName;
System.out.println ("Running:" + sql);
res = stmt.executequery (SQL);

Perform a "select * query" operation
sql = "SELECT * from" + tableName;
System.out.println ("Running:" + sql);
res = stmt.executequery (SQL);
System.out.println ("Execute" SELECT * query "Run result:");
while (Res.next ()) {
System.out.println (Res.getint (1) + "\ T" + res.getstring (2));
}

Perform the regular Hive query action
sql = "SELECT COUNT (1) from" + TableName;
System.out.println ("Running:" + sql);
res = stmt.executequery (SQL);
System.out.println ("Execute" Regular hive query "Run Result:");
while (Res.next ()) {
System.out.println (res.getstring (1));

}

Conn.close ();
conn = null;
} catch (ClassNotFoundException e) {
E.printstacktrace ();
Log.error (drivername + "Not found!", e);
System.exit (1);
} catch (SQLException e) {
E.printstacktrace ();
Log.error ("Connection error!", e);
System.exit (1);
}

}
}

Hive Project Development Environment Setup (Eclipse\myeclipse + Maven)

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.