2
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.

Pythonでhbaseをいじる

Last updated at Posted at 2018-07-14

はじめに

Pythonでhbaseをいじる際には happybaseを用いることが多いと思います。
ただ、happybaseで対応してないコマンドもあり、その場合はhbaseのshellコマンドを直接用いることしかないと思います。
このページでは、hbase上でよくやる作業をまとめておきたいと思います。乱雑ですが、ご容赦ください。

tableの一覧表示

happybaseでできるのだろうか?
hbaseのshellコマンドで行なった。

$ hbase shell
> list

ns_1:table_1
ns_1:table_2
ns_2:table_1

ns_1,ns_2はネームスペース。table_1、table_2はテーブル名。
ネームスペースが異なれば、テーブル名が被っても問題ない。

namespaceの作成

happybaseではできなそう。

> create_namespace "ns_3"

参考:http://www.task-notes.com/entry/20160321/1458538973

tableの作成

happybaseで行える。

families = {
    'cf1': dict(max_versions=10),
    'cf2': dict(max_versions=1, block_cache_enabled=False),
    'cf3': dict(),  # use defaults
}
connection.create_table('ns_3:table_1', families)

ただし、namespaceを指定する場合(上記のns_3)は、事前にhbaseのshellコマンドで作成しておく必要がある。

参考:http://happybase.readthedocs.io/en/latest/api.html#happybase.Connection.create_table

tableの削除

happybaseで行える。

connection.delete_table("ns_1:table_1", disable=True)

hbaseはtableを削除するには、テーブルの停止→削除と二段階踏む必要がある。disable=Trueはテーブルの停止も同時に行うオプション。

tableのfamiliesの確認

table = connection.table("ns_1:table_1")
table.families()

table内の特定familiesの削除

hbaseではあるカラムに入ったデータを一括で削除することはできないようだ。
だが、families単位であれば、一括で削除が可能なようだ。

参考:http://www.ne.jp/asahi/hishidama/home/tech/apache/hbase/shell.html#h_alter

だが、happybaseにはその機能は見当たらない。
そのため、複数カラムを一括で削除したい場合には、テーブルを分けておき、テーブルごと削除→再作成するのが良さそう。

2
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
2
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?