Hive QL

 

0: jdbc:hive2://10.121.63.240:10000> CREATE TABLE pokes (foo INT, bar STRING);
No rows affected (1.93 seconds)
0: jdbc:hive2://10.121.63.240:10000> show tables;
+-----------+
| tab_name  |
+-----------+
| alice     |
| pokes     |
+-----------+
0: jdbc:hive2://10.121.63.240:10000>  DESCRIBE pokes;
+-----------+------------+----------+
| col_name  | data_type  | comment  |
+-----------+------------+----------+
| foo       | int        |          |
| bar       | string     |          |
+-----------+------------+----------+

 

 

0: jdbc:hive2://10.121.63.240:10000> create table alice(line string);
No rows affected (0.916 seconds)
0: jdbc:hive2://10.121.63.240:10000> show tables;
+-----------+
| tab_name  |
+-----------+
| alice     |
| pokes     |
+-----------+
2 rows selected (0.073 seconds)
0: jdbc:hive2://10.121.63.240:10000> describ alice;
0: jdbc:hive2://10.121.63.240:10000> describe alice;
+-----------+------------+----------+
| col_name  | data_type  | comment  |
+-----------+------------+----------+
| line      | string     |          |
+-----------+------------+----------+
1 row selected (0.168 seconds)
//导入文件/home/hadoop/soft/LICENSE
0: jdbc:hive2://10.121.63.240:10000> load data local inpath '/home/hadoop/soft/LICENSE' into table alice;
No rows affected (0.827 seconds)
0: jdbc:hive2://10.121.63.240:10000> select * from alice;
+----------------------------------------------------+
|                     alice.line                     |
+----------------------------------------------------+
|                                  Apache License    |
|                            Version 2.0, January 2004 |
|                         http://www.apache.org/licenses/ |
|    TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION |
|    1. Definitions.                                 |
|       "License" shall mean the terms and conditions for use, reproduction, |
|       and distribution as defined by Sections 1 through 9 of this document. |
|                                                    |
|       "Licensor" shall mean the copyright owner or entity authorized by |
|       the copyright owner that is granting the License. |
+----------------------------------------------------+
10 rows selected (1.372 seconds)
// 统计前3行有多少个单词
0: jdbc:hive2://10.121.63.240:10000> select split(line,' ') from alice where line!='' limit 3;
+----------------------------------------------------+
|                        _c0                         |
+----------------------------------------------------+
| ["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","Apache","License"] |
| ["","","","","","","","","","","","","","","","","","","","","","","","","","","","Version","2.0,","January","2004"] |
| ["","","","","","","","","","","","","","","","","","","","","","","","","http://www.apache.org/licenses/"] |
+----------------------------------------------------+
3 rows selected (0.629 seconds)
//统计每一行有多少个单词
0: jdbc:hive2://10.121.63.240:10000> select size(split(line,' ')) from alice;
+------+
| _c0  |
+------+
| 35   |
| 31   |
| 25   |
| 11   |
| 5    |
| 16   |
| 18   |
| 1    |
| 16   |
| 14   |
+------+
10 rows selected (0.222 seconds)

 

posted @ 2019-03-05 16:37  牧 天  阅读(109)  评论(0)    收藏  举报