内容简介:翻译自:https://stackoverflow.com/questions/9902353/how-to-clear-a-table-in-hbase
我想在hbase中清空一个表…例如:user.是否有任何命令或函数来清空表而不删除它…
我的表结构是:
$mutations = array( new Mutation( array( 'column' => 'username:1', 'value' =>$name ) ), new Mutation( array( 'column' => 'email:1', 'value' =>$email ) ) ); $hbase->mutateRow("user",$key,$mutations);
有人能帮我吗?
没有单一命令可以清除Hbase表,但您可以使用2种解决方法:禁用,删除,创建表或扫描所有记录并删除每个记录.
实际上,再次禁用,删除和创建表大约需要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);
如果表中没有大量数据 – 扫描所有行并删除每个行的速度要快得多.
$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); }
在这种情况下,数据不会被物理删除,实际上它被“标记为已删除”并保留在表中直到下一个主要契约.
翻译自:https://stackoverflow.com/questions/9902353/how-to-clear-a-table-in-hbase
以上所述就是小编给大家介绍的《php – 如何清除hbase中的表?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
How to Build a Billion Dollar App
George Berkowski / Little, Brown Book Group / 2015-4-1 / USD 24.95
Apps have changed the way we communicate, shop, play, interact and travel and their phenomenal popularity has presented possibly the biggest business opportunity in history. In How to Build a Billi......一起来看看 《How to Build a Billion Dollar App》 这本书的介绍吧!