4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

beelineを利用してhiveでデータベースを作成してみる

Last updated at Posted at 2015-11-05

前回の投稿で、hiveのdockerコンテナを作成しました。

今回は、databaseの作成を実施しました。

参考

1. beelineでhiveserver2に接続

# コンテナにdocker-xecで/bin/bashで入ってから、beelineと入力

$ docker exec -it dockercompose_hiveserver2_1 /bin/bash
root@6a715b5d374e:/# beeline

# hiveserver2に接続
beeline> !connect jdbc:hive2://localhost:10000 hive hive org.apache.hive.jdbc.HiveDriver

2. databaseを作成してみる

0: jdbc:hive2://localhost:10000> show databases;
+----------------+--+
| database_name  |
+----------------+--+
| default        |
+----------------+--+
1 row selected (1.086 seconds)

0: jdbc:hive2://localhost:10000> create database if not exists erdrepo;
No rows affected (0.149 seconds)
0: jdbc:hive2://localhost:10000> show databases;
+----------------+--+
| database_name  |
+----------------+--+
| default        |
| erdrepo        |
+----------------+--+
2 rows selected (0.023 seconds)

if not exists構文も利用できるようです。

3. OS側のファイルを確認してみる

root@6a715b5d374e:/# ls -la /user/hive/warehouse/
total 20
drwxr-xr-x 5 hive root 4096 Nov  5 02:30 .
drwxr-xr-x 4 hive root 4096 Nov  2 16:46 ..
drwxr-xr-x 2 hive hive 4096 Nov  5 02:30 erdrepo.db

/user/hive/warehouseの下に、erdrepo.dbが生成されたことが確認できます。

4. queryからも確認できないのか。

できます。 describe database構文。

0: jdbc:hive2://localhost:10000> describe database erdrepo;
+----------+----------+---------------------------------------+-------------+-------------+-------------+--+
| db_name  | comment  |               location                | owner_name  | owner_type  | parameters  |
+----------+----------+---------------------------------------+-------------+-------------+-------------+--+
| erdrepo  |          | file:/user/hive/warehouse/erdrepo.db  | hive        | USER        |             |
+----------+----------+---------------------------------------+-------------+-------------+-------------+--+

5. databaseに属性(properties)を付与する。

alter database erdrepo set db properties ('used_system' = 'my cloud');
1 row selected (0.024 seconds)

0: jdbc:hive2://localhost:10000> describe database extended erdrepo;
+----------+----------+---------------------------------------+-------------+-------------+-------------------------+--+
| db_name  | comment  |               location                | owner_name  | owner_type  |       parameters        |
+----------+----------+---------------------------------------+-------------+-------------+-------------------------+--+
| erdrepo  |          | file:/user/hive/warehouse/erdrepo.db  | hive        | USER        | {used_system=my cloud}  |
+----------+----------+---------------------------------------+-------------+-------------+-------------------------+--+
1 row selected (0.029 seconds)

parametersを表示させるには、describe構文にextendedが必要な模様。

6. databaseにコメントを付与する

あとから、コメントできない。。。ぽい。。
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-Create/Drop/AlterDatabase

諦めて今日は再作成する

0: jdbc:hive2://localhost:10000> drop database erdrepo;
No rows affected (0.205 seconds)
0: jdbc:hive2://localhost:10000> create database erdrepo comment 'erd objects management tool' with dbproperties ('used_system' = 'my cloud' );
No rows affected (0.039 seconds)
0: jdbc:hive2://localhost:10000> describe database extended erdrepo;
+----------+------------------------------+---------------------------------------+-------------+-------------+-------------------------+--+
| db_name  |           comment            |               location                | owner_name  | owner_type  |       parameters        |
+----------+------------------------------+---------------------------------------+-------------+-------------+-------------------------+--+
| erdrepo  | erd objects management tool  | file:/user/hive/warehouse/erdrepo.db  | hive        | USER        | {used_system=my cloud}  |

7. MySQLの構文もみてみた。

create databaseで、commentとかdbpropertiesみたいなものは付与できない様子。DBが変わるといろいろ違ってきますね。


今日はここまでとします。

他のデータベースってコメントつけたりできるんだっけ。とか、ストレージ領域として、s3n,hdfs,maprfsもあるのかー、みたいなとこも気になります。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?