php 如何清除hbase中的表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9902353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to clear a table in hbase?
提问by Micku
I want to empty a table in hbase... eg: user
. Is there any command or function to empty the table without deleting it...
我想清空 hbase 中的一个表...例如:user
。是否有任何命令或函数可以清空表而不删除它...
My table structure is :
我的表结构是:
$mutations = array(
new Mutation( array(
'column' => 'username:1',
'value' =>$name
) ),
new Mutation( array(
'column' => 'email:1',
'value' =>$email
) )
);
$hbase->mutateRow("user",$key,$mutations);
Can someone help me?
有人能帮我吗?
采纳答案by starl1ng
There's no single command to clear Hbase table, but you can use 2 workarounds: disable, delete, create table, or scan all records and delete each.
没有单一的命令可以清除 Hbase 表,但您可以使用 2 种解决方法:禁用、删除、创建表或扫描所有记录并删除每个记录。
Actually, disable, delete and create table again takes about 4 seconds.
实际上,禁用、删除和再次创建表大约需要 4 秒钟。
// get Hbase client
$client = <Your code here>;
$t = "table_name";
$tables = $client->getTableNames();
if (in_array($t, $tables)) {
if ($client->isTableEnabled($t))
$client->disableTable($t);
$client->deleteTable($t);
}
$descriptors = array(
new ColumnDescriptor(array("name" => "c1", "maxVersions" => 1)),
new ColumnDescriptor(array("name" => "c2", "maxVersions" => 1))
);
$client->createTable($t, $descriptors);
If there's not a lot of data in table - scan all rows and delete each is much faster.
如果表中的数据不多 - 扫描所有行并删除每一行会快得多。
$client = <Your code here>;
$t = "table_name";
// i don't remember, if list of column families is actually needed here
$columns = array("c1", "c2");
$scanner = $client->scannerOpen($t, "", $columns);
while ($result = $client->scannerGet($scanner)) {
$client->deleteAllRow($t, $result[0]->row);
}
In this case data is not deleted physically, actually it's "marked as deleted" and stays in table until next major compact.
在这种情况下,数据不会被物理删除,实际上它被“标记为已删除”并保留在表中直到下一个主要压缩。
回答by Alexis Gamarra
If you execute this in HBase shell:
如果您在 HBase shell 中执行此操作:
> truncate 'yourTableName'
Then HBase will execute this operations for 'yourTableName':
然后 HBase 将为“yourTableName”执行以下操作:
> disable 'yourTableName'
> drop 'yourTableName'
> create 'yourTableName', 'f1', 'f2', 'f3'
回答by André Staltz
Another efficient option is to actually delete the table then reconstruct another one with all the same settings as the previous.
另一个有效的选择是实际删除该表,然后使用与前一个相同的所有设置重建另一个表。
I don't know how to do this in php, but I do know how to do it in Java. The corresponding actions in php should be similar, you just need to check how the API looks like.
我不知道如何在 php 中做到这一点,但我知道如何在 Java 中做到这一点。php中对应的action应该是类似的,你只需要看看API是什么样子就行了。
In Java using HBase 0.90.4:
在使用 HBase 0.90.4 的 Java 中:
// Remember the "schema" of your table
HBaseAdmin admin = new HBaseAdmin(yourConfiguration);
HTableDescriptor td = admin.getTableDescriptor(Bytes.toBytes("yourTableName");
// Delete your table
admin.disableTable("yourTableName");
admin.deleteTable("yourTableName");
// Recreate your talbe
admin.createTable(td);
回答by Farooque
回答by Heapify
回答by grbulat
回答by Arnon Rotem-Gal-Oz
HBase thrift API (which is what php is using) doesn't provide a truncate command only deleteTable and createTable functionality (what's the diff from your point of view?)
HBase thrift API(这是 php 正在使用的)不提供截断命令,仅提供 deleteTable 和 createTable 功能(从您的角度来看有什么区别?)
otherwise you have to scan to get all the keys and deleteAllRow for each key - which isn't a very efficient option
否则您必须扫描以获取所有键并为每个键删除所有行 - 这不是一个非常有效的选择
回答by Lobo
Perhaps using one of these two commands:
也许使用这两个命令之一:
DELETE FROM your_table WHERE 1;
Or
或者
TRUNCATE your_table;
Regards!
问候!