In the hive/bin directory, enter./hive -- service hiveserver to indicate that hive has started the server mode.
Unlike normal mode, hive starts a server named thrift at the same time.
You don't need to study the principle of this server. You just need to think that it is a person who transmits information. You can send commands to hive and then hive sends the commands to hadoop.
1. Command Line Mode:
./Hive-h127.0.0.1-P10000
Simple and clear, IP and port.
2. JDBC mode:
The name is confusing.
Private Static string drivername = "org. Apache. hadoop. hive. JDBC. hivedriver ";
@ Beforeclass
Public static void beforeclass () throws sqlexception,
Classnotfoundexception {
Class. forname (drivername );
Connection con = drivermanager. getconnection (
"JDBC: Hive: // 127.0.0.1: 10000/Default ","","");
Stmt = con. createstatement ();
}
@ Test
Public void droptable (){
Try {
Res = stmt.exe cutequery ("Drop table" + tablename );
Res = stmt.exe cutequery ("Drop table" + basetable );
// Res = stmt.exe cutequery ("Drop table" + agecount );
} Catch (sqlexception e ){
E. printstacktrace ();
}
}
The preceding Code deletes a table through JDBC.
Compared with traditional JDBC, I think hive's JDBC features and ease of use are much worse.
However, the hive statement style is similar to that of traditional SQL, so people invented this. It's a bit nondescribable. It is not very good in terms of uadf, not very fond of it.
3. Java client
TTransport transport;
Tprotocol protocol;
Hiveclient client;
Transport = new tsocket ("localhost", 10000 );
Protocol = new tbinaryprotocol (transport );
Client = new hiveclient (Protocol );
Transport. open ();
Client.exe cute ("select usercount (userid) from user3 ");
Transport. Close ();
Obviously, we call the hive API to generate a Java hive client, which has the same effect as the command line client.
I like this because UDAF provides perfect support for parameter modification.