我想在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); }