Hive的連線方式。。。。。
1、直接在安裝完hive之後,進入到bin目錄下面./hive啟動就ok了:
[[email protected] bin]$ ./hive
Logging initialized using configuration in file:/home/hadoop/apps/apache-hive-1.2.2-bin/conf/hive-log4j.properties
hive> show databases; //這樣就Ok了。
2、利用beeline方式。
首選退出上面的方式quit;
./hiveserver2 & //表示啟動到後臺,不佔用當前命令列。
PS:nohup 命令:如果你正在執行一個程序,而且你覺得在退出帳戶時該程序還不會結束, 那麼可以使用 nohup 命令。該命令可以在你退出帳戶/關閉終端之後繼續執行相應的程序。 nohup 就是不掛起的意思(no hang up)。 該命令的一般形式為:nohup command &
[[email protected] bin]$ ./beeline -u jdbc:hive2://172.16.0.37:10000 -n hadoop
Connecting to jdbc:hive2://172.16.0.37:10000
Connected to: Apache Hive (version 1.2.2)
Driver: Hive JDBC (version 1.2.2)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 1.2.2 by Apache Hive
0: jdbc:hive2://172.16.0.37:10000>
按照以上的方式去連線。-n 後面跟的是你的主機的使用者名稱
這是用的最多的兩種方式。
hive的高階資料結構的用法:
資料cdt.txt內容如下:
1 huangbo guangzhou,xianggang,shenzhen a1:30,a2:20,a3:100 beijing,112233,13522334455,500
2 xuzheng xianggang b2:50,b3:40 tianjin,223344,13644556677,600
3 wangbaoqiang beijing,zhejinag c1:200 chongqinjg,334455,15622334455,20
0: jdbc:hive2://172.16.0.37:10000> create table cdt(id int, name string, work_location array<string>, piaofang map<string, bigint>, address struct<location:string, zipcode:int, phone:string, value:int>) row format delimited fields terminated by "\t" collection items terminated by "," map keys terminated by ":" lines terminated by "\n";
No rows affected (0.44 seconds)
0: jdbc:hive2://172.16.0.37:10000> load data local inpath "/home/hadoop/cdt.txt" into table cdt;
INFO : Loading data to table myhive.cdt from file:/home/hadoop/cdt.txt
INFO : Table myhive.cdt stats: [numFiles=1, totalSize=224]
No rows affected (0.792 seconds)
0: jdbc:hive2://172.16.0.37:10000> select * from cdt;
+---------+---------------+---------------------------------------+-----------------------------+------------------------------------------------------------------------------+--+
| cdt.id | cdt.name | cdt.work_location | cdt.piaofang | cdt.address |
+---------+---------------+---------------------------------------+-----------------------------+------------------------------------------------------------------------------+--+
| 1 | huangbo | ["guangzhou","xianggang","shenzhen"] | {"a1":30,"a2":20,"a3":100} | {"location":"beijing","zipcode":112233,"phone":"13522334455","value":500} |
| 2 | xuzheng | ["xianggang"] | {"b2":50,"b3":40} | {"location":"tianjin","zipcode":223344,"phone":"13644556677","value":600} |
| 3 | wangbaoqiang | ["beijing","zhejinag"] | {"c1":200} | {"location":"chongqinjg","zipcode":334455,"phone":"15622334455","value":20} |
+---------+---------------+---------------------------------------+-----------------------------+------------------------------------------------------------------------------+--+
3 rows selected (0.161 seconds)
0: jdbc:hive2://172.16.0.37:10000> select work_location[1] from cdt; //表示訪問陣列
+------------+--+
| _c0 |
+------------+--+
| xianggang |
| NULL |
| zhejinag |
+------------+--+
3 rows selected (0.131 seconds)
0: jdbc:hive2://172.16.0.37:10000> select piaofang["a1"] from cdt; //查詢map結構
+-------+--+
| _c0 |
+-------+--+
| 30 |
| NULL |
| NULL |
+-------+--+
0: jdbc:hive2://172.16.0.37:10000> select address.phone from cdt; //查詢結構體的資料
+--------------+--+
| phone |
+--------------+--+
| 13522334455 |
| 13644556677 |
| 15622334455 |
+--------------+--+
3 rows selected (0.115 seconds)