大数据技术_Hive_总结

查看数据库

0: jdbc:hive2://hadoop102:10000> show databases;
0: jdbc:hive2://hadoop102:10000> show databases like "m.*";
0: jdbc:hive2://hadoop102:10000> show databases like 'm.*';

注: describe  的简写就是 desc databases 关键字必须有。

0: jdbc:hive2://hadoop102:10000> show databases;
+----------------+--+
| database_name  |
+----------------+--+
| default        |
| financials     |
| mydb1          |
| myhivedb       |
+----------------+--+
4 rows selected (0.031 seconds)
0: jdbc:hive2://hadoop102:10000> show databases like "m.*";
+----------------+--+
| database_name  |
+----------------+--+
| mydb1          |
| myhivedb       |
+----------------+--+
2 rows selected (0.054 seconds)
0: jdbc:hive2://hadoop102:10000> show databases like 'm.*';
+----------------+--+
| database_name  |
+----------------+--+
| mydb1          |
| myhivedb       |
+----------------+--+
2 rows selected (0.023 seconds)

查看数据库的时候可以使用通配符(Like)或者正则表达式(RLike),关键字必须有,通配符或者正则表达式用单引号双引号都可以。

查看数据库的详细信息:

0: jdbc:hive2://hadoop102:10000> desc database myhivedb;
0: jdbc:hive2://hadoop102:10000> describe database myhivedb;
0: jdbc:hive2://hadoop102:10000> describe database extended myhivedb;

注:关键字 database 必须有。

0: jdbc:hive2://hadoop102:10000> desc myhivedb;
Error: Error while compiling statement: FAILED: SemanticException [Error 10001]: Table not found myhivedb (state=42S02,code=10001)
0: jdbc:hive2://hadoop102:10000> desc database myhivedb;
+-----------+----------+--------------------------------------------------------+-------------+-------------+-------------+--+
|  db_name  | comment  |                        location                        | owner_name  | owner_type  | parameters  |
+-----------+----------+--------------------------------------------------------+-------------+-------------+-------------+--+
| myhivedb  |          | hdfs://hadoop102:9000/user/hive/warehouse/myhivedb.db  | atguigu     | USER        |             |
+-----------+----------+--------------------------------------------------------+-------------+-------------+-------------+--+
1 row selected (0.031 seconds)
0: jdbc:hive2://hadoop102:10000> describe  database myhivedb;
+-----------+----------+--------------------------------------------------------+-------------+-------------+-------------+--+
|  db_name  | comment  |                        location                        | owner_name  | owner_type  | parameters  |
+-----------+----------+--------------------------------------------------------+-------------+-------------+-------------+--+
| myhivedb  |          | hdfs://hadoop102:9000/user/hive/warehouse/myhivedb.db  | atguigu     | USER        |             |
+-----------+----------+--------------------------------------------------------+-------------+-------------+-------------+--+
1 row selected (0.034 seconds)
0: jdbc:hive2://hadoop102:10000> describe  database extended myhivedb;
+-----------+----------+--------------------------------------------------------+-------------+-------------+-------------+--+
|  db_name  | comment  |                        location                        | owner_name  | owner_type  | parameters  |
+-----------+----------+--------------------------------------------------------+-------------+-------------+-------------+--+
| myhivedb  |          | hdfs://hadoop102:9000/user/hive/warehouse/myhivedb.db  | atguigu     | USER        |             |
+-----------+----------+--------------------------------------------------------+-------------+-------------+-------------+--+
1 row selected (0.029 seconds)

 查看表

0: jdbc:hive2://hadoop102:10000> use myhivedb;
0: jdbc:hive2://hadoop102:10000> show tables;
0: jdbc:hive2://hadoop102:10000> show tables in myhivedb; 

0: jdbc:hive2://hadoop102:10000> show tables;
0: jdbc:hive2://hadoop102:10000> show tables like "m.*";
0: jdbc:hive2://hadoop102:10000> show tables like 'm.*';
0: jdbc:hive2://hadoop102:10000> show tables 'm.*';

和查询数据库不同,这里的 like 可加可不加,但是查询数据的时候必须加( show databases like "m.*";

0: jdbc:hive2://hadoop102:10000> desc employess;
0: jdbc:hive2://hadoop102:10000> desc formatted employess;
0: jdbc:hive2://hadoop102:10000> desc extended employess; 

 查询表的类型(Table Type)等详细信息需要使用 desc formatted employess 使用 desc extended employess 会看不清楚。

0: jdbc:hive2://hadoop102:10000> desc employess.salary;

可以单独查一个属性

0: jdbc:hive2://hadoop102:10000> desc employess.salary;
+-----------+------------+--------------------+--+
| col_name  | data_type  |      comment       |
+-----------+------------+--------------------+--+
| salary    | float      | from deserializer  |
+-----------+------------+--------------------+--+
1 row selected (0.1 seconds)
0: jdbc:hive2://hadoop102:10000> use myhivedb;
No rows affected (0.03 seconds)
0: jdbc:hive2://hadoop102:10000> show tables;
+------------+--+
|  tab_name  |
+------------+--+
| employess  |
| mytable    |
| mytable2   |
| some_data  |
+------------+--+
4 rows selected (0.037 seconds)
0: jdbc:hive2://hadoop102:10000> show tables in myhivedb; 
+------------+--+
|  tab_name  |
+------------+--+
| employess  |
| mytable    |
| mytable2   |
| some_data  |
+------------+--+
4 rows selected (0.035 seconds)
0: jdbc:hive2://hadoop102:10000> 

0: jdbc:hive2://hadoop102:10000> desc employess;
+---------------+---------------------------------------------------------+----------+--+
|   col_name    |                        data_type                        | comment  |
+---------------+---------------------------------------------------------+----------+--+
| name          | string                                                  |          |
| salary        | float                                                   |          |
| subordinates  | array                                           |          |
| deductions    | map                                       |          |
| address       | struct  |          |
+---------------+---------------------------------------------------------+----------+--+
5 rows selected (0.071 seconds)
0: jdbc:hive2://hadoop102:10000> desc formatted employess;
+-------------------------------+------------------------------------------------------------------+-----------------------+--+
|           col_name            |                            data_type                             |        comment        |
+-------------------------------+------------------------------------------------------------------+-----------------------+--+
| # col_name                    | data_type                                                        | comment               |
|                               | NULL                                                             | NULL                  |
| name                          | string                                                           |                       |
| salary                        | float                                                            |                       |
| subordinates                  | array                                                    |                       |
| deductions                    | map                                                |                       |
| address                       | struct           |                       |
|                               | NULL                                                             | NULL                  |
| # Detailed Table Information  | NULL                                                             | NULL                  |
| Database:                     | myhivedb                                                         | NULL                  |
| Owner:                        | atguigu                                                          | NULL                  |
| CreateTime:                   | Sat Apr 20 21:31:53 CST 2019                                     | NULL                  |
| LastAccessTime:               | UNKNOWN                                                          | NULL                  |
| Protect Mode:                 | None                                                             | NULL                  |
| Retention:                    | 0                                                                | NULL                  |
| Location:                     | hdfs://hadoop102:9000/user/hive/warehouse/myhivedb.db/employess  | NULL                  |
| Table Type:                   | MANAGED_TABLE                                                    | NULL                  |
| Table Parameters:             | NULL                                                             | NULL                  |
|                               | transient_lastDdlTime                                            | 1555767113            |
|                               | NULL                                                             | NULL                  |
| # Storage Information         | NULL                                                             | NULL                  |
| SerDe Library:                | org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe               | NULL                  |
| InputFormat:                  | org.apache.hadoop.mapred.TextInputFormat                         | NULL                  |
| OutputFormat:                 | org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat       | NULL                  |
| Compressed:                   | No                                                               | NULL                  |
| Num Buckets:                  | -1                                                               | NULL                  |
| Bucket Columns:               | []                                                               | NULL                  |
| Sort Columns:                 | []                                                               | NULL                  |
| Storage Desc Params:          | NULL                                                             | NULL                  |
|                               | serialization.format                                             | 1                     |
+-------------------------------+------------------------------------------------------------------+-----------------------+--+
30 rows selected (0.075 seconds)
0: jdbc:hive2://hadoop102:10000> 

 

 

 

你可能感兴趣的:(大数据_Hive)